Skip to content

The Jakarta JAXB migration adds jakarta.xml.bind-api for imports the parser could not resolve - #1264

Merged
jkschneider merged 1 commit into
mainfrom
jakarta/jaxb-api-for-imports
Oct 4, 2026
Merged

jkschneider merged 1 commit into
mainfrom
jakarta/jaxb-api-for-imports

Conversation

@jkschneider

Copy link
Copy Markdown
Member

A Java 8 project gets JAXB from the JDK, so its LST holds unresolved javax.xml.bind types, and JavaxXmlBindMigrationToJakartaXmlBind, whose AddDependency relies on onlyIfUsing: javax.xml.bind..*, moved the imports to jakarta.xml.bind without adding jakarta.xml.bind-api, so the module no longer compiled. #1257 closed the same gap for the Java 11+ migrations with AddJaxbApiForImports, which matches imports by name, but that recipe is fixed to javax.xml.bind and version 2.3.x and the Jakarta migration does not run it. Rather than add a second recipe that does the same thing, this generalizes it: AddJaxbApiForImports becomes AddApiDependencyForImports with the package and the dependency coordinates as options (a jakarta package also matches imports of its javax predecessor), AddJaxbAPIDependencies configures it for javax.xml.bind and 2.3.x as before, and JavaxXmlBindMigrationToJakartaXmlBind now runs it for jakarta.xml.bind and 3.0.x. The one behavior added to #1257's recipe is that a module declaring the API, or a dependency that carries it, in provided scope is left alone. That check reads the declared scope, because Maven's provided resolution scope also lists compile and runtime dependencies, so an API reached only through a runtime jaxb-runtime still gets a compile declaration. AddJaxbApiForImports has not been released yet, so its recipe name goes away without a replacement, and like #1257 this covers Maven builds only.

Found by a team of coding agents reviewing a Moderne run of org.openrewrite.java.migrate.jakarta.JavaxMigrationToJakarta over the 31 Arquillian repositories (run 20261003120559-YQoma). The issue is jaxb-api-missing-java8 in the run's io.moderne.RecipeIssues data table (6 rows), and the fix was discussed and reviewed on the run's message board. A row from the table, as a generalized example:

JAXB annotations supplied by Java 8 are migrated without adding the Jakarta JAXB compile dependency. (arquillian/arquillian-recorder, arquillian-recorder-reporter/arquillian-recorder-reporter-spi/pom.xml, recipe org.openrewrite.java.migrate.jakarta.JavaxMigrationToJakarta)

Before:

// Java 8 POM without JAXB dependency; saved JAXB types are JavaType.Unknown.
import javax.xml.bind.annotation.XmlTransient;
class A { @XmlTransient String value; }

What the recipe produced:

// POM still has no JAXB dependency.
import jakarta.xml.bind.annotation.XmlTransient;
class A { @XmlTransient String value; }

Expected:

// Add jakarta.xml.bind:jakarta.xml.bind-api:3.0.1 in compile scope.
import jakarta.xml.bind.annotation.XmlTransient;
class A { @XmlTransient String value; }

First of a stack of 19 pull requests from the same review; each later one is based on the one before it.

…er could not resolve

Generalize AddJaxbApiForImports into AddApiDependencyForImports (package and coordinates as options),
skip modules that declare the API through a provided dependency, and use it in the Jakarta JAXB migration.
@jkschneider
jkschneider force-pushed the jakarta/jaxb-api-for-imports branch from 98d7c83 to b430e31 Compare October 3, 2026 22:26
@jkschneider
jkschneider added this pull request to stack #1284 October 4, 2026 09:43
@jkschneider
jkschneider merged commit e6998e4 into main Oct 4, 2026
1 check passed
@jkschneider
jkschneider deleted the jakarta/jaxb-api-for-imports branch October 4, 2026 09:44
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.

1 participant