rewrite-spring icon indicating copy to clipboard operation
rewrite-spring copied to clipboard

`jakarta.xml.bind-api` is missing when petclinic is upgraded to Boot 3

Open BoykoAlex opened this issue 1 year ago • 2 comments

The unit test with trimmed down petclinic is #485 The issue seems to be coming from maven resolution in rewrite as XML Bind dependency somehow ends up as a compile scope transitive dependency while in reality without xml bind th emaven build fails and m2e in Eclipse gives compiler error on XmlElement as well

BoykoAlex avatar Jan 29 '24 20:01 BoykoAlex

I was here to report this exact same issue and found the same problem with the same conclusion. jakarta.xml.bind:jakarta.xml.bind-api:4.0.1 was not added because it was resolved via runtime dependency transitively and it will make petclinic not to compile unless explicitly added.

Additionally, this was working on previous versions of the plugin: This one correctly adds the dependency:

 ./mvnw -U org.openrewrite.maven:rewrite-maven-plugin:5.10.0:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:5.1.7 -Drewrite.activeRecipes=org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_0

And from this version onwards, it fails:

 ./mvnw -U org.openrewrite.maven:rewrite-maven-plugin:5.10.0:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:5.2.0 -Drewrite.activeRecipes=org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_0

Albertoimpl avatar Feb 20 '24 14:02 Albertoimpl

Perhaps we can do something similar to what we've seen in this PR

  • https://github.com/openrewrite/rewrite-migrate-java/pull/456

The case there was that before we only ever changed dependencies, but didn't explicitly add dependencies. That sounds similar to what might be going on here without having explored in depth just yet.

timtebeek avatar May 09 '24 20:05 timtebeek

@timtebeek I have figured it out finally.

Aa part of the upgrade to the latest 2.7.x (2.7.18) the Java 8 -> Java 11 upgrade is performed. This will attempt to execute recipe org.openrewrite.java.migrate.javax.AddJaxbDependencies which attempts to add jakarta.xml.bind-api to petclinic but would fail to do so because Spring Petclinic at 2.7.18 has jakarta.xml.bind-api as a transitive compile scope dependency coming in via hibernate-core 5.7.x (it has jaxb-runtime as a compile scope dependency).

Now moving to Boot 3.0 hibernate is updated to 6.1 via org.openrewrite.hibernate.MigrateToHibernate61 (actually maven dependencies would be upgraded via spring boot parent upgrade to 3.0 but the hibernate upgrade recipe would still execute). Now the hibernate 6.1 upgrade should be responsible for adding jakarta.xml.bind-api because jaxb-runtime became runtime scope dependency rather than compile scope - this should be accounted for. See https://github.com/openrewrite/rewrite-hibernate/pull/29

Even after adding jakarta.xml.bind-api via hibernate 6.1 upgrade recipe it is still not added because somehow jakarta.xml.bind-api is a dependency on a compile scope in the MavenResolutionResult object. This is due to a bug in Maven dependency resolution per scope as any runtime scope dependency is always on the compile scope. See the fix for it with a simple unit test: https://github.com/openrewrite/rewrite/pull/4273

Once two PRs above merged (rewrite-hibernate and rewrite-maven) the unit test in #485 will start passing and can be merged.

BoykoAlex avatar Jun 20 '24 02:06 BoykoAlex

Fixed

BoykoAlex avatar Jun 21 '24 14:06 BoykoAlex