【发布时间】:2020-09-12 16:46:41
【问题描述】:
我最近为一个 Spring Boot 项目将 Gradle 从 4.x 升级到了 6.6。我以为我终于把它全部启动并运行了,但后来意识到我们的一个应用程序可能会启动两个不同配置的 BootRun 类型的任务(比如 A 和 B),但无法启动第二个 B 实例。
这是我尝试运行第二个实例时的错误:
Build file 'C:\Users\...\build.gradle' line: 17
Execution failed for task ':apps:myapp:bootRunB'.
> The value for task ':apps:myapp:bootRunB' property 'mainClass' is final and cannot be changed any further.
这是我的build.gradle 文件中用于配置任务的部分:
task bootRunB(type: org.springframework.boot.gradle.tasks.run.BootRun, dependsOn: 'build') {
group = 'Application'
doFirst() {
main = bootJar.mainClassName
classpath = bootRun.classpath
systemProperty '...'
}
}
任何建议将不胜感激。
【问题讨论】:
-
参见github.com/gradle/gradle/issues/12841 :将
main属性配置移到doFirst块之外,在执行阶段无法更改此属性 -
@M.Ricciuti 这可能会导致在配置
bootRunB后更改bootJar.mainClassName时出现问题。我想这些问题是首先使用doFirst的原因。
标签: gradle build.gradle