Skip to content

Conversation

@jkschneider
Copy link
Member

@jkschneider jkschneider commented Jan 25, 2026

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

  • Existing tests pass

  • New test added for the transitive dependency scenario

  • Fixes moderneinc/customer-requests#1563

When migrating from javax.annotation to jakarta.annotation, the recipe was
only changing the dependency if it already existed explicitly. If the
javax.annotation classes were available transitively, the migration would
change the import statements but not add the jakarta.annotation-api dependency,
causing compilation failures.

Added AddDependency recipe to JavaxAnnotationMigrationToJakartaAnnotation
to ensure the jakarta.annotation-api dependency is added when javax.annotation
classes are in use, consistent with how other migration recipes handle this.

Fixes moderneinc/customer-requests#1563
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Jan 25, 2026
@jkschneider jkschneider merged commit 4f2dca1 into main Jan 26, 2026
2 checks passed
@jkschneider jkschneider deleted the jkschneider/add-jakarta-annotation-dependency branch January 26, 2026 00:15
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants