我有一个Gradle项目,我想创建一个子模块,但是我在构建这个项目时遇到了一个失败。
错误信息是
任务执行失败:子项目:
‘>无法解析配置的所有文件“子项目:编译compileClasspath”.>找不到org.springframework.boot:spring-boot-starter:.要求:项目:父-项目
这是父项目build.gradle文件:
plugins {
id 'org.springframework.boot' version '2.3.0.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
allprojects {
apply plugin: 'java'
group = 'com.test'
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
repositories {
//local nexus
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
//other dependencies
}这是子项目build.gradle:
plugins {
id 'java'
}
group = 'com.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_11
dependencies {
compile 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}请帮忙,谢谢。
发布于 2020-06-15 11:30:59
为了能够在没有版本的情况下指定Spring依赖项,您需要将Spring插件应用于所有模块。现在,您只在父项目中,而不是在子项目中。
由于应用插件在默认情况下也会禁用普通jar任务,因此可以创建一个bootJar,因此需要对库进行更改:
// Child build file
plugins {
// Note that there are no versions on the plugins in the child project as this is defined by the ones in the parent
id 'org.springframework.boot'
id 'io.spring.dependency-management'
}
bootJar {
enabled = false
}
jar {
enabled = true
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
}或者,您也可以废弃io.spring.dependency-management插件(以及子项目中的org.springframework.boot插件),而是将Spring导入为一个平台:
// Child build file (alternative)
dependencies {
// Use 'platform' for making the versions in the BOM a recommendation only, and 'enforcedPlatform' for making them a requirement.
// Note that you need the version of the BOM, so I recommend putting it in a property.
implementation enforcedPlatform("org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE")
// Here you can leave out the version
implementation 'org.springframework.boot:spring-boot-starter'
}我通常选择后一种选择,因为这允许我使用普通的Gradle语义。但这主要是出于偏好。
(只需对构建脚本做一个小小的说明:不推荐使用compile配置。它在行compile 'org.springframework.boot:spring-boot-starter'中使用。您可能只是从某个地方复制/粘贴它,但是您应该用implementation替换它。)
https://stackoverflow.com/questions/62384903
复制相似问题