Add annotation processor's product to buildcache


(Yi Cheng) #1

Hi,

Currently we rely on some output from java annotation processor during the compilation phase, but the issue is that the output is not bundled into the build cache, and it is only available when the actual compilation takes place, which means I need to force it by using --rerun-tasks.

E.g.

android {
    defaultConfig {
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["deepLinkDoc.output": "${buildDir}/doc/deeplinks.txt".toString()]
            }
        }
    }
}

Typically we can add outputs.files to mark the output to be cached in a task. However, we do not own this java compile task in this case. How should I go about making "${buildDir}/doc/deeplinks.txt" in this case to be cached?

Thanks,
Yi


(Yi Cheng) #2

Also tried to inject the artifact into the task, but got denied.

Task 'compileReleaseJavaWithJavac' output files does not allow modification.

(Mark Vieira) #3

You could try something like this.

android {
    applicationVariants.all { // or libraryVariants.all for a aar project
        javaCompile.outputs.file("${buildDir}/doc/deeplinks.txt")
    }
}

Edit:

Since an Android project could have a number of compile tasks due to variants (debug/release) you’ll probably want to make this output file path unique for each variant to avoid overlapping outputs.

javaCompile.outputs.file("${buildDir}/doc/${name}/deeplinks.txt")

(Yi Cheng) #4

Nice, that seems to do the trick! Thanks so much @mark_vieira!