Add
io.spring.dependency-management
plugin, if in use
org.openrewrite.gradle.spring.AddSpringDependencyManagementPlugin
Prior to Spring Boot 2.0 the dependency management plugin was applied automatically as part of the overall spring boot plugin. Afterwards the dependency-management plugin must be applied explicitly, or Gradle's
platform()
feature may be used instead. This recipe makes usage of io-spring.dependency-management explicit in anticipation of upgrade to Spring Boot 2.0 or later.
Recipe source
GitHub , Issue Tracker , Maven Central
This recipe is available under the Moderne Source Available License .
Example
- build.gradle
- Diff
Before
plugins {
id "java"
id "org.springframework.boot" version "1.5.22.RELEASE"
}
repositories {
mavenCentral()
}
dependencyManagement { }
dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
}
After
plugins {
id "java"
id "org.springframework.boot" version "1.5.22.RELEASE"
id "io.spring.dependency-management" version "1.0.6.RELEASE"
}
repositories {
mavenCentral()
}
dependencyManagement { }
dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
}
--- build.gradle
+++ build.gradle
@@ -4,0 +4,1 @@
id "java"
id "org.springframework.boot" version "1.5.22.RELEASE"
+ id "io.spring.dependency-management" version "1.0.6.RELEASE"
}
Usage
This recipe has no required configuration options. It can be activated by adding a dependency on
org.openrewrite.recipe:rewrite-spring
in your build file or by running a shell command (in which case no build changes are needed):
- Gradle
- Gradle init script
- Moderne CLI
-
Add the following to your
build.gradlefile:
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.gradle.spring.AddSpringDependencyManagementPlugin")
setExportDatatables(true)
}
repositories {
mavenCentral()
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-spring:6.9.0")
}
-
Run
gradle rewriteRunto run the recipe. -
Create a file named
init.gradlein the root of your project.
initscript {
repositories {
maven { url "https://plugins.gradle.org/m2" }
}
dependencies { classpath("org.openrewrite:plugin:7.9.0") }
}
rootProject {
plugins.apply(org.openrewrite.gradle.RewritePlugin)
dependencies {
rewrite("org.openrewrite.recipe:rewrite-spring:6.9.0")
}
rewrite {
activeRecipe("org.openrewrite.gradle.spring.AddSpringDependencyManagementPlugin")
setExportDatatables(true)
}
afterEvaluate {
if (repositories.isEmpty()) {
repositories {
mavenCentral()
}
}
}
}
- Run the recipe.
gradle --init-script init.gradle rewriteRun
You will need to have configured the Moderne CLI on your machine before you can run the following command.
mod run . --recipe AddSpringDependencyManagementPlugin
If the recipe is not available locally, then you can install it using:
mod config recipes jar install org.openrewrite.recipe:rewrite-spring:6.9.0
See how this recipe works across multiple open-source repositories
Run this recipe on OSS repos at scale with the Moderne SaaS.