我是 Gradle 新手,我遇到了问题(使用 Gradle 2.14)
我的项目有3个子项目:程序集、sprinBootProject、E2E
组装模块负责压缩 Spring Boot 应用程序的 jar 以及属性文件。
E2E 模块是用于测试 Spring Boot 应用程序的“端到端”测试模块。
我在 assembly/build.gradle 中使用分发插件,如下所示:
apply plugin: 'distribution'
distributions {
main {
baseName "project-assembly"
contents{
from project(':springBootProject').fileTree(dir: 'build/libs', include: ['*.jar'])
from project(':springBootProject').fileTree(dir: 'build/resources/main', includes: ['*.properties', 'conf/*.properties'])
}
}
}
但我需要确保 springBootProject 将在程序集子项目之前进行评估,所以我像这样使用了dependsOn:
distZip.dependsOn(':springBootProject:build')
当我添加这一行时,我看到 E2E 模块在 compileTestJava 任务中失败,所以这一行影响了 spring boot 应用程序的生成方式(我认为)
E2E/build.gradle:
dependencies {
testCompile project(":springBootProject")
}
所以我的问题是我做得对吗?为什么当我添加dependsOn 行时,E2E 模块会受到影响,如何强制Gradle 在组装模块之前评估spring boot 应用程序?
最佳答案
我想通了。
Gradle 将按字母顺序评估模块
所以评估将是:组装 -> E2E -> springBootProject
将此行添加到 assembly/build.gradle 时:
distZip.dependsOn(':springBootProject:build')
评估顺序改为:组装 -> springBootProject -> E2E
现在在'springBootProject'模块中,我正在使用spring boot插件来生成一个可执行jar,这个可执行jar是由任务生成的:springBootProject:bootRepackage使用由:springBootProject:jar任务生成的jar并将其转换为可执行文件.
现在因为'E2E'模块依赖于'springBootProject'它将使用它的jar,但现在这个jar是可执行的,因此我在'E2E'中遇到了编译错误。
所以我必须确保“E2E”模块获取原始 jar 而不是可执行文件。
所以我在 springBootProject/build.gradle 中添加了这一行:
bootRepackage.mustRunAfter(':E2E:test')
这似乎解决了问题
关于java - 带装配模块的 Gradle Spring Boot ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43705585/