Last updated by
1 year ago
Page: GrailsDevEnvironment, Version:28
Setting up a Grails development environment
So, 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-requisites
You 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 code
Once 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:git clone http://github.com/grails/grails-core.git
Adding grails/grails-core as an upstream
In 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 runninggit remote add upstream https://github.com/grails/grails-core.git
git fetch upstream
Building and running
After you have made a change to Grails, how do you check that it has had the desired effect?Create the required jars
Running "./gradlew libs" 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 suite
All you have to do to run the full suite of tests is:./gradlew test
./gradlew -Dtest.single=MappingDslTest grails-test-suite-persistence:test
Developing in IntelliJ IDEA
You need to run the following gradle task:./gradlew idea
Developing in STS / Eclipse
You need to run the following gradle task:./gradlew cleanEclipse eclipse
- Edit grails-scripts/.classpath and remove the line "<classpathentry kind="src" path="../scripts"/>".
- Add "~/.gradle/cache/com.springsource.springloaded/springloaded-core/jars/springloaded-core-XXXX.jar" to grails-core's classpath.
- 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.
- Do a clean build for the whole workspace.
- 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.
Debug
To debug Grails run the Grails application using:grails-debug <command>