Skip to content

Commit 56b280c

Browse files
authored
Retain javax.xml.bind:jaxb-api when jackson-module-jaxb-annotations is present (#987)
* Retain javax.xml.bind:jaxb-api when jackson-module-jaxb-annotations is 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 * Update recipes.csv with RetainJaxbApiForJackson * Replace imperative recipe with declarative YAML, use actual() in tests 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 * Update recipes.csv for new declarative recipes * Consolidate into single declarative recipe using DependencyInsight precondition 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.
1 parent 0c1793f commit 56b280c

File tree

3 files changed

+243
-5
lines changed

3 files changed

+243
-5
lines changed

src/main/resources/META-INF/rewrite/jakarta-ee-9.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,7 @@ recipeList:
829829
newGroupId: jakarta.xml.bind
830830
newArtifactId: jakarta.xml.bind-api
831831
newVersion: 3.0.x
832+
- org.openrewrite.java.migrate.jakarta.RetainJaxbApiForJackson
832833
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
833834
groupId: jakarta.xml.bind
834835
artifactId: jakarta.xml.bind-api
@@ -858,6 +859,30 @@ recipeList:
858859
- org.openrewrite.java.migrate.jakarta.JavaxXmlToJakartaXmlXJCBinding
859860
---
860861
type: specs.openrewrite.org/v1beta/recipe
862+
name: org.openrewrite.java.migrate.jakarta.RetainJaxbApiForJackson
863+
displayName: Retain `javax.xml.bind:jaxb-api` when `jackson-module-jaxb-annotations` is present
864+
description: >-
865+
When migrating from `javax.xml.bind` to `jakarta.xml.bind` 3.0+, the `javax.xml.bind:jaxb-api`
866+
dependency is normally replaced. However, if `jackson-module-jaxb-annotations` is on the classpath
867+
(and still uses the `javax.xml.bind` namespace), this recipe ensures `javax.xml.bind:jaxb-api`
868+
remains available as a runtime dependency to prevent `NoClassDefFoundError`.
869+
tags:
870+
- jaxb
871+
- javax
872+
- jakarta
873+
preconditions:
874+
- org.openrewrite.java.dependencies.DependencyInsight:
875+
groupIdPattern: com.fasterxml.jackson.module
876+
artifactIdPattern: jackson-module-jaxb-annotations
877+
recipeList:
878+
- org.openrewrite.java.dependencies.AddDependency:
879+
groupId: javax.xml.bind
880+
artifactId: jaxb-api
881+
version: 2.3.x
882+
scope: runtime
883+
acceptTransitive: true
884+
---
885+
type: specs.openrewrite.org/v1beta/recipe
861886
name: org.openrewrite.java.migrate.jakarta.JavaxXmlToJakartaXmlXJCBinding
862887
displayName: Migrate XJC Bindings to Jakata XML
863888
description: Java EE has been rebranded to Jakarta EE, migrates the namespace and version in XJC bindings.

0 commit comments

Comments
 (0)