As far as I know, this is not possible. You definitely need to configure the respective CompileOptions
of the JavaExec
tasks using the Gradle API. The easiest way to do this is in fact the build.gradle
file. If you just want to keep the changes to build.gradle
to a minimum, consider using a project property:
if (hasProperty('compilerArgs')) {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
compilerArgs.split().each { arg ->
options.compilerArgs << arg
}
}
}
}
This way you won't need to change your build.gradle
from now on to change your compiler arguments, as you may simply pass them using gradle <tasks> -PcompilerArgs="<arg1> <arg2>"
. Project properties may also be defined using environment variables.
An alternative without touching the build.gradle
at all is the use of initialization scripts. These scripts in your home directory apply to any Gradle build performed using your account, so you may add some restrictions if you have other projects that should not be effected. A simple initialization script for your use case could be:
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}
You may combine this with the approach from my first snippet to only apply the changes based on a command line argument.
You need to put this into a file
- specified on the command line using
-I
or --init-script
- called
init.gradle
in the USER_HOME/.gradle/
directory
- that ends with
.gradle
in the USER_HOME/.gradle/init.d/
directory
- that ends with
.gradle
in the GRADLE_HOME/init.d/
directory
Of course, those changes need to be applied to any user / any machine.