I have a Java project in which I would like to create a task that runs the build task with some annotation processors enabled through compiler flags. My impression from Googling is that implementing this by running something akin to "add compiler flags, then invoke build
" is not possible, as a task cannot pass control to another task. I wrote this instead:
task buildWithProcessors {
compileJava.options.compilerArgs += [<flags>]
}
compileJava.dependsOn buildWithProcessors
Not really what I intended, unfortunately, but at least it passes the options, albeit for every invocation of gradle build
.
I considered using a command line flag to indicate whether the extra compiler flags are desired, but I felt it wasn’t ideal due to the fact that it wouldn’t show up in gradle tasks
. There was also the option of using an empty withProcessors
task along with gradle.taskGraph.whenReady
, but, again, I thought that it wasn’t really ideal to require the user to type gradle build withProcessors
instead of gradle buildWithProcessors
I saw that Maven has a way to specify annotation processors without messing with compiler flags, but I didn’t see an equivalent for Gradle.
Is there a better/more Groovy-/Gradle-style way of doing something like this? Am I missing another way of looking at the problem that doesn’t require such a setup?