Skip to content

Add jakarta.annotation-api dependency when using javax.annotation#972

Merged
jkschneider merged 1 commit intomainfrom
jkschneider/add-jakarta-annotation-dependency
Jan 26, 2026
Merged

Add jakarta.annotation-api dependency when using javax.annotation#972
jkschneider merged 1 commit intomainfrom
jkschneider/add-jakarta-annotation-dependency

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
mergify bot added a commit to robfrank/linklift that referenced this pull request Feb 14, 2026
…26.0 to 3.27.0 [skip ci]

Bumps [org.openrewrite.recipe:rewrite-migrate-java](https://github.com/openrewrite/rewrite-migrate-java) from 3.26.0 to 3.27.0.
Release notes

*Sourced from [org.openrewrite.recipe:rewrite-migrate-java's releases](https://github.com/openrewrite/rewrite-migrate-java/releases).*

> 3.27.0
> ------
>
> What's Changed
> --------------
>
> * Add jakarta.annotation-api dependency when using javax.annotation by [`@​jkschneider`](https://github.com/jkschneider) in [openrewrite/rewrite-migrate-java#972](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/972)
> * Add com.sun.istack.NotNull migration to Jakarta validation by [`@​jkschneider`](https://github.com/jkschneider) in [openrewrite/rewrite-migrate-java#973](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/973)
> * Add UseListOf and UseSetOf recipes by [`@​jkschneider`](https://github.com/jkschneider) in [openrewrite/rewrite-migrate-java#974](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/974)
> * Lombok Annotation Processor Configuration by [`@​MBoegers`](https://github.com/MBoegers) in [openrewrite/rewrite-migrate-java#977](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/977)
> * Migrate GraalVM resource-config.json from regex to glob patterns by [`@​MBoegers`](https://github.com/MBoegers) in [openrewrite/rewrite-migrate-java#976](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/976)
> * Followup after the formatting merge by [`@​Jenson3210`](https://github.com/Jenson3210) in [openrewrite/rewrite-migrate-java#978](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/978)
> * Avoid line continuation escapes in text blocks with mixed newline content by [`@​Jenson3210`](https://github.com/Jenson3210) in [openrewrite/rewrite-migrate-java#975](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/975)
> * Change Docker image version in Java upgrades by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#980](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/980)
>
> **Full Changelog**: <openrewrite/rewrite-migrate-java@v3.26.0...v3.27.0>


Commits

* [`04592ca`](openrewrite/rewrite-migrate-java@04592ca) Expect continuation indent in text blocks
* [`f42714b`](openrewrite/rewrite-migrate-java@f42714b) Delete files
* [`9499e38`](openrewrite/rewrite-migrate-java@9499e38) [Auto] SDKMAN! Java candidates as of 2026-02-09T1052
* [`ca26543`](openrewrite/rewrite-migrate-java@ca26543) Change Docker image version in Java upgrades ([#980](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/980))
* [`6e525a1`](openrewrite/rewrite-migrate-java@6e525a1) Make declarative recipes singletons
* [`dc6029d`](openrewrite/rewrite-migrate-java@dc6029d) [Auto] SDKMAN! Java candidates as of 2026-02-02T1038
* [`e13f6e8`](openrewrite/rewrite-migrate-java@e13f6e8) Update documentation examples
* [`653dd7c`](openrewrite/rewrite-migrate-java@653dd7c) Add avoidLineContinuations option to UseTextBlocks ([#975](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/975))
* [`c6b1bcf`](openrewrite/rewrite-migrate-java@c6b1bcf) Followup after the formatting merge ([#978](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/978))
* [`4f3aaa0`](openrewrite/rewrite-migrate-java@4f3aaa0) Migrate GraalVM resource-config.json from regex to glob patterns ([#976](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/976))
* Additional commits viewable in [compare view](openrewrite/rewrite-migrate-java@v3.26.0...v3.27.0)
  
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=org.openrewrite.recipe:rewrite-migrate-java&package-manager=maven&previous-version=3.26.0&new-version=3.27.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
Dependabot commands and options
  
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot show  ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant