Our build is doing code generation and we have a use case where one sub-project generates domain objects from a model, and another sub-project generates persistence for these objects.
The persistence itself is relatively complex and we have special model for it - we found it nice to implement the model in Groovy, where we can reference the generated domain classes directly, rather than use strings to specify classes and such. The generator reads the config script, which builds a model and then spews the custom persistence code.
The problem is that the generator resides in one of the sub-projects that Gradle will build, which is not present during the configuration phase. Just in case, we tried it with:
buildscript {
dependencies {
classpath project(":domain-objects")
}
}
And the build failed with an error that Gradle can not resolve the â:domain-objectsâ dependencies. We did make sure that the buildscript section has the repos set up, but to no help.
Our next attempt was to use the JavaExec task - the problem there was that while it was easy to add project(":domain-objects") to the classpath, it was impossible to add the rest of the build classpath. I did try:
classpath project(':stream').configurations.default,
buildscript.configurations.classpath
But it didnât work - after some poking, I found that buildscript.configurations.classpath was emptyâŚ
Finally we made it work with this:
task generate(type: JavaExec) {
ext.modelRoot = file('src/model/groovy', PathValidation.DIRECTORY)
ext.destDir = generatedSrc
inputs.source modelRoot
outputs.dir destDir
main = '....gradle.codegen.StoreGenerator'
args = [modelRoot, destDir, 'com.ubs.start.stores']
classpath project(':stream').configurations.default,
project(':stores').configurations.testRuntime,
// workaround for fetching groovy
rootProject.file('buildSrc/build/libs/buildSrc.jar')
// <---- ugly
doFirst {
delete fileTree(dir: generatedSrc, excludes: ['**/.svn/**'])
}
}
That works, but is completely bypassing the dependency management - is there a better way?