Custom JavaCompile task in Gradle
I'm using Gradle in a Java project. In my build.gradle I have defined
following source sets:
sourceSets {
main {
java {
srcDirs = ['src', 'src.mdd']
}
resources {
srcDir 'resources'
}
}
test {
java {
srcDir 'test'
}
}
}
src is for my regular source files, src.mdd contains all source files that
were generated from an UML modelling tool.
I am also using a code generator in my project which takes several of my
Java classes as input and then generates new source files (.java) to a new
directory (build/gen).
In order to build my project correctly, I have to run following sequence:
compile sources in src and src.mdd
run the code generator and pass some of the previously compiled classes as
parameter. The code generator will save all generated .java files in
build/gen
compile sources in build/gen
jar everything
Steps 1 & 2 are working just fine. The sources are compiled via Gradle's
compileJava task and the code generator is run via a custom task that I
wrote.
My approach for step 3 is to use following task that should be executed
after the generator task has completed:
task compileGen(type: JavaCompile) {
source genDir
classpath sourceSets.main.compileClasspath
destinationDir '$buildDir/genClasses'
}
This approach, however, doesn't work at all. Everytime I try to run this
task, Gradle gives me following error message:
Could not find method classpath() for arguments [configuration ':compile']
on root project 'ProjectName'
The console output points to the line starting with classpath in my
compileGen task.
Could anyone tell me what I'm doing wrong and whether I'm using the right
approach?
No comments:
Post a Comment