如何使"gradle --console = rich"成为默认值? [英] How can I make “gradle --console=rich” the default?
问题描述
this答案(对我来说是有效的,顺便说一句)和
Along the lines of this answer (which works for me, BTW) and the javadocs, I tried
gradle.startParameter.consoleOutput = org.gradle.api.logging.configuration.ConsoleOutput.Rich
我的~/.gradle/init.gradle
中的
.但是,我仍然需要--console=rich
以获得颜色输出.为什么?
in my ~/.gradle/init.gradle
. However, I still need --console=rich
to get color output. Why?
使用Gradle 2.14.1和3.2.1进行了测试
Tested with Gradle 2.14.1 and 3.2.1.
终端是cygwin urxvt,其TERM变量设置为rxvt-unicode-256color.
Terminal is cygwin urxvt with TERM variable set to rxvt-unicode-256color.
推荐答案
我不确定是否可以从gradle脚本中强制执行丰富控制台,因为检测可能是在解释脚本之前进行的.
I am not sure if you can force the rich console from a gradle script, as the detection happens likely before the script is interpreted.
NativeServices类提供了与控制台的集成.如果您查看源代码,日志中可能会显示两条消息:
NativeServices class provides the integration with the console. If you look at the source code, there are two messages possibly printed in log:
Native-platform terminal integration is not available. Continuing with fallback.
Unable to load from native-platform backed ConsoleDetector. Continuing with fallback.
后者可能会为您提供更多信息.尝试使用--debug
运行gradle脚本.您可能会发现您缺少一个本机库,该库在cygwin中不可用,或者在cygwin中不可用,但是不在库路径上.
The latter might give you more information why. Try running the gradle script with --debug
. You will likely find out that you are missing a native library that is either not available in cygwin or it is, but is not on library path.
我相信,当您从命令行指定富控制台时,它会起作用,因为gradle会强制设置颜色,即使控制台未指示它支持它们也是如此.
I believe it works when you specify the rich console from the command line, because gradle forces the colours even though the console doesn't indicate it supports them.
如果您不使用Windows本机命令行中的cygwin控制台,或者也许不使用GitBash,它是否可以工作?
Does it work if you don't use the cygwin console in Windows native command line or maybe GitBash?
有一个变通办法,您可以使此工作. 您可以在cygwin中创建一个别名,该别名将始终添加--console=rich
.
There is a workaround how you can make this work. You can create an alias in cygwin that will always add the --console=rich
.
如果使用gradle包装器,则可以编辑gradlew
脚本并添加命令行参数.要使其自动化,可以更改wrapper
任务以更改doLast
部分中的脚本.
If you are using gradle wrapper, you can edit the gradlew
script and add the command line parameter. To make it automated, you can change the wrapper
task to alter your script in the doLast
part.
这篇关于如何使"gradle --console = rich"成为默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!