diff --git a/build.gradle.kts b/build.gradle.kts
index 968201e6ee..d02f433cd3 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -54,6 +54,7 @@ dependencies {
testRuntimeOnly("com.fasterxml.jackson.datatype:jackson-datatype-jsr353")
testRuntimeOnly("com.fasterxml.jackson.core:jackson-core")
testRuntimeOnly("com.fasterxml.jackson.core:jackson-databind")
+ testRuntimeOnly("org.apache.johnzon:johnzon-core:1.2.18")
testRuntimeOnly("org.codehaus.groovy:groovy:latest.release")
testRuntimeOnly("jakarta.annotation:jakarta.annotation-api:2.1.1")
testRuntimeOnly("org.springframework:spring-core:6.1.13")
diff --git a/src/main/resources/META-INF/rewrite/jakarta-ee-9.yml b/src/main/resources/META-INF/rewrite/jakarta-ee-9.yml
index eff6ee0e34..d3259f26df 100644
--- a/src/main/resources/META-INF/rewrite/jakarta-ee-9.yml
+++ b/src/main/resources/META-INF/rewrite/jakarta-ee-9.yml
@@ -952,10 +952,12 @@ recipeList:
groupId: org.apache.johnzon
artifactId: "*"
newVersion: latest.release
- - org.openrewrite.maven.ChangeDependencyClassifier:
- groupId: org.apache.johnzon
- artifactId: "*"
- newClassifier: jakarta
+ - org.openrewrite.java.dependencies.AddDependency:
+ groupId: jakarta.json
+ artifactId: jakarta.json-api
+ scope: provided
+ version: 2.1.X
+ onlyIfUsing: org.apache.johnzon..*
---
# Currently this recipe is only updating the artifacts to a version that is compatible with J2EE 9. There still may be
# breaking changes to the Rest Assured API that need to be addressed.
diff --git a/src/test/java/org/openrewrite/java/migrate/jakarta/JohnzonJavaxtoJakartaTest.java b/src/test/java/org/openrewrite/java/migrate/jakarta/JohnzonJavaxtoJakartaTest.java
index 20240531c6..9c95acebc6 100644
--- a/src/test/java/org/openrewrite/java/migrate/jakarta/JohnzonJavaxtoJakartaTest.java
+++ b/src/test/java/org/openrewrite/java/migrate/jakarta/JohnzonJavaxtoJakartaTest.java
@@ -17,6 +17,7 @@
import org.junit.jupiter.api.Test;
import org.openrewrite.config.Environment;
+import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
@@ -24,6 +25,7 @@
import java.util.regex.Pattern;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.openrewrite.java.Assertions.*;
import static org.openrewrite.maven.Assertions.pomXml;
class JohnzonJavaxtoJakartaTest implements RewriteTest {
@@ -34,55 +36,83 @@ public void defaults(RecipeSpec spec) {
Environment.builder()
.scanRuntimeClasspath("org.openrewrite.java.migrate")
.build()
- .activateRecipes("org.openrewrite.java.migrate.jakarta.JohnzonJavaxToJakarta"));
+ .activateRecipes("org.openrewrite.java.migrate.jakarta.JohnzonJavaxToJakarta")
+ ).parser(JavaParser.fromJavaVersion().classpath("johnzon-core"));
}
@Test
void migrateJohnzonDependencies() {
- //language=xml
rewriteRun(
- pomXml(
- """
-
- com.example.ehcache
- johnzon-legacy
- 1.0.0
-
- 1.2.5
-
-
-
- org.apache.johnzon
- johnzon-core
- ${johnzon.version}
-
-
-
- """,
- spec -> spec.after(actual -> {
- assertThat(actual).isNotNull();
- Matcher version = Pattern.compile("([0-9]+\\.[0-9]+\\.[0-9]+)")
- .matcher(actual);
- assertThat(version.find()).isTrue();
- return """
-
- com.example.ehcache
- johnzon-legacy
- 1.0.0
-
- %s
-
-
-
- org.apache.johnzon
- johnzon-core
- ${johnzon.version}
- jakarta
-
-
-
- """.formatted(version.group(1));
- })
+ mavenProject("demo",
+ pomXml(
+ //language=xml
+ """
+
+ com.example.ehcache
+ johnzon-legacy
+ 1.0.0
+
+ 1.2.5
+
+
+
+ org.apache.johnzon
+ johnzon-core
+ ${johnzon.version}
+
+
+
+ """,
+ spec -> spec.after(actual -> {
+ assertThat(actual).isNotNull();
+ Matcher version = Pattern.compile("([0-9]+\\.[0-9]+\\.[0-9]+)")
+ .matcher(actual);
+
+ Matcher jsonApiVersion = Pattern.compile("2.1.\\d+").matcher(actual);
+ assertThat(jsonApiVersion.find()).describedAs("Expected jakarta.json-api 2.1.x version in %s", actual).isTrue();
+
+ assertThat(version.find()).isTrue();
+ return """
+
+ com.example.ehcache
+ johnzon-legacy
+ 1.0.0
+
+ %s
+
+
+
+ org.apache.johnzon
+ johnzon-core
+ ${johnzon.version}
+
+
+ jakarta.json
+ jakarta.json-api
+ %s
+ provided
+
+
+
+ """.formatted(version.group(1), jsonApiVersion.group(0));
+ })
+ ),
+ srcMainJava(
+ java(
+ //language=java
+ """
+ package com.example.demo;
+
+ import org.apache.johnzon.core.Snippet;
+
+ public class A {
+
+ void foo(Snippet snippet, String str) {
+ }
+ }
+ """
+ )
+ )
)
);
}