diff --git a/src/main/resources/META-INF/rewrite/java-version-17.yml b/src/main/resources/META-INF/rewrite/java-version-17.yml index d8a8538bc2..1da448fd01 100644 --- a/src/main/resources/META-INF/rewrite/java-version-17.yml +++ b/src/main/resources/META-INF/rewrite/java-version-17.yml @@ -58,6 +58,19 @@ recipeList: groupId: commons-codec artifactId: commons-codec newVersion: 1.17.x + # As it's a Maven plugin, we should only need Maven versions of these upgrades + - org.openrewrite.maven.UpgradeDependencyVersion: + groupId: com.github.spotbugs + artifactId: spotbugs-maven-plugin + newVersion: 4.9.x + - org.openrewrite.maven.UpgradePluginVersion: + groupId: com.github.spotbugs + artifactId: spotbugs-maven-plugin + newVersion: 4.9.x + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.mapstruct + artifactId: mapstruct* + newVersion: 1.6.x - org.openrewrite.java.migrate.AddLombokMapstructBinding - org.openrewrite.java.migrate.UpdateJakartaAnnotationsIfForJavax - org.openrewrite.java.migrate.UpdateJakartaAnnotationsIfExistsForJakarta @@ -325,7 +338,6 @@ recipeList: groupId: org.projectlombok artifactId: lombok-mapstruct-binding version: 0.2.0 - --- # The scanning phase comes before the editing phase, therefor we check if a javax.annotation dependency is on the classpath (with whatever version) type: specs.openrewrite.org/v1beta/recipe diff --git a/src/test/java/org/openrewrite/java/migrate/UpgradeToJava17Test.java b/src/test/java/org/openrewrite/java/migrate/UpgradeToJava17Test.java index e4e03109d8..b16d7576f3 100644 --- a/src/test/java/org/openrewrite/java/migrate/UpgradeToJava17Test.java +++ b/src/test/java/org/openrewrite/java/migrate/UpgradeToJava17Test.java @@ -27,6 +27,8 @@ import java.util.regex.Pattern; import static org.assertj.core.api.Assertions.assertThat; +import static org.openrewrite.gradle.Assertions.buildGradle; +import static org.openrewrite.gradle.toolingapi.Assertions.withToolingApi; import static org.openrewrite.java.Assertions.*; import static org.openrewrite.maven.Assertions.pomXml; @@ -571,4 +573,115 @@ void init() {} 8) ); } + + @Test + void upgradeSpotbugsPluginVersion() { + rewriteRun( + pomXml( + //language=xml + """ + + 4.0.0 + com.mycompany.app + my-app + 1 + + + + com.github.spotbugs + spotbugs-maven-plugin + 3.1.0 + + + + + + + com.github.spotbugs + spotbugs-maven-plugin + 3.1.0 + + + + + """, + spec -> spec.after(actual -> + assertThat(actual) + .containsPattern("4.9.\\d+(.\\d+)?") + .doesNotContain("3.1.0") + .actual() + ) + ) + ); + } + + @Test + void upgradeMapstructAndAnnotationPaths() { + rewriteRun( + pomXml( + //language=xml + """ + + 4.0.0 + com.mycompany.app + my-app + 1 + + + org.mapstruct + mapstruct + 1.4.0.Final + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + + org.mapstruct + mapstruct-processor + 1.4.1.Final + + + + + + + + """, + spec -> spec.after(actual -> + assertThat(actual) + .doesNotContain("1.4.0.Final") + // TODO .doesNotContain("1.4.1.Final") // after https://github.com/openrewrite/rewrite/pull/5936 + .actual()) + ) + ); + } + + @Test + void upgradeMapstructAndAnnotationPathsWithGradle() { + rewriteRun( + spec -> spec.beforeRecipe(withToolingApi()), + buildGradle( + //language=groovy + """ + plugins { id 'java' } + repositories { mavenCentral() } + dependencies { + implementation 'org.mapstruct:mapstruct:1.4.1.Final' + annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.1.Final' + } + """, + spec -> spec.after(actual -> + assertThat(actual) + .doesNotContain("1.4.1.Final") + .containsPattern("1.6.\\d+(.\\d+)?") + .actual()) + ) + ); + } }