0

I use Spring Boot and Spring Boot Dependency Management Plugin which helps me use dependencies from Spring Boot BOM. However, Gradle support for BOM import since version 5.0. I made a decision to migrate to Gradle built-in BOM import support. But I run into the issue: I use custom Gradle plugin with dynamically added dependency:

open class MyCustomPlugin : Plugin<Project> {
    override fun apply(project: Project): Unit = project.run {
        project.dependencies.add("jooqRuntime", "org.postgresql:postgresql")
    }
}

This plugis depends on another plugin

dependencies {
implementation("nu.studer:gradle-jooq-plugin:4.1")}

Thus I could get the version of PostgreSQL from this plugin. Now I cannot do the same. How can I resolve dependency added in plugin dynamically?

wakedeer
  • 493
  • 5
  • 14

1 Answers1

1

Spring's dependency management plugin is a bit heavy handed. It touches all configurations as you can see here with the usage of all() call.

The native Gradle solution is optimized or "smarter" and only "touches" the configurations it needs to. You can learn more about differences in this talk.

So the solution here is to import the BOM or platform as Gradle calls it for the jooqRuntime configuration. This can either be done in your project:

dependencies {
    "jooqRuntime"(platform("org.springframework.boot:spring-boot-dependencies:2.2.5.RELEASE")
}

or in the plugin directly (Java example):

public class MyCustomPlugin implements Plugin<Project> {

    @Override
    public void execute(Project project) {
        DependencyHandler dependencies = project.getDependencies();
        dependencies.add("jooqRuntime", dependencies.platform("org.springframework.boot:spring-boot-dependencies:2.2.5.RELEASE"));
    }

}
Cisco
  • 20,972
  • 5
  • 38
  • 60