Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make a task always run quiet from my build.gradle?

Tags:

gradle

One of my tasks in my build.gradle is interative and should always be run with the -q flag, e.g.

./gradlew -q MyTask

If there a way I can control this attribute from my build.gradle file so that even if the user forgets to use the -q flag, the build script will set it automatically?

like image 245
Chris Snow Avatar asked Oct 25 '25 05:10

Chris Snow


1 Answers

It is not possible currently to change the logging level of gradle after the build has started. You can discover the current value but it's readonly by time you can execute code.

The LogLevel can be accessed via the gradle object in scripts by it's startParamater:

LogLevel level = gradle.startParameter.logLevel
println "Current logging level: $level"

https://docs.gradle.org/current/javadoc/org/gradle/StartParameter.html#getLogLevel--

Another note if you want to have logging that isn't always sent to the console then you could use gradle's built in logger

project.logger.info("my message that only prints if caller uses --info flag on command line")

then for your events you want in the console logger use the lifecycle level.

project.logger.lifecycle('my message that will always print')
like image 178
JBirdVegas Avatar answered Oct 26 '25 22:10

JBirdVegas