I am trying to set the verbose
flag/option to true in the gradle build script (Kotlin DSL).
Gradle throws error that this property is private and not accessible in Kotlin DSL. The same thing works in Groovy DSL though.
Groovy DSL (working)
plugins {
id("java")
}
tasks.named("compileJava") {
options.verbose = true
}
Kotlin DSL (not-working)
plugins {
id("java")
}
tasks.named<JavaCompile>("compileJava") {
options.verbose = true
}
Error
Script compilation error:
Line 32: options.verbose = true;
^ Cannot access 'verbose': it is private in 'CompileOptions'
1 error
I am sure I am missing something. Any help is appreciated. Thanks.
CodePudding user response:
CompileOptions has a setter for verbose
, so this will work
tasks.named<JavaCompile>("compileJava") {
options.setVerbose(true)
}
It is also possible to set the flag via property:
tasks.named<JavaCompile>("compileJava") {
options.isVerbose = true
}
CodePudding user response:
Not sure why it is private
for Kotlin DSL and not for Groovy DSL, but found an alternative using compilerArgs
from this stackoverflow post
tasks.named<JavaCompile>("compileJava") {
val compilerArgs = options.compilerArgs
compilerArgs.add("-verbose")
}
This, to me, feels a bit low-level since we are directly updating the compiler arguments instead of using objects/maps to set them. Will wait for someone to post a better solution (if it exists).