How to set compileOptions for my Gradle Java plugin?

I want to set the -parameters command for my gradle assembly so that I can use reflection to access the parameter name. Looks like I should be doing this with the next close.

compileJava { compileOptions { compilerArgs << '-parameters' } } 

But compileOptions is displayed as read-only, and when I look at the source code, there is no installer.

https://gradle.org/docs/current/dsl/org.gradle.api.tasks.compile.JavaCompile.html#org.gradle.api.tasks.compile.JavaCompile:options

How can I assume that I can compile a javac compiler that args use in Gradle?

 Groovy: 2.3.6 Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013 JVM: 1.8.0_40 (Oracle Corporation 25.40-b25) OS: Windows 7 6.1 amd64 
+5
source share
3 answers

Try:

 apply plugin: 'java' compileJava { options.compilerArgs << '-parameters' } 
+3
source

You cannot overwrite all parameters (since the "options" property is read-only), but you can set them one at a time. For instance:

 compileJava { //enable compilation in a separate daemon process options.fork = true //enable incremental compilation options.incremental = true } 

Check out the docs: https://gradle.org/docs/current/dsl/org.gradle.api.tasks.compile.JavaCompile.html and https://gradle.org/docs/current/dsl/org.gradle. api.tasks.compile.CompileOptions.html

+4
source
  tasks.withType(JavaCompile) { configure(options) { options.compilerArgs << '-Xlint:deprecation' << '-Xlint:unchecked' // examples } } 

Source: http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.compile.CompileOptions.html

+3
source

All Articles