Retain javax.xml.bind:jaxb-api when jackson-module-jaxb-annotations is present#987
Merged
Retain javax.xml.bind:jaxb-api when jackson-module-jaxb-annotations is present#987
Conversation
…s present When migrating from javax.xml.bind to jakarta.xml.bind 3.0+, the ChangeDependency recipe replaces javax.xml.bind:jaxb-api entirely. However, jackson-module-jaxb-annotations still depends on the javax.xml.bind namespace at runtime through its transitive dependency on jakarta.xml.bind:jakarta.xml.bind-api:2.3.x (the bridge version). When version resolution upgrades to 3.0.x+, the javax.xml.bind classes disappear, causing NoClassDefFoundError. This adds a RetainJaxbApiForJackson recipe that re-adds javax.xml.bind:jaxb-api as a runtime dependency when jackson-module-jaxb-annotations is detected on the classpath, for both Gradle and Maven projects. Fixes #504
timtebeek
reviewed
Feb 17, 2026
...est/java/org/openrewrite/java/migrate/jakarta/JavaxXmlBindMigrationToJakartaXmlBindTest.java
Outdated
Show resolved
Hide resolved
timtebeek
reviewed
Feb 17, 2026
Address PR feedback: - Replace imperative RetainJaxbApiForJackson.java with declarative YAML recipes using FindDependency preconditions (split into Gradle and Maven variants since ModuleHasDependency is a ScanningRecipe which doesn't work as a declarative precondition) - Use assertThat().actual() instead of return in test assertions
…econdition Replace the Gradle/Maven split with a single declarative recipe that uses DependencyInsight as a cross-platform precondition instead of build-system specific FindDependency recipes.
timtebeek
approved these changes
Feb 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RetainJaxbApiForJacksonrecipe that re-addsjavax.xml.bind:jaxb-apias a runtime dependency whenjackson-module-jaxb-annotationsis on the classpathJavaxXmlBindMigrationToJakartaXmlBindinjakarta-ee-9.yml, after theChangeDependencystepProblem
When running the Jakarta EE 9 migration (
JavaxXmlBindMigrationToJakartaXmlBind),ChangeDependencyreplacesjavax.xml.bind:jaxb-apiwithjakarta.xml.bind:jakarta.xml.bind-api:3.0.x. However,jackson-module-jaxb-annotationstransitively depends onjakarta.xml.bind:jakarta.xml.bind-api:2.3.x(the bridge version that still provides thejavax.xml.bindnamespace). Version resolution picks the highest version (3.0.x), which no longer providesjavax.xml.bindclasses, causingNoClassDefFoundErrorat runtime.Solution
A new imperative recipe
RetainJaxbApiForJacksonchecks ifjackson-module-jaxb-annotationsis on the resolved classpath (for both Gradle and Maven). If found, it addsjavax.xml.bind:jaxb-api:2.3.xas aruntimeOnly/runtimedependency so the javax namespace classes remain available.Test plan
New tests reproduce the bug on unmodified
main(both Gradle and Maven assertions fail without the fix)New tests pass with the fix applied
Negative test confirms
jaxb-apiis NOT retained when Jackson is absentExisting
AddJaxbDependenciesWithRuntimeTest,AddJaxbDependenciesWithoutRuntimeTest, andJavaxToJakartaTestall pass (no regressions)Fixes AddJaxbDependencies removes
javax.xml.bind:jaxb-apiwhen it is required by another dependency #504