如何调试Gradle build.gradle文件(在调试器中,带有断点)? [英] How to debug a Gradle build.gradle file (in a debugger, with breakpoints)?

查看:845
本文介绍了如何调试Gradle build.gradle文件(在调试器中,带有断点)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个工具可以让我在build.gradle文件中设置断点,并在调试器中逐步执行任务?

Is there a tool that will allow me to set breakpoints in a build.gradle file and step through tasks in a debugger?

注意:我相信,问一个与类似的stackoverflow问题有关调试Gradle插件的问题,其中(大概)意图是逐步通过定制的Groovy或Java插件代码位于一个单独的文件。我想在一个简单的build.gradle文件中的Gradle任务中设置一个断点,如...

Note: I believe that I'm asking a different question than similar stackoverflow questions about debugging Gradle plugins, where (presumably) the intent is to step through custom Groovy or Java plugin code located in a separate file. I want to set a breakpoint in a Gradle task in a simple build.gradle file, like...

task example {
   println "I want to set a breakpoint here"
}

...所以当我运行 gradle示例我可以检查调试器中的上下文。

...so that when I run gradle example I can inspect the context in a debugger.

(对于那些谁会指向我到IntelliJ ...虽然JetBrains的网站宣称他们支持在IDEA UI中调试Gradle脚本,但是AFAICT这是不真实的,因为这在IDEA13 EAP中被报告了,在IDEA14中还没有被修复,请参见在Intellij / Android Studio中调试Gradle构建文件

(For those who would point me to IntelliJ...although JetBrains' website advertises that they support debugging Gradle scripts in IDEA UI, AFAICT this is untrue, as this was reported broken in IDEA13 EAP and hasn't been fixed in IDEA14. See Debugging Gradle build files in Intellij / Android Studio )

是否有任何调试工具允许我在build.gradle文件中设置一个断点,或者有一些关于Gradle DSL的东西,这使得它在根本上是不可能在一个任务中设置断点,例如我的例子,以上?

Is there any debugging tool that allows me to set a breakpoint in a build.gradle file, or is there something about the Gradle DSL that makes it fundamentally impossible to set breakpoints in a task such as my example, above?

推荐答案

Personnaly我需要调试构建脚本时执行此操作:

Personnaly I do this when I need to debug build scripts:



Inside you terminal do

export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

然后运行您的构建

gradle clean install

最后在端口上放置一些断点并启动远程调试配置5005,你很好去!

Finally put some breakpoints and launch the remote debug configuration inside your IDE on the port 5005 and you’re good to go!

这篇关于如何调试Gradle build.gradle文件(在调试器中,带有断点)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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