Gradle:用于Spring Boot的jvm参数的自定义任务 [英] Gradle: custom task with jvm arguments for Spring Boot

查看:1081
本文介绍了Gradle:用于Spring Boot的jvm参数的自定义任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试为Spring Boot创建一个小型自定义Gradle任务,原本如下所示:


$ b

gradle bootRun --debug-jvm

code>



任务应该如下所示: gradle debugRun



我试过这个,但它不起作用:

 任务debugRun(dependsOn:'bootRun')< ;< {
applicationDefaultJvmArgs = ['--debug-jvm']
}

如何将此调试标志传递给bootRun任务?

解决方案

这对于 debug 运行任务依赖于 bootRun 任务。它需要修改现有的 bootRun 任务来启用调试。你可以通过检查Gradle的任务图中的 debugRun 任务来完成。如果它在那里,您将 bootRun 任务的 debug 属性设置为 true

 任务debugRun(dependsOn:bootRun){
gradle.taskGraph.whenReady {graph - >
if(graph.hasTask(debugRun)){
bootRun {
debug = true
}
}
}
}


Trying to create a small custom gradle task for Spring Boot that originally looks like this:

gradle bootRun --debug-jvm

The task should look like this: gradle debugRun

I tried this but it does not work:

task debugRun(dependsOn: 'bootRun') << {
    applicationDefaultJvmArgs = ['--debug-jvm']
}

How can I pass this debug-flag to the bootRun task?

解决方案

It isn't sufficient for your debug run task to depend on the bootRun task. It needs to modify the existing bootRun task to enable debugging. You can do that by checking for the debugRun task in Gradle's task graph. If it's there, you set the bootRun task's debug property to true:

task debugRun(dependsOn:bootRun) {
    gradle.taskGraph.whenReady { graph ->
        if (graph.hasTask(debugRun)) {
            bootRun {
                debug = true
            }
        }
    }
}

这篇关于Gradle:用于Spring Boot的jvm参数的自定义任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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