upgradespringboot_2_3 must not add spring-boot-starter-validation if project has explicit [javax | jakarta].validation declared
What version of OpenRewrite are you using?
I am using
- OpenRewrite v8.8.0
- RewriteSpring v5.0.11
How are you running OpenRewrite?
From the CLI using
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_7
What is the smallest, simplest way to reproduce the problem?
If have this dependency in my project (which due to #437 always gets changed back to javax, but that's a different issue which anyway boils down to the same in this context).
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<!-- Version is managed by SpringBoot -->
</dependency>
What did you expect to see?
No change to the spring-boot-dependencies section.
What did you see instead?
The recipe added
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
to the POM.
Overall, the fact that this change is included in the recipe is correct and necessary due to https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3-Release-Notes#validation-starter-no-longer-included-in-web-starters
However it took me a while to understand this and to come to the conclusion that in the described case it's safe to remove that additional dependency again (which otherwise needlessly increases the size of the fat jar).
So, there these two small things that should be improved in the 2.3 recipe, which includes this rule:
Add Gradle or Maven dependency
- groupId: org.springframework.boot
- artifactId: spring-boot-starter-validation
- version: 2.3.x
- onlyIfUsing: javax.validation.constraints.*
- acceptTransitive: true
I'm not (yet) familiar with the properties available to configure a recipe, but this would need to be changed to something like (using made-up configuration language here):
- onlyIfUsing: javax.validation.constraints.* | jakarta.validation.constraints.* (referring to #437)
- onlyIfNotExplicitlyDeclared: true