Summary
- Added
AddDependency recipe to JavaxAnnotationMigrationToJakartaAnnotation to add jakarta.annotation:jakarta.annotation-api when javax.annotation.* classes are in use
- Added test case covering the transitive dependency scenario
Problem
When migrating from javax.annotation to jakarta.annotation, the recipe was only changing/upgrading the dependency if it already existed explicitly. If the javax.annotation classes (like @Priority) were available transitively, the migration would change the import statements but not add the jakarta.annotation-api dependency, causing compilation failures.
This is inconsistent with how other migration recipes (like JavaxMailToJakartaMail, JavaxServletToJakartaServlet, JavaxWsToJakartaWs) handle this scenario - they all include an AddDependency recipe with onlyIfUsing to ensure the dependency is present.
Solution
Added AddDependency recipe to JavaxAnnotationMigrationToJakartaAnnotation:
- org.openrewrite.java.dependencies.AddDependency:
groupId: jakarta.annotation
artifactId: jakarta.annotation-api
version: 2.0.x
onlyIfUsing: javax.annotation..*
acceptTransitive: true
Test plan