【发布时间】:2016-02-15 20:58:09
【问题描述】:
在使用 Gradle 插件 spring-boot-dependencies 和 spring-boot 的多模块项目中,正确的 Gradle 配置是什么样的?
我有以下项目设置:
parent
|
+ build.gradle
|
+ alpha
| |
| + build.gradle
|
+ beta
| |
| + build.gradle
-
parent模块包含通用项目配置。 -
alpha模块是一个模块,我想使用spring-boot-dependencies bom 中指定的版本号在其中导入依赖项,但结果是标准 jar。 -
beta模块是一个依赖于alpha的模块,结果是一个可执行的 Spring Boot jar 文件(包括所有依赖项)。因此,该项目需要spring-boot-dependencies和spring-boot插件。
为了保持 Gradle 文件 DRY,我已将常用模块脚本提取到父级的 build.gradle 文件中。
尝试使用以下项目配置执行 $ gradle build 会导致:
> Plugin with id 'io.spring.dependency-management' not found.
父 gradle.build
allprojects {
group = "com.example"
version '0.0.1-SNAPSHOT'
ext {
dependencyManagementPluginVersion = '0.5.3.RELEASE'
springBootVersion = '1.3.0.RC1'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
}
subprojects {
sourceCompatibility = 1.8
targetCompatibility = 1.8
buildscript {
repositories {
jcenter()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("io.spring.gradle:dependency-management-plugin:${dependencyManagementPluginVersion}")
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
// mavenBom("org.springframework.boot:spring-boot-starter-parent:${springBootVersion}")
}
}
}
alpha build.gradle
dependencies {
compile('org.springframework:spring-web')
}
beta gradle.build
apply plugin: 'spring-boot'
dependencies {
compile project(':alpha')
compile('org.springframework.boot:spring-boot-starter')
compile('org.springframework.boot:spring-boot-starter-web')
}
评论:
-
spring-boot插件 was changed 在 Spring Boot 1.3.0.M1 中的行为 - Gradle 版本:2.8
- Spring Boot 版本 1.3.0.RC1
【问题讨论】:
-
如果我的回答有帮助,请点赞。
-
@Opal 抱歉耽搁了,我以为我已经接受了你的回答。我已经就此事写了blog post,请查看致谢。 :-)
-
谢谢,正是我遇到的问题 --- 为了帮助其他人在谷歌上搜索这个问题,我会补充:如果你天真地尝试:将插件“spring-boot”应用于所有子项目,(仅按顺序免费获得spring依赖管理)你会得到构建错误(至少我在windows下得到了),比如:任务':xxxxx:bootRepackage'的执行失败。无法将“xxxxx.jar”重命名为“xxxxx.jar.original”
-
@matsev,刚刚注意到有关文章的信息 - 看起来不错。感谢您被提及!
标签: gradle spring-boot dependency-management spring-boot-gradle-plugin