diff --git a/build.gradle.kts b/build.gradle.kts index f424b0231..15d14c0e9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { group = "org.openrewrite.recipe" description = "Eliminate legacy Spring patterns and migrate between major Spring Boot versions. Automatically." -val springBootVersions: List = listOf("1_5", "2_1", "2_2", "2_3", "2_4", "2_5", "2_6", "2_7", "3_0", "3_2", "3_3", "3_4") +val springBootVersions: List = listOf("1_5", "2_1", "2_2", "2_3", "2_4", "2_5", "2_6", "2_7", "3_0", "3_2", "3_3", "3_4", "3_5") val springSecurityVersions: List = listOf("5_7", "5_8", "6_2") val sourceSetNames: Map> = mapOf( diff --git a/src/main/resources/META-INF/rewrite/spring-boot-35-properties.yml b/src/main/resources/META-INF/rewrite/spring-boot-35-properties.yml new file mode 100644 index 000000000..40eb55ad0 --- /dev/null +++ b/src/main/resources/META-INF/rewrite/spring-boot-35-properties.yml @@ -0,0 +1,108 @@ +# +# Copyright 2025 the original author or authors. +#

+# Licensed under the Moderne Source Available License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +#

+# https://docs.moderne.io/licensing/moderne-source-available-license +#

+# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# This file is automatically generated by the GeneratePropertiesMigratorConfiguration class. +# Do not edit this file manually. Update the Spring Boot property metadata upstream instead. +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.spring.boot3.SpringBootProperties_3_5 +displayName: Migrate Spring Boot properties to 3.5 +description: Migrate properties found in `application.properties` and `application.yml`. +tags: + - spring + - boot +recipeList: + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: management.promethus.metrics.export.pushgateway.base-url + newPropertyKey: management.prometheus.metrics.export.pushgateway.address + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.codec.log-request-details + newPropertyKey: spring.http.codecs.log-request-details + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.codec.max-in-memory-size + newPropertyKey: spring.http.codecs.max-in-memory-size + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.graphql.path + newPropertyKey: spring.graphql.http.path + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.graphql.sse.timeout + newPropertyKey: spring.graphql.http.sse.timeout + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.groovy.template.configuration.auto-escape + newPropertyKey: spring.groovy.template.auto-escape + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.groovy.template.configuration.auto-indent + newPropertyKey: spring.groovy.template.auto-indent + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.groovy.template.configuration.auto-indent-string + newPropertyKey: spring.groovy.template.auto-indent-string + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.groovy.template.configuration.auto-new-line + newPropertyKey: spring.groovy.template.auto-new-line + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.groovy.template.configuration.base-template-class + newPropertyKey: spring.groovy.template.base-template-class + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.groovy.template.configuration.cache-templates + newPropertyKey: spring.groovy.template.cache + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.groovy.template.configuration.declaration-encoding + newPropertyKey: spring.groovy.template.declaration-encoding + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.groovy.template.configuration.expand-empty-elements + newPropertyKey: spring.groovy.template.expand-empty-elements + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.groovy.template.configuration.locale + newPropertyKey: spring.groovy.template.locale + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.groovy.template.configuration.new-line-string + newPropertyKey: spring.groovy.template.new-line-string + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.groovy.template.configuration.resource-loader-path + newPropertyKey: spring.groovy.template.resource-loader-path + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.groovy.template.configuration.use-double-quotes + newPropertyKey: spring.groovy.template.use-double-quotes + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.mvc.converters.preferred-json-mapper + newPropertyKey: spring.http.converters.preferred-json-mapper + + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: management.signalfx.metrics.export.access-token + comment: "This property is deprecated: Deprecated in Micrometer 1.15.0" + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: management.signalfx.metrics.export.batch-size + comment: "This property is deprecated: Deprecated in Micrometer 1.15.0" + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: management.signalfx.metrics.export.connect-timeout + comment: "This property is deprecated: Deprecated in Micrometer 1.15.0" + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: management.signalfx.metrics.export.enabled + comment: "This property is deprecated: Deprecated in Micrometer 1.15.0" + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: management.signalfx.metrics.export.published-histogram-type + comment: "This property is deprecated: Deprecated in Micrometer 1.15.0" + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: management.signalfx.metrics.export.read-timeout + comment: "This property is deprecated: Deprecated in Micrometer 1.15.0" + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: management.signalfx.metrics.export.source + comment: "This property is deprecated: Deprecated in Micrometer 1.15.0" + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: management.signalfx.metrics.export.step + comment: "This property is deprecated: Deprecated in Micrometer 1.15.0" + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: management.signalfx.metrics.export.uri + comment: "This property is deprecated: Deprecated in Micrometer 1.15.0" diff --git a/src/main/resources/META-INF/rewrite/spring-boot-35.yml b/src/main/resources/META-INF/rewrite/spring-boot-35.yml new file mode 100644 index 000000000..fa9c500f0 --- /dev/null +++ b/src/main/resources/META-INF/rewrite/spring-boot-35.yml @@ -0,0 +1,51 @@ +# +# Copyright 2025 the original author or authors. +#

+# Licensed under the Moderne Source Available License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +#

+# https://docs.moderne.io/licensing/moderne-source-available-license +#

+# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_5 +displayName: Migrate to Spring Boot 3.5 +description: >- + Migrate applications to the latest Spring Boot 3.5 release. This recipe will modify an application's build files, + make changes to deprecated/preferred APIs. +tags: + - spring + - boot +recipeList: + - org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_4 + - org.openrewrite.java.spring.boot3.SpringBootProperties_3_5 + - org.openrewrite.java.spring.cloud2025.UpgradeSpringCloud_2025 + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.springframework.boot + artifactId: "*" + newVersion: 3.5.x + overrideManagedVersion: false + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.springframework.boot + artifactId: spring-boot-dependencies + newVersion: 3.5.x + overrideManagedVersion: true + - org.openrewrite.maven.UpgradePluginVersion: + groupId: org.springframework.boot + artifactId: spring-boot-maven-plugin + newVersion: 3.5.x + - org.openrewrite.maven.UpgradeParentVersion: + groupId: org.springframework.boot + artifactId: spring-boot-starter-parent + newVersion: 3.5.x + - org.openrewrite.gradle.plugins.UpgradePluginVersion: + pluginIdPattern: org.springframework.boot + newVersion: 3.5.x diff --git a/src/main/resources/META-INF/rewrite/spring-cloud-2025.yml b/src/main/resources/META-INF/rewrite/spring-cloud-2025.yml new file mode 100644 index 000000000..b4f1fa4d5 --- /dev/null +++ b/src/main/resources/META-INF/rewrite/spring-cloud-2025.yml @@ -0,0 +1,209 @@ +# +# Copyright 2025 the original author or authors. +#

+# Licensed under the Moderne Source Available License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +#

+# https://docs.moderne.io/licensing/moderne-source-available-license +#

+# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.spring.cloud2025.UpgradeSpringCloud_2025 +displayName: Migrate to Spring Cloud 2025 +description: Migrate applications to the latest Spring Cloud 2025 (Northfields) release. +tags: + - spring + - cloud +recipeList: + # Do not chain previous versions of Spring Cloud; leave inclusion up to Spring Boot migrations to avoid duplicates + - org.openrewrite.java.spring.cloud2025.DependencyUpgrades + - org.openrewrite.java.spring.cloud2025.SpringCloudGatewayDeprecatedModulesAndStarters + - org.openrewrite.java.spring.cloud2025.SpringCloudGatewayProperties + - org.openrewrite.java.spring.cloud2025.SpringCloudGatewayWebfluxProperties + - org.openrewrite.java.spring.cloud2025.SpringCloudGatewayProxyWebfluxProperties + - org.openrewrite.java.spring.cloud2025.SpringCloudGatewayWebMvcProperties + - org.openrewrite.java.spring.cloud2025.SpringCloudGatewayProxyWebMvcProperties + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.spring.cloud2025.DependencyUpgrades +displayName: Upgrade dependencies to Spring Cloud 2025 +description: Upgrade dependencies to Spring Cloud 2025 from prior 2024.x version. +tags: + - spring + - cloud +recipeList: + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.springframework.cloud + artifactId: "*" + newVersion: 4.3.x + overrideManagedVersion: false + - org.openrewrite.maven.UpgradeParentVersion: + groupId: org.springframework.cloud + artifactId: spring-cloud-starter-parent + newVersion: 2025.0.x + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.springframework.cloud + artifactId: spring-cloud-dependencies + newVersion: 2025.0.x + overrideManagedVersion: false + + # circuitbreaker, kubernetes & task follow a different versioning scheme + # https://docs.spring.io/spring-cloud-release/reference/2025.0/ + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.springframework.cloud + artifactId: spring-cloud-starter-circuitbreaker-* + newVersion: 3.3.x + overrideManagedVersion: false + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.springframework.cloud + artifactId: spring-cloud-circuitbreaker-* + newVersion: 3.3.x + overrideManagedVersion: false + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.springframework.cloud + artifactId: spring-cloud-starter-kubernetes-* + newVersion: 3.3.x + overrideManagedVersion: false + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.springframework.cloud + artifactId: spring-cloud-kubernetes-* + newVersion: 3.3.x + overrideManagedVersion: false + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.springframework.cloud + artifactId: spring-cloud-starter-task-* + newVersion: 3.3.x + overrideManagedVersion: false + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.springframework.cloud + artifactId: spring-cloud-task-* + newVersion: 3.3.x + overrideManagedVersion: false + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.spring.cloud2025.SpringCloudGatewayDeprecatedModulesAndStarters +displayName: Migrate to New Spring Cloud Gateway Modules and Starters +description: Migrate to new Spring Cloud Gateway modules and starters for Spring Cloud 2025 +tags: + - spring + - cloud +recipeList: + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springframework.cloud + oldArtifactId: spring-cloud-gateway-server + newArtifactId: spring-cloud-gateway-server-webflux + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springframework.cloud + oldArtifactId: spring-cloud-gateway-server-mvc + newArtifactId: spring-cloud-gateway-server-webmvc + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springframework.cloud + oldArtifactId: spring-cloud-starter-gateway-server + newArtifactId: spring-cloud-starter-gateway-server-webflux + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springframework.cloud + oldArtifactId: spring-cloud-starter-gateway-server-mvc + newArtifactId: spring-cloud-starter-gateway-server-webmvc + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springframework.cloud + oldArtifactId: spring-cloud-gateway-mvc + newArtifactId: spring-cloud-gateway-proxyexchange-webmvc + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springframework.cloud + oldArtifactId: spring-cloud-gateway-webflux + newArtifactId: spring-cloud-gateway-proxyexchange-webflux + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.spring.cloud2025.SpringCloudGatewayProperties +displayName: Migrate Spring Cloud Gateway Properties +description: Migrate Spring Cloud Gateway properties for Spring Cloud 2025 release. +tags: + - spring + - cloud +recipeList: + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.cloud.gateway + newPropertyKey: spring.cloud.gateway.server.webflux + except: ["proxy"] + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.cloud.gateway.mvc + newPropertyKey: spring.cloud.gateway.server.webmvc + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.spring.cloud2025.SpringCloudGatewayWebfluxProperties +displayName: Migrate Spring Cloud Gateway Webflux Properties +description: Migrate Spring Cloud Gateway Webflux properties for Spring Cloud 2025 release. +tags: + - spring + - cloud +preconditions: + - org.openrewrite.java.dependencies.search.ModuleHasDependency: + groupIdPattern: org.springframework.cloud + artifactIdPattern: spring-cloud-gateway-webflux +recipeList: + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.cloud.gateway.proxy + newPropertyKey: spring.cloud.gateway.proxy-exchange.webflux + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.spring.cloud2025.SpringCloudGatewayProxyWebfluxProperties +displayName: Migrate Spring Cloud Gateway Proxy Webflux Properties +description: Migrate Spring Cloud Gateway Proxy Webflux properties for Spring Cloud 2025 release. +tags: + - spring + - cloud +preconditions: + - org.openrewrite.java.dependencies.search.ModuleHasDependency: + groupIdPattern: org.springframework.cloud + artifactIdPattern: spring-cloud-gateway-proxyexchange-webflux +recipeList: + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.cloud.gateway.proxy + newPropertyKey: spring.cloud.gateway.proxy-exchange.webflux + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.spring.cloud2025.SpringCloudGatewayWebMvcProperties +displayName: Migrate Spring Cloud Gateway WebMvc Properties +description: Migrate Spring Cloud Gateway WebMvc properties for Spring Cloud 2025 release. +tags: + - spring + - cloud +preconditions: + - org.openrewrite.java.dependencies.search.ModuleHasDependency: + groupIdPattern: org.springframework.cloud + artifactIdPattern: spring-cloud-gateway-mvc +recipeList: + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.cloud.gateway.proxy + newPropertyKey: spring.cloud.gateway.proxy-exchange.webmvc + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.spring.cloud2025.SpringCloudGatewayProxyWebMvcProperties +displayName: Migrate Spring Cloud Gateway Proxy WebMvc Properties +description: Migrate Spring Cloud Gateway Proxy WebMvc properties for Spring Cloud 2025 release. +tags: + - spring + - cloud +preconditions: + - org.openrewrite.java.dependencies.search.ModuleHasDependency: + groupIdPattern: org.springframework.cloud + artifactIdPattern: spring-cloud-gateway-proxyexchange-webmvc +recipeList: + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.cloud.gateway.proxy + newPropertyKey: spring.cloud.gateway.proxy-exchange-webmvc diff --git a/src/testWithSpringBoot_3_5/java/org/openrewrite/java/spring/boot3/UpgradeSpringBoot_3_5Test.java b/src/testWithSpringBoot_3_5/java/org/openrewrite/java/spring/boot3/UpgradeSpringBoot_3_5Test.java new file mode 100644 index 000000000..4d440f88c --- /dev/null +++ b/src/testWithSpringBoot_3_5/java/org/openrewrite/java/spring/boot3/UpgradeSpringBoot_3_5Test.java @@ -0,0 +1,61 @@ +/* + * Copyright 2025 the original author or authors. + *

+ * Licensed under the Moderne Source Available License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://docs.moderne.io/licensing/moderne-source-available-license + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.java.spring.boot3; + +import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.openrewrite.java.Assertions.mavenProject; +import static org.openrewrite.maven.Assertions.pomXml; + +class UpgradeSpringBoot_3_5Test implements RewriteTest { + + @Override + public void defaults(RecipeSpec spec) { + spec.recipeFromResources("org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_5"); + } + + @DocumentExample + @Test + void upgradeVersion() { + rewriteRun( + mavenProject("project", + //language=xml + pomXml( + """ + + 4.0.0 + com.example + fooservice + 1.0-SNAPSHOT + + org.springframework.boot + spring-boot-starter-parent + 3.4.9 + + + + """, + spec -> spec.after(actual -> + assertThat(actual).containsPattern("3.5.\\d+").actual()) + ) + ) + ); + } +} diff --git a/src/testWithSpringBoot_3_5/java/org/openrewrite/java/spring/boot3/UpgradeSpringCloud2025Test.java b/src/testWithSpringBoot_3_5/java/org/openrewrite/java/spring/boot3/UpgradeSpringCloud2025Test.java new file mode 100644 index 000000000..0d1c7998e --- /dev/null +++ b/src/testWithSpringBoot_3_5/java/org/openrewrite/java/spring/boot3/UpgradeSpringCloud2025Test.java @@ -0,0 +1,73 @@ +/* + * Copyright 2025 the original author or authors. + *

+ * Licensed under the Moderne Source Available License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://docs.moderne.io/licensing/moderne-source-available-license + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.java.spring.boot3; + +import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.openrewrite.java.Assertions.mavenProject; +import static org.openrewrite.java.Assertions.srcMainResources; +import static org.openrewrite.maven.Assertions.pomXml; +import static org.openrewrite.properties.Assertions.properties; + +class UpgradeSpringCloud2025Test implements RewriteTest { + + @Override + public void defaults(RecipeSpec spec) { + spec.recipeFromResources("org.openrewrite.java.spring.cloud2025.UpgradeSpringCloud_2025"); + } + + @DocumentExample + @Test + void renameProperty() { + rewriteRun( + mavenProject("project", + pomXml( + //language=xml + """ + + 4.0.0 + com.example + fooservice + 1.0-SNAPSHOT + + + org.springframework.cloud + spring-cloud-gateway-webflux + 4.2.4 + + + + """, + spec -> spec.after(pom -> assertThat(pom) + .containsPattern("4\\.3\\.\\d+") + .actual()) + ), + srcMainResources( + //language=properties + properties( + "spring.cloud.gateway.proxy=foo", + "spring.cloud.gateway.proxy-exchange.webflux=foo", + spec -> spec.path("application.properties") + ) + ) + ) + ); + } +}