I’m trying to share some build logic between some submodules
as suggest in
Sharing build logic between subprojects Sample
myproject.java-conventions.gradle
plugins {
id 'org.springframework.boot'
id 'groovy'
id 'java-library'
repositories {
gradlePluginPortal()
mavenCentral()
dependencies {
implementation 'org.springframework.boot:spring-boot-gradle-plugin:2.7.1'
But when a run the build I get
An exception occurred applying plugin request [id: 'myproject.java-conventions']
> Failed to apply plugin 'myproject.java-conventions'.
> org.gradle.api.plugins.UnknownPluginException: Plugin with id 'org.springframework.boot' not found.
What I’m doing wrong ?
You need to declare the dependency on the spring boot plugin in the build script that builds that plugin, so yourIncludedBuild/build.gradle(.kts)
or buildSrc/build.gradle(.kts)
.
Where you defined it, it would be added as dependency for your actual project.
I’d strongly recommend not to use the io.spring.dependency-management
though.
Besides that you don’t use it to import the BOM, you should imho prefer the built-in BOM support of Gradle using platform(...)
if it is just about consuming the BOM.
That plugin comes from a time where Gradle did not have that support built-in, and it also does more than that, like porting over imho broken-by-design behavior from Maven over to the Gradle world.
So if you don’t use or need any of the additional functionalities, just use the built-in functionality.
dependencies {
implementation platform('org.springframework.boot:spring-boot-dependencies:2.7.1')
submoduleApi/build.gradle
plugins {
id 'myproject.java-conventions'
dependencies {
compileOnly 'org.springframework.boot:spring-boot-starter-web'
submoduleService/build.gradle
plugins {
id 'myproject.java-conventions'
id 'org.springframework.boot'
id 'application'
dependencies {
implementation project(":api")
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
I think the following way would be better
import org.springframework.boot.gradle.plugin.SpringBootPlugin
dependencies {
api platform(SpringBootPlugin.BOM_COORDINATES)
When ‘importing’ dependencies, the difference is transitivity. When importing BOM, I don’t think they are any different.
I think ‘implmentation’ is not practical, you need to customize the introduction method