Allow to enable annotation processing explicitly (#20117)

In 1e91f3b we disabled annotation processors globally. However, some
project like JMH need annotation processing, so we add an ability to
selectively enabled annotation processing for certain projects by
setting an external property in the corresponding Gradle build script.

Note that `javac` would allow to set a specific annotation processor
with the command line option `-processor`. However, due to a bug in
Gradle we we cannot use this option and need to enable all annotation
processors.
This commit is contained in:
Daniel Mitterdorfer 2016-08-23 15:15:22 +02:00 committed by GitHub
parent d685847b73
commit c13513ed61
2 changed files with 10 additions and 1 deletions

View File

@ -57,6 +57,9 @@ dependencies {
} }
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked" compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
// enable the JMH's BenchmarkProcessor to generate the final benchmark classes
// needs to be added separately otherwise Gradle will quote it and javac will fail
compileJava.options.compilerArgs.addAll(["-processor", "org.openjdk.jmh.generators.BenchmarkProcessor"])
compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked" compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
forbiddenApis { forbiddenApis {

View File

@ -394,7 +394,13 @@ class BuildPlugin implements Plugin<Project> {
* -serial because we don't use java serialization. * -serial because we don't use java serialization.
*/ */
// don't even think about passing args with -J-xxx, oracle will ask you to submit a bug report :) // don't even think about passing args with -J-xxx, oracle will ask you to submit a bug report :)
options.compilerArgs << '-Werror' << '-proc:none' << '-Xlint:all,-path,-serial,-options,-deprecation' << '-Xdoclint:all' << '-Xdoclint:-missing' options.compilerArgs << '-Werror' << '-Xlint:all,-path,-serial,-options,-deprecation' << '-Xdoclint:all' << '-Xdoclint:-missing'
// either disable annotation processor completely (default) or allow to enable them if an annotation processor is explicitly defined
if (options.compilerArgs.contains("-processor") == false) {
options.compilerArgs << '-proc:none'
}
options.encoding = 'UTF-8' options.encoding = 'UTF-8'
//options.incremental = true //options.incremental = true