I am trying to build multi module gradle library. I am trying to follow what I read in offical documentation. I am working in company which has its own nexus repository for spring and other libraries
My project structure is as follows multi-project
├── libA
│ └── build.gradle
├── libB
│ └── build.gradle
├── buildSrc
│ └── build.gradle
└── main/src/groovy
└────────multiproject.common-conventions.gradle
│ └── settings.gradle
The project involves using spring boot for different library, and the dependencies are almost the same. Here was my attempt that is not working
buildSrc/build.gradle
plugins {
id 'groovy-gradle-plugin'
}
repositories {
gradlePluginPortal()
}
buildSrc/multiproject.common-conventions.gradle
plugins {
id 'java-library'
id 'maven-publish'
id 'org.springframework.boot'
}
repositories {
mavenCentral()
}
dependencies {
implementation group: 'org.springframework.boot:spring-boot-gradle-plugin'
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.ws:spring-ws-core'
implementation 'org.apache.httpcomponents:httpclient:4.5.13'
implementation 'org.springframework.retry:spring-retry:1.3.1'
implementation 'javax.cache:cache-api:1.1.1'
implementation 'org.ehcache:ehcache:3.10.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.3'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
now I try to use above plugin in one sub modules, let say libA libA/build.gradle
plugins {
id("multiproject.common-conventions")
id 'org.springframework.boot' version
}
I get the following exception
org.gradle.api.plugins.UnknownPluginException: Plugin with id 'org.springframework.boot' not found.
when I add the version to 2.6.4 I get Invalid plugin request [id: 'org.springframework.boot', version: '2.7.1']. Plugin requests from precompiled scripts must not include a version number. Please remove the version from the offending request and make sure the module containing the requested plugin 'org.springframework.boot' is an implementation dependency.
Invalid plugin request [id: 'org.springframework.boot', version: '2.7.1']. Plugin requests from precompiled scripts must not include a version number. Please remove the version from the offending request and make sure the module containing the requested plugin 'org.springframework.boot' is an implementation dependency.
How can I setup multi module gradle library to use common-conventions plugin using the buildSrc folder, and the plugins DSL? I am using gradle 7.3 version.
Have a look at this section of Gradle's doc https://docs.gradle.org/current/userguide/custom_plugins.html#applying_external_plugins_in_precompiled_script_plugins . As stated there, in order to apply an external plugin (spring-boot-gradle-plugin in your case) in a precompiled script plugin (your multiproject.common-conventions.gradle), it has to be added to the plugin project's implementation classpath in the plugin's build file (you're buildSrc/build.gradle file)
buildSrc/build.gradle
plugins {
id 'groovy-gradle-plugin'
}
repositories {
mavenCentral()
}
dependencies {
implementation('org.springframework.boot:spring-boot-gradle-plugin:3.0.0')
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.