Add annotation processor's product to buildcache

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

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

Task 'compileReleaseJavaWithJavac' output files does not allow modification.

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")

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