Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgradespringboot_2_7: Include de.flapdoodle.embed in migration #441

Open
Philzen opened this issue Nov 1, 2023 · 0 comments
Open

upgradespringboot_2_7: Include de.flapdoodle.embed in migration #441

Philzen opened this issue Nov 1, 2023 · 0 comments
Labels
boot-2.7 enhancement New feature or request recipe Recipe requested

Comments

@Philzen
Copy link

Philzen commented Nov 1, 2023

What problem are you trying to solve?

Spring Boot 2.7 dropped support for Embedded Mongo, incl. the configuration property required to configure it.

See https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.7-Release-Notes#springmongodbembeddedfeatures-configuration-property-removed

Depending on perspective, this could also be considered a bug b/c when https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring is listed in the POMs test scope dependencies the project will no longer build after having migrated to 2.7.x with the recipe.

Describe the solution you'd like

1. POM modifications:

When the recipe finds this dependency:

        <dependency>
            <groupId>de.flapdoodle.embed</groupId>
            <artifactId>de.flapdoodle.embed.mongo</artifactId>
            <scope>test</scope>
        </dependency>

It needs to upgrade the POM as follows (4.9.3 is the latest version as of today, it should ideally always refer to the latest):

    <properties>
        <!-- ↓ add this version override (which exists in `spring-boot-dependencies`) -->
        <embedded-mongo.version>4.9.3</embedded-mongo.version>
    </properties>

The above is important so the transitive dependency for the following update is resolved correctly (could very well be done with a dedicated <dependencyManagement> section, but for what it's worth this is the most concise solution:

        <!-- ↓ This REPLACES the dependency `de.flapdoodle.embed.mongo` -->
        <dependency>
            <groupId>de.flapdoodle.embed</groupId>
            <artifactId>de.flapdoodle.embed.mongo.spring27x</artifactId>
            <version>${embedded-mongo.version}</version>
            <scope>test</scope>
        </dependency>

The whole change as a diff example:

@@ -20,6 +20,7 @@
          <java.version>11</java.version>
          <junit-jupiter.version>5.10.0</junit-jupiter.version>
+        <embedded-mongo.version>4.9.3</embedded-mongo.version>
     </properties>
@@ -224,7 +219,8 @@
         </dependency>
         <dependency>
             <groupId>de.flapdoodle.embed</groupId>
-            <artifactId>de.flapdoodle.embed.mongo</artifactId>
+            <artifactId>de.flapdoodle.embed.mongo.spring27x</artifactId>
+            <version>${embedded-mongo.version}</version>
             <scope>test</scope>
         </dependency>
     </dependencies>

2. Migrate properties

If it finds the following property in application.properties, respectively YAML:

spring.mongodb.embedded.version={VERSION_STRING}

This will need to be replaced by:

de.flapdoodle.mongodb.embedded.version={VERSION_STRING}

An example diff from my manual upgrade:

--- a/src/test/resources/application-integration-test.yaml
+++ b/src/test/resources/application-integration-test.yaml
@@ -1,12 +1,10 @@
+de.flapdoodle.mongodb.embedded.version: 3.4.0
 spring:
   main:
     banner-mode: "off"
   data:
     mongodb:
       port: 0
-  mongodb:
-    embedded:
-      version: 3.4.0
 
 logging:
   level:

(note that i'm using grouped single leaf nodes style here, which not everybody's style, but it is legal b/c of the way spring boot converts all yaml to properties).

Have you considered any alternatives or workarounds?

Switching to Testcontainers would be an alternative, however that would require changes to the integration test codebase as well and may not work out-of-the-box for all environments.

Context

3.x recipes

This will be relevant for the 3.x recipes as well, which require these dependencies:

From what i can tell, the version override <property> can be removed by the spring 3.0 recipe again, the rest would be the same, but i haven't reached that migration step yet but can confirm once i do.

Programmatic properties

There may be additional changes required if the embedded mongo db version is not managed via a properties/yaml file but programmatically, however i have no exact knowledge or experience in that area given the projects i'm working on.

These files describe the potentially required changes:

Are you interested in contributing this feature to OpenRewrite?

If somebody could point me at an example that implements these 3 types of replacements (1. add pom propery, 2. replace dependency block, 3. replace a key in .properties and .yaml) and the accompanying tests, i could give it a go, but as my time is very limited ATM i cannot promise when i find the time.

@Philzen Philzen added the enhancement New feature or request label Nov 1, 2023
@Philzen Philzen changed the title upgradespringboot_2_7: Also upgrade de.flapdoodle.embed to a working version upgradespringboot_2_7: Include de.flapdoodle.embed in migration Nov 1, 2023
@Philzen Philzen changed the title upgradespringboot_2_7: Include de.flapdoodle.embed in migration upgradespringboot_2_7: Include de.flapdoodle.embed in migration Nov 1, 2023
@timtebeek timtebeek added recipe Recipe requested boot-2.7 labels Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
boot-2.7 enhancement New feature or request recipe Recipe requested
Projects
Status: Backlog
Development

No branches or pull requests

2 participants