Using gradle with grails
I just recently migrated my entire kiwidoc project to use gradle for its build framework (replacing maven). The biggest challenge I faced in the exercise was to have grails work with gradle. I spent way too much time on this part due to my lack of deep knowledge of each framework but in the end it is extremely simple. The reason why it was challenging in the first place is that my project is a multi-project build as gradle calls it (see Chapter 36). What I wanted was that my other projects be recompiled before starting grails to get the latest version.
There are 2 ways you can go about it:
1. Use the grails gradle plugin
I actually opened a Jira Ticket for this and within a couple of days there was already a solution out there. The details are on the jira ticket and on the github project. Here is how you use it: grailsVersion is a variable defined in my 'root' build script (grailsVersion="1.3.4"). As can be seen on this short example, I have dependencies to my other projects built by gradle as well. Please note the extra dependency on aspectj due to an improper pom file :(.2. Use gradle to build the classpath
Solution #1 works great but everything you do needs to go through gradle and it also downloads a new version of grails. So if you already have grails installed there is another solution: By declaring the lib task to depend on the jar task, the groovy plugin will automatically build my classpath which I copy in the lib folder that grails know about. I can then simply invoke the grails command line (which is assumed to be in your path). The beauty with this solution is you can simply run gradle lib and once you are done, you can go on the command line and simply run grails directly as now all the dependencies you need are where grails expects them. If you want to run the app with gradle, you need to use gradle -i run-app otherwise you won't see any of the messages that grails log.
Aug 28 2010 - Posted by Yan in