In Hibernate build we have a number of tasks that run annotation-processing tools. The JDJ “AP API” is sadly not really an API even, it just uses javac. So from Gradle, this means using a highly customized Compile task. We have a hard time getting these tasks set up correctly for UP-TO-DATE checks. Here is one as an example:
task generateMainLoggingClasses(type: Compile) {
classpath = compileJava.classpath + configurations.jbossLoggingTool
source = sourceSets.main.originalJavaSrcDirs
destinationDir = aptDumpDir
options.define(
compilerArgs: [
"-nowarn",
"-proc:only",
"-encoding", "UTF-8",
"-processor", "org.jboss.logging.processor.apt.LoggingToolsProcessor",
"-s", "$sourceSets.main.generatedLoggingSrcDir.absolutePath",
"-AloggingVersion=3.0",
"-source", "1.6",
"-target", "1.6",
"-AtranslationFilesPath=${project.rootDir}/src/main/resources"
]
);
outputs.dir sourceSets.main.generatedLoggingSrcDir;
doFirst {
//
source = sourceSets.main.originalJavaSrcDirs
sourceSets.main.generatedLoggingSrcDir.mkdirs()
}
}
This task seems to always run, even when nothing has changed. Which in turn means that now compileJava has to run because it depends on the above task, and so on.
What all do I need to set up to have this task execute only when needed?
It is important to note that javac requires a destination directory be specified, but it is literally irrelevant here. The real output directory is specified by ‘-s’ javac option to the AP tool.