我来自 Maven 背景,对 Gradle 非常陌生。下面给出了上下文。
我有一个图书馆项目
LibraryStarter
需要导入到
LibraryUser
项目。
两者都是 spring boot 项目和 的 build.gradle图书馆用户 提示说
Could not run phased build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-6.6.1-bin.zip'. Build file 'C:\WORK\LEARN\User\LibraryStarter\build.gradle' line: 2 Error resolving plugin [id: 'org.springframework.boot', version: '2.3.4.RELEASE'] Plugin request for plugin already on the classpath must not include a version
我尝试申请 suggestion ,但没有帮助。
保留两个 build.gradle 文件以供引用。
对于 图书馆入门
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
group = 'com.sample.library.starter'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation project(":MyLibrary")
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
对于 图书馆用户 plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
group = 'com.sample.library.user'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation project(":LibraryStarter")
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
任何帮助都感激不尽。#################### 更新 #################
按照@Onur 在评论中的要求更新了 build.gradle。但是 spring 依赖项从类路径中删除并导致类中的编译错误。
apply plugin: 'java'
group = 'com.sample.library.user'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation project(":LibraryStarter")
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
###################### 更新 ########################我让它工作了。但不确定我是否做得对。
从 中删除插件图书馆入门 并添加了以下依赖项。
implementation group: 'org.springframework', name: 'spring-context', version: "${spring_version}" implementation group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: "${springboot_version}" implementation group: 'org.springframework.cloud', name: 'spring-cloud-context' implementation group: 'org.springframework.cloud', name: 'spring-cloud-commons'
如果您认为这是正确的方法,我可以将其发布为答案。否则我仍然愿意接受你的建议。
渴望知道处理这种情况的最佳和有效方法,而不是应用任何补丁!
最佳答案
如果你的模块结构像
root (LibraryUser)
|__build.gradle
|__sub-project (LibraryStarter)
|__build.gradle
然后在根 build.gradleplugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
allprojects {
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.springframework.boot'
}
不要在子项目中添加(删除)插件部分
关于java - 将gradle项目导入另一个插件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63950534/