问题描述
我有一个执行命令的任务。我需要更改传递给命令的参数,具体取决于我是否执行 ./ gradlew --debug myTask
或 ./ gradlew myTask
。
我认为这将会如此简单: project.logger.isEnabled(LogLevel.DEBUG) code>,但即使当
--debug
传递给Gradle时,它也会返回false。
- = - = - = - = - = - = - = - = - - -
看来你们都是对的。我做了一个无效的假设,即主要的Gradle进程会将其调试标志信息传递给工具API,结果证明这是不正确的。问题是我需要传递一个额外的 --debug
标志到工具API过程。
您可以使用
if(project.gradle.startParameter.logLevel.name()=='DEBUG' )
@see
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.
You could use
if (project.gradle.startParameter.logLevel.name() == 'DEBUG')
@see StartParameter.getLogLevel()
这篇关于Gradle - 如何检测 - 从命令行调试标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!