Last updated by mauk81 2 years ago
Setting up a Grails development environmentSo, you'd like to delve into the Grails source code? Whatever reason you have for doing so, you first need to set yourself up so that you can easily run and debug with the source code version of Grails. Where to start?
Pre-requisitesYou won't go far without some essential tools and libraries, but to be honest you probably already have all of them:
- JDK (1.5+)
- Git client
Downloading the Grails source codeOnce you have all the pre-requisite packages installed, the next step is to download the Grails source code. The source code is hosted at github.com in several different git repositories owned by the "grails" github user.To download the source using git, use the "git clone" command followed by the public URL of the repository you want to clone (download). For example, to clone the "grails-core" repository, run the following:
The above will create a "grails-core" directory in your current working directory populated with the project source and the git repository.Note that if you want to submit changes to the project, you will need to fork the repository on GitHub rather than clone it directly from the above URL.
git clone http://github.com/grails/grails-core.git
Adding grails/grails-core as an upstreamIn order to keep your fork up to date with the main grails project, it is worth adding the grails/grails-core project as your 'upstream' remote location. You can do this by running
Now, when you need to re-sync your own fork of grails with the current development mainline, you can simply
git remote add upstream https://github.com/grails/grails-core.git
A zip distribution of each git tag (not including the git history) is also available on the "Downloads" tab of each github project.
git fetch upstream
Building and runningAfter you have made a change to Grails, how do you check that it has had the desired effect?
Create the required jarsRunning "./gradlew install" will create everything you need to run Grails. This target also skips running the extensive collection of Grails test classes (Grails' 1000+ tests can bring a single core processor to a grinding halt for some time).Once the jars have been built, simply set GRAILS_HOME to the checkout directory and add the "bin" directory to your path.
Run the test suiteAll you have to do to run the full suite of tests is:
These will take a while (15-30 mins), so consider running individual tests using the command line. For example, to run the tests in grails-core/src/test/groovy/org/codehaus/groovy/grails/plugins/BinaryPluginSpec.groovy, run the following command:
You need to give it the specific test suite that the test exists in, just using the "test" target won't work.
./gradlew -Dtest.single=BinaryPluginSpec :grails-core:test
Developing in IntelliJ IDEAYou need to run the following gradle task:
Then open the project file which is generated in IDEA. Simple!
Developing in STS / EclipseYou need to run the following gradle task:
./gradlew cleanEclipse eclipse
- Use "Import->General->Existing Projects into Workspace" to import all projects to STS.
- Do a clean build for the whole workspace.
- Remove "src/test/groovy" from grails-plugin-testing's source path GRECLIPSE-1067
- Add "~/.gradle/cache/javax.servlet.jsp/jsp-api/jars/jsp-api-2.1.jar" (after "~/.gradle/cache/javax.servlet/jsp-api/jars/jsp-api-2.0.jar") to the classpath of grails-web
- Fix the source path of grails-scripts. Add linked source folder linking to "../scripts". If you get build errors in grails-scripts, do "../gradlew cleanEclipse eclipse" in that directory and edit the .classpath file again (remove the line "<classpathentry kind="src" path="../scripts"/>"). Remove possible empty "scripts" directory under grails-scripts if you are not able to add the linked folder.
- To use Eclipse GIT scm team provider: Select all projects (except "Servers") in the navigation and right click -> Team -> Share project (not "Share projects"). Choose "Git". Then check "Use or create repository in parent folder of project" and click "Finish".
- Get the recommended code style settings from the mailing list thread (final style not decided yet, currently profile.xml). Import the code style xml file to STS in Window->Preferences->Java->Code Style->Formatter->Import . Grails code uses spaces instead of tabs for indenting.
DebugTo debug Grails run the Grails application using:
and then connect to it remotely via the IDE. There should be an option for "remote debugging". Unless you modify the "grails-debug" script, you should connect to port 5005.If you need to debug stuff that happens during application start-up, then you should modify the "grails-debug" script and change the "suspend" option from 'n' to 'y'.You can read more about the JPDA Connection settings here: http://java.sun.com/j2se/1.5.0/docs/guide/jpda/conninv.html#InvocationIt's also possible to get Eclipse to wait for incoming debugger connections and instead of using "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005" you could use this "-Xrunjdwp:transport=dt_socket,server=n,address=8000" (which assumes the Eclipse default port for remote java applications) Inside eclipse you create a new "Remote Java Application" launch configuration and change the connection type to "Standard (Socket Listen)" and click debug. This allows you to start a debugger session in eclipse and just leave it running and you're free to debug anything without having to keep remembering to relaunch a "Socket Attach" launch configuration. You might find it handy to have 2 scripts, one called "grails-debug", and another called "grails-debug-attach"