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_3 must not add spring-boot-starter-validation if project has explicit [javax | jakarta].validation declared #439

Open
Philzen opened this issue Oct 25, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@Philzen
Copy link

Philzen commented Oct 25, 2023

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):

@Philzen Philzen added the bug Something isn't working label Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

1 participant