u1234
(tulsoba)
1
In a custom plugin I need to check if gradle is run with --stacktrace. I have tried the following:
testLogging {
if ( project.hasProperty("--stacktrace") ) {
println
"POSITIVE";
} else {
println
"NEGATIVE";
}
}
and I run it with:
gradle clean install --stacktrace
but it prints: NEGATIVE. How do I add a check for build-in commandline options?
You’d check ‘project.gradle.startParameter’, which is of type org.gradle.StartParameter.
mzbrand
(Michael Brand)
3
I just stumbled on this as well. It turns out that
if (project.gradle.startParameter.showStacktrace) {
println
"POSITIVE";
} else {
println
"NEGATIVE";
}
}
also always displays “NEGATIVE”. Here’s what worked for me:
import org.gradle.logging.ShowStacktrace
if (project.gradle.startParameter.showStacktrace != ShowStacktrace.INTERNAL_EXCEPTIONS) {
println
"POSITIVE";
} else {
println
"NEGATIVE";
}
}
ShowStacktrace is an enum with three possible values:
INTERNAL_EXCEPTIONS := no stacktrace parameters
ALWAYS
:= "--stacktrace"
ALWAYS_FULL := "--full-stacktrace".