gpt4 book ai didi

java - 为什么我无法调试 Gradle 构建脚本的每一行?

转载 作者:行者123 更新时间:2023-12-02 11:34:04 26 4
gpt4 key购买 nike

当使用典型的命令行参数(-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 不允许调试构建脚本中的每一行?

谢谢!

最佳答案

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

我相信如果您使用kotlin-dsl您也许可以在 kotlin 构建脚本中放置断点并在 IntelliJ IDEA 中进行调试,而不是使用 groovy DSL,但我对此并不能 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
}
}
}

关于java - 为什么我无法调试 Gradle 构建脚本的每一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49080859/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com