为什么我不能调试Gradle构建脚本的每一行?

问题描述 投票:0回答:1

当使用典型的命令行args(-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个回答
1
投票

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

我相信如果你使用kotlin-dsl而不是groovy DSL,你可以在kotlin buildscript中放置断点并在IntelliJ IDEA中调试,但我不是100%肯定这个

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

$根/的build.gradle

apply plugin: MyBuildScript

$根/ buildSrc / src目录/主/常规/ 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
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.