在使用Gradle插件spring-boot-dependencies和spring-boot的多模块项目中,正确的Gradle配置是什么样子的?
我有以下项目设置:
parent
|
+ build.gradle
|
+ alpha
| |
| + build.gradle
|
+ beta
| |
| + build.gradleparent模块包含常见的项目配置。alpha模块是一个模块,在该模块中,我希望使用spring-boot-dependencies bom中指定的版本号导入依赖项,但其结果是一个标准jar。beta模块是一个依赖于alpha的模块,其结果是一个可执行的Spring文件(包括所有依赖项)。因此,这个项目既需要spring-boot-dependencies也需要spring-boot插件。为了保持Gradle文件的干燥,我已经将常见的模块脚本提取到父文件的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}")
}
}
}αbuild.gradle
dependencies {
compile('org.springframework:spring-web')
}β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在SpringBoot1.3.0.M1中的行为发布于 2015-11-14 22:20:39
事实证明,parent/build.gradle应该按以下方式重新排列:
buildscript {
ext {
dependencyManagementPluginVersion = '0.5.3.RELEASE'
springBootVersion = '1.3.0.RC1'
}
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}")
}
}
allprojects {
group = "com.example"
version '0.0.1-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
}
subprojects {
sourceCompatibility = 1.8
targetCompatibility = 1.8
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}")
}
}
}问题在于子项目的buildscript块确实配置得很好,但是.在错误的地方。这个subprojects块与子项目有关,但它将在声明的脚本中进行计算,并且它试图应用的插件没有声明依赖项。
https://stackoverflow.com/questions/33706957
复制相似问题