Override version of shared convention plugins

Hello,

In my projects I use shared convention plugins, which works fine. I now trying to update certain dependencies independent in the projects. In my case springboot.

convention - build.gradle.kts

plugins {
    `kotlin-dsl`
    id("publish-conventions")
}

dependencies {
    implementation("org.springframework.boot:spring-boot-gradle-plugin") {
        version {
            prefer("3.1.5")
        }
    }
}

convention - spring-conventions

import org.gradle.kotlin.dsl.apply

plugins {
    id("org.springframework.boot")
}

apply(plugin = "org.springframework.boot")
apply(plugin = "io.spring.dependency-management")

tasks.bootJar {
    enabled = false
}

dependencies {
    compileOnly("org.projectlombok:lombok")
    annotationProcessor("org.projectlombok:lombok")

    testCompileOnly("org.projectlombok:lombok")
    testAnnotationProcessor("org.projectlombok:lombok")

    testImplementation("org.springframework.boot:spring-boot-starter-test")
}

How can I override Spring Boot version in a single project which uses spring-conventions?

Sidenote: You apply the org.springframework.boot plugin twice (no actual problem, second time is ignored) and should remove the io.spring.dependency-management plugin as it is a relict from times when Gradle had no built-in BOM support, by now does more harm than good, and even its maintainer recommends not to use it anymore.

Regarding your actual question, largely depends on how you consume that plugin. If it for example lives in buildSrc you do not have much chance besides an init script. If it is published somewhere and you use it in a plugins block, you should be able to declare an according constraint on the classpath configuration of the according build script. Or you could override the version by depending on it from buildSrc as runtimeOnly dependency, as buildSrc things are in a parent class loader and would thus be used, but could then cause other classloader problems depending on concrete details and so on.

So this is hard to answer generically and you best provide an MCVE of the concrete situation if you need more concrete recommendations.

To your sidenote: I tried without io.spring.dependency-management but then I have issues in the projects with resolving dependencies managed by Spring.

I build a mcve with my current state of work:

mcve-project includes conventions and with it the dependency to org.springframework.boot:spring-boot-gradle-plugin with version 3.1.5. What I try to find out, if its possible to set the in mcve-project the version to 3.2.0.
With the dependencies I can request the libraries (with version catalog) and the project can set the version. Same thing I try with the org.springframework.boot:spring-boot-gradle-plugin.

Thank for helping me.

To your sidenote: I tried without io.spring.dependency-management but then I have issues in the projects with resolving dependencies managed by Spring.

Of course you cannot simply remove it. You need to replace it with the built-in BOM handling like doing implementation(platform(<thebomhere>)) as is also documented in the Spring Boot documentation.

mavarazo/mcve-conventions

Unfortunately, this is not buildable, as it does not contain repositories, hence it does not really fulfill the "C"omplete of “MCVE”. :wink:
And after fixing that mavarazo/mcve-project also was not usable as it did not find the dependencies in mavenLocal()
But after fixing those, I could have a look.

While using mavenLocal() is bad of course, but I assume it is just for the sake of the “MCVE”.
Givent that, it is like I described, just add an according constraint.

Add this to foo/build.gradle.kts and you get 3.2.0:

buildscript {
    dependencies {
        constraints {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:3.2.0")
        }
    }
}