Reputation: 1154
I am from Maven background and very new to Gradle. Given below is the context.
I have a library project
LibraryStarter
which needs to be imported to a
LibraryUser
project.
Both are spring boot projects and the build.gradle of LibraryUser complains that
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
I tried to apply the suggestion, but did not helped.
Keeping both the build.gradle files for reference.
For LibraryStarter
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()
}
For LibraryUser
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()
}
Any help will be much appreciated.
#################### UPDATE #################
Updated the build.gradle as requested by @Onur in comments. But the spring dependencies are removed from classpath and caused compilation errors in classes.
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()
}
###################### UPDATE ########################
I got it working. But not sure if I am doing it right.
Removed the plugins from the LibraryStarter and added the following dependencies.
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'
If you think this is the right approach, I can post it as an answer. Else I am still open for your suggestions.
Keen to know the best and valid approach to handle this situation, rather than applying any patch!.
Upvotes: 0
Views: 974
Reputation: 2438
if your module structure is like
root (LibraryUser)
|__build.gradle
|__sub-project (LibraryStarter)
|__build.gradle
then in the root build.gradle
plugins {
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'
}
Do not add (remove) plugins section in the sub-projects
Upvotes: 0