Skip to content

feat(mvnup): add JakartaEeApiMigrationStrategy for JEP 320 removed API artifacts (#14163) - #14169

Open
gnodet wants to merge 2 commits into
apache:masterfrom
gnodet:fix/14163-java-ee-apis
Open

gnodet wants to merge 2 commits into
apache:masterfrom
gnodet:fix/14163-java-ee-apis

Conversation

@gnodet

@gnodet gnodet commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Introduces JakartaEeApiMigrationStrategy, a new mvnup upgrade strategy that
detects and migrates legacy Java EE API Maven dependencies to their Jakarta EE
equivalents.

Root Cause

Java 11 (JEP 320) removed several Java EE modules from the JDK that were
previously bundled in rt.jar: JAXB (javax.xml.bind), JAX-WS (javax.xml.ws),
javax.annotation, javax.activation, and javax.jws. Projects that declared
these APIs as explicit Maven dependencies (e.g. javax.xml.bind:jaxb-api) will
fail to compile on JDK 11+ unless they migrate to the standalone Jakarta EE
equivalents.

mvnup previously had no handling for these JEP 320 removed APIs. The existing
ToolchainPluginStrategy only acts on JEP 182 retired source levels (≤7) and
does not detect JEP 320-removed API usage even when source=8 is declared.

Fix

The new JakartaEeApiMigrationStrategy (priority 16, runs alongside
ToolchainPluginStrategy) scans all dependency sections in each POM file:

  • <dependencies>
  • <dependencyManagement><dependencies>
  • Profile <dependencies> and <dependencyManagement>
  • Plugin-level <dependencies> (e.g. maven-antrun-plugin)

When a legacy Java EE artifact is found, it is replaced in-place with the
last Jakarta EE release that preserves the javax.* package namespace — making
it source-compatible without requiring import changes:

Legacy (removed in JDK 11) Jakarta EE replacement
javax.xml.bind:jaxb-api jakarta.xml.bind:jakarta.xml.bind-api:2.3.3
com.sun.xml.bind:jaxb-core org.glassfish.jaxb:jaxb-core:2.3.0.1
com.sun.xml.bind:jaxb-impl org.glassfish.jaxb:jaxb-runtime:2.3.9
javax.xml.ws:jaxws-api jakarta.xml.ws:jakarta.xml.ws-api:2.3.3
javax.jws:javax.jws-api jakarta.jws:jakarta.jws-api:1.1.1
javax.annotation:javax.annotation-api jakarta.annotation:jakarta.annotation-api:1.3.5
javax.activation:activation jakarta.activation:jakarta.activation-api:1.2.2
javax.activation:javax.activation-api jakarta.activation:jakarta.activation-api:1.2.2

The version element is updated only when it is explicitly declared on the
dependency. Versions managed via <dependencyManagement> (absent at the usage
site) are left untouched.

Tests

JakartaEeApiMigrationStrategyTest (18 test cases) covers:

  • Applicability conditions (--model, --all, default)
  • Migration of each supported legacy artifact (jaxb-api, jaxws-api, javax.annotation-api, activation)
  • Version update when explicit; no version added when managed
  • <dependencyManagement> migration
  • Profile <dependencies> migration
  • No modification for non-matching POMs
  • Migration map completeness and validity

Relates to / partially addresses #14163.

Note: this covers the case where projects explicitly declare the removed Java EE artifacts. Projects relying purely on rt.jar without any POM declaration cannot be detected from the POM alone and are out of scope for this strategy.


Hermes Agent (Claude Sonnet 4.5) on behalf of Guillaume Nodet

  • The code I'm contributing is licensed under the Apache License Version 2.0

…I artifacts (apache#14163)

Introduces JakartaEeApiMigrationStrategy, a new mvnup upgrade strategy that
detects and migrates legacy Java EE API Maven dependencies to their Jakarta EE
equivalents.

Java 11 (JEP 320) removed several Java EE modules from the JDK that were
previously bundled in rt.jar: JAXB (javax.xml.bind), JAX-WS (javax.xml.ws),
javax.annotation, javax.activation, and javax.jws. Projects that declared these
APIs as explicit Maven dependencies (javax.xml.bind:jaxb-api, etc.) will fail to
compile on JDK 11+ until they migrate to the standalone Jakarta EE equivalents.

This strategy:
- Scans <dependencies>, <dependencyManagement>, profile dependencies, and
  plugin-level dependencies for the known legacy Java EE artifact coordinates
- Replaces matched entries with the last Jakarta EE release that preserves the
  javax.* package namespace (source-compatible, no import changes required)
- Updates the version element in-place when explicitly declared; leaves it
  untouched when version is managed via dependencyManagement

Migration table (legacy → Jakarta EE replacement):
  javax.xml.bind:jaxb-api         → jakarta.xml.bind:jakarta.xml.bind-api:2.3.3
  com.sun.xml.bind:jaxb-core      → org.glassfish.jaxb:jaxb-core:2.3.0.1
  com.sun.xml.bind:jaxb-impl      → org.glassfish.jaxb:jaxb-runtime:2.3.9
  javax.xml.ws:jaxws-api          → jakarta.xml.ws:jakarta.xml.ws-api:2.3.3
  javax.jws:javax.jws-api         → jakarta.jws:jakarta.jws-api:1.1.1
  javax.annotation:javax.annotation-api → jakarta.annotation:jakarta.annotation-api:1.3.5
  javax.activation:activation     → jakarta.activation:jakarta.activation-api:1.2.2
  javax.activation:javax.activation-api → jakarta.activation:jakarta.activation-api:1.2.2

Note: this covers the case where projects explicitly declare these artifacts.
Projects relying purely on rt.jar without declaring the dependency will still
need manual intervention (toolchain injection or explicit dep addition).

Fixes apache#14163
@Bukama

Bukama commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

I'm not sure if this is really a task of the mvnup tool.
If we want to make mvnup a kind of OpenRewrite for Maven things we should consider the recipe idea, shouldn't we?

edit: and changing the deps is not enough. The imports in Java code needs to be changed, config files need to be changed as well due the namespace change.

@gnodet
gnodet marked this pull request as ready for review November 28, 2026 16:38
@gnodet gnodet added enhancement New feature or request backport-to-4.0.x labels Nov 28, 2026

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well-structured new strategy that correctly follows the existing mvnup pattern (e.g. NashornCompatibilityStrategy). Two real issues to address before merge.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet-bot

Copy link
Copy Markdown
Contributor

Just to clarify on the package concern: the replacements in this PR target the last Jakarta EE 2.x releases, which deliberately preserve the javax.* package namespace. For example:

  • jakarta.xml.bind:jakarta.xml.bind-api:2.3.3 → still javax.xml.bind.*
  • jakarta.annotation:jakarta.annotation-api:1.3.5 → still javax.annotation.*
  • jakarta.activation:jakarta.activation-api:1.2.2 → still javax.activation.*

No import changes are needed — these are drop-in replacements at the Maven coordinate level only. The jakarta.* package rename happened in Jakarta EE 9+ (e.g. jakarta.xml.bind:3.x), which is a different migration entirely.

I'm open to dropping this PR if the scope is considered too broad for mvnup, but not on the grounds that it would break imports — that reasoning doesn't apply to these specific 2.x target versions.

- Detect property expressions (${...}) in version elements and warn
  instead of silently replacing them with literal versions
- Change post-migration context.warning() to context.detail() since
  the migration is already complete and not actionable
- Add test for property expression version preservation
- Add test for plugin-level dependency migration

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up on my earlier review — all 3 findings have been addressed. ✅

[Medium] Property expression version clobbering — ✅ Fixed. The ${...} detection is correct: groupId and artifactId are still migrated (the coordinate change is unambiguous), while the version element is preserved and a context.warning() is emitted with the target version for the user to update manually. This is the right behaviour.

[Low] context.warning() after completed migration — ✅ Fixed. Post-migration logging now uses context.detail(). The context.warning() call that remains is for the property-expression case (actionable by the user), which is appropriate.

[Low] No plugin-level dependency test — ✅ Fixed. PluginDependencyTests added with a test covering <build><plugins><plugin><dependencies> migration.

One minor observation on the property-expression test: preservesPropertyExpressionVersion verifies the XML output (property preserved, no literal version injected) but does not assert that context.warning() was actually called. The mock context would need a verifyWarningContains(...) check to close that gap — currently the warning behaviour is exercised but not asserted. Low severity, not a blocker.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-4.0.x enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants