Gradle - How to detect --debug flag from command l

2019-07-11 06:36发布

问题:

I have a task in which I am executing a command. And I need to change which parameters are passed to the command depending on whether I do ./gradlew --debug myTask or ./gradlew myTask.

I thought that it would be as simple as doing: project.logger.isEnabled(LogLevel.DEBUG), but this returns false even when --debug is passed to Gradle.

-=-=-=-=-=-=-=-=-=-

It seems that you are both correct. I was making an invalid assumption that the main Gradle process would pass its debug flag information to the tooling API, which turned out to be incorrect. The issue was that I needed to pass an additional --debug flag to the tooling API process.

回答1:

You could use

if (project.gradle.startParameter.logLevel.name() == 'DEBUG')

@see StartParameter.getLogLevel()



回答2:

The following build.gradle works just fine:

println "LOL ${logger.isDebugEnabled()}"

Try running just gradle and gradle -d or gradle --debug



标签: gradle