grails.plugin.location."my-plugin" = "../../.."
in its BuildConfig.groovy. Doing this allows you as a plugin developer to:- Automate tests for sample projects using the plugin with significantly different configurations.
- Test using domain classes, controllers, etc. that shouldn't be packaged with the plugin.
- Test drive, changing code in both the test app and the plugin without the need to use
grails package-plugin
orgrails install-plugin
to pick up changes.
I wanted to find a way to automate this so I could run all my plugins' tests with a single command. I could write a bash script or an Ant build I guess, or even use maven <shudder>. However keeping things in Groovy-land I decided to try using Gradle which I've been meaning to look into for a while now. I saw Hans Dockter's presentation on Gradle at the London Groovy & Grails Exchange back in December and was impressed with how terse and expressive the syntax is, especially compared to XML based formats. Unfortunately one thing Gradle doesn't grok yet is Grails.
The solution I've come up with is based on a post by Helmut Denk on the gradle-user list. Gradle just uses Ant's exec task to shell out and execute the appropriate Grails command. Combining this with Gradle's multi-project build support I now have plugin builds that can be run with
gradle test
that will automatically descend into the test apps under test/projects/*.The build.gradle file at the root of the project defines clean and test tasks:
allprojects { | |
task clean << { task -> | |
ant.exec(executable: "grails", dir: "$task.project.projectDir", failonerror: true) { | |
arg line: "clean" | |
} | |
} | |
} | |
task test << { | |
ant.exec(executable: "grails", dir: "$projectDir", failonerror: true) { | |
arg line: "test-app unit:" | |
} | |
} |
Then in settings.gradle I tell Gradle where to find the various sub-projects:
include "springcache-test", "alt-cache-impl" | |
project(":springcache-test").projectDir = new File(settingsDir, "test/projects/springcache-test") | |
project(":alt-cache-impl").projectDir = new File(settingsDir, "test/projects/alt-cache-impl") |
Finally each test app has it's own build.gradle that defines its test task:
task test << { | |
ant.exec(executable: "grails", dir: "$projectDir", failonerror: true) { | |
arg line: "test-app integration:" | |
} | |
} |
The process is not as fast as it could be if Grails were wired in to Gradle properly. gradle clean test for the Springcache plugin and its two test apps takes just over 2 minutes on my MBP. Also, my Gradle-fu leaves a lot to be desired right now so I'm sure there are improvements that could be made with the way I'm handling the sub-projects. But, for the purposes of a pre-commit test run or Hudson build this works pretty well.