Skip to content

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

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

gnodet wants to merge 1 commit 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.

Comment on lines +303 to +305
if (versionElement != null) {
versionElement.textContent(replacement.version());
}

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.

⚠️ Medium: Version property expressions silently clobbered

If the POM declares <version>${jaxb.version}</version>, this code replaces the property expression with a literal version string — silently destroying property-managed version coordination across the reactor. PluginUpgradeStrategy already handles this by detecting ${...} patterns and updating <properties> instead, or skipping with a warning.

This strategy should do the same:

Suggested change
if (versionElement != null) {
versionElement.textContent(replacement.version());
}
Element versionElement = dependency.childElement(VERSION).orElse(null);
if (versionElement != null) {
String currentVersion = versionElement.textContentTrimmed();
if (currentVersion != null && currentVersion.startsWith("${") && currentVersion.endsWith("}")) {
context.warning("Version of " + key + " is controlled by property "
+ currentVersion + " — update the property value manually to "
+ replacement.version());
} else {
versionElement.textContent(replacement.version());
}
}

Comment on lines +309 to +312
context.warning(key + " uses APIs that were removed from the JDK in Java 11 (JEP 320)."
+ " Replaced with " + replacement.groupId() + ":" + replacement.artifactId() + ":"
+ replacement.version()
+ " which provides the same API as a standalone dependency.");

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.

🔸 Low: context.warning() after migration is not actionable

This warning fires after the migration is already complete — the user has nothing to act on. context.detail() on line 307 already logs the migration. Per Maven convention, WARN should only be used when the user can/should do something in response. This is a migration log entry, not a warning.

Suggested change
context.warning(key + " uses APIs that were removed from the JDK in Java 11 (JEP 320)."
+ " Replaced with " + replacement.groupId() + ":" + replacement.artifactId() + ":"
+ replacement.version()
+ " which provides the same API as a standalone dependency.");
context.detail(key + " uses APIs that were removed from the JDK in Java 11 (JEP 320)."
+ " Replaced with " + replacement.groupId() + ":" + replacement.artifactId() + ":"
+ replacement.version()
+ " which provides the same API as a standalone dependency.");

}
}
}
}

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.

🔹 Low: No test for plugin-level dependency migration

The strategy traverses <build><plugins><plugin><dependencies> and profile plugin dependencies (see production code), but no test verifies migration in those code paths. The existing tests only cover <dependencies> and <dependencyManagement>. Consider adding a test with a POM that has a legacy JEE artifact in a plugin's <dependencies>.

@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.

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