openrewrite / openrewrite/rewrite-spring
upgradespringboot_2_7: Include `de.flapdoodle.embed` in migration
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 403
- Forks
- 149
- Avg merge
- 2h 33m
- Merged PRs (30d)
- 10
Description
What problem are you trying to solve?
Spring Boot 2.7 dropped support for Embedded Mongo, incl. the configuration property required to configure it.
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:
- https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/tree/spring-3.0.x
- https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/tree/spring-3.1.x
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:
- https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/blob/spring-2.7.x/HowTo.md
- https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/blob/spring-3.0.x/HowTo.md
- https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/blob/spring-3.1.x/HowTo.md
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the upgradespringboot_2_7 recipe and its accompanying tests, then run the existing recipe test suite first. Implement the documented POM dependency and property changes, plus the spring.mongodb.embedded.version replacement in properties and YAML; done means all three transformations are covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- build-system, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100