【问题标题】:Why can't I debug each line of Gradle build script?为什么我不能调试 Gradle 构建脚本的每一行?
【发布时间】:2018-03-03 05:04:42
【问题描述】:

当使用典型的命令行参数 (-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005) 远程调试 gradle 构建时,我只能在我提供的类中的断点处停止;我无法在构建脚本本身内停下来。

根据包括here 在内的各种消息来源,这显然是一种预期行为。例如:

apply plugin: 'groovy'  // not able to stop debugger here

class Penguin() {
    def ork() {
        println 'ork!'  // able to stop debugger here
    }
}

new Penguin().ork()

我试图理解这是为什么?为什么 Gradle 不允许调试构建脚本中的每一行?

谢谢!

【问题讨论】:

    标签: java debugging gradle groovy remote-debugging


    【解决方案1】:

    虽然它与 groovy 非常相似,但 build.gradle 文件是由 Gradle 解析的自定义 DSL。断点只能添加到 .java.groovy 文件中,并且没有可以添加断点的文件。

    我相信,如果您使用 kotlin-dsl 而不是 groovy DSL,您也许可以在 kotlin 构建脚本中放置断点并在 IntelliJ IDEA 中进行调试,但我对此不是 100% 确定

    如果你真的想调试,你可以将所有内容移到一个可以调试的插件中,并在build.gradle 中有一行

    $root/build.gradle

    apply plugin: MyBuildScript
    

    $root/buildSrc/src/main/groovy/MyBuildScript.groovy

    import org.gradle.api.*
    class MyBuildScript implements Plugin<Project> {
        void apply(Project project) {
            project.with {
                apply plugin: 'foo'
                dependencies { ... }
                task bar(type: Baz) { ... }
                // etc
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-26
      • 2018-05-09
      • 1970-01-01
      • 1970-01-01
      • 2011-01-03
      • 2020-04-05
      • 1970-01-01
      • 2021-12-30
      相关资源
      最近更新 更多