openrewrite / rewrite-spring

OpenRewrite recipes for Spring projects.
Apache License 2.0
253 stars 73 forks source link

`jakarta.validation-api` dependency added while upgrading Spring Petclinic example #542

Closed BoykoAlex closed 3 months ago

BoykoAlex commented 3 months ago

The jakarta.validation-api dependency shouldn't be present while upgrading Spring Petclinic to Boot 3.x. This dependency is transitive coming in via spring-boot-validation-starter.

The problem is that first javax validation-api dependency added explicitly. Then the validation-api is transformed into jakarta.validation-api.

I'd try to work with the problem of adding javax validation-api. It is added via org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_0 -> org.openrewrite.java.spring.boot2.MigrateHibernateConstraintsToJavax

Namely this bit of YAML:

  - org.openrewrite.java.dependencies.AddDependency:
      groupId: javax.validation
      artifactId: validation-api
      version: 2.x
      onlyIfUsing: javax.validation.constraints.*

At this moment the petclinic is on Boot 2.7.x which is on jakarta.validation-api version 2.0.x already. Consequently, the old validation-api dependency has no issues to be added.

Wonder if there is a condition in the YAML recipe that could prevent execution of recipes under 2.7.x for the 2.7.x project that we could add in spring upgrade yaml recipes...

Anything you can recommend @timtebeek and @sambsnyd ?