Gradle - 如何检测 - 从命令行调试标志? [英] Gradle - How to detect --debug flag from command line?

查看:220
本文介绍了Gradle - 如何检测 - 从命令行调试标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个执行命令的任务。我需要更改传递给命令的参数,具体取决于我是否执行 ./ gradlew --debug myTask ./ gradlew myTask



我认为这将会如此简单: project.logger.isEnabled(LogLevel.DEBUG) code>,但即使当 --debug 传递给Gradle时,它也会返回false。



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

看来你们都是对的。我做了一个无效的假设,即主要的Gradle进程会将其调试标志信息传递给工具API,结果证明这是不正确的。问题是我需要传递一个额外的 --debug 标志到工具API过程。

解决方案

您可以使用

if(project.gradle.startParameter.logLevel.name()=='D​​EBUG' )



@see StartParameter.getLogLevel()


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 - 如何检测 - 从命令行调试标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆