Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jaxb-runtime added only if not present already #499

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,15 @@ public G.CompilationUnit visitCompilationUnit(G.CompilationUnit cu, ExecutionCon
return g;
}

String groupId = GLASSFISH_JAXB_RUNTIME_GROUP;
String artifactId = GLASSFISH_JAXB_RUNTIME_ARTIFACT;
String version = "2.3.x";
if ("sun".equals(runtime)) {
g = (G.CompilationUnit) new org.openrewrite.gradle.AddDependencyVisitor(SUN_JAXB_RUNTIME_GROUP, SUN_JAXB_RUNTIME_ARTIFACT, "2.3.x", null, "runtimeOnly", null, null, null, null)
.visitNonNull(g, ctx);
} else {
g = (G.CompilationUnit) new org.openrewrite.gradle.AddDependencyVisitor(GLASSFISH_JAXB_RUNTIME_GROUP, GLASSFISH_JAXB_RUNTIME_ARTIFACT, "2.3.x", null, "runtimeOnly", null, null, null, null)
groupId = SUN_JAXB_RUNTIME_GROUP;
artifactId = SUN_JAXB_RUNTIME_ARTIFACT;
}
if (rc.findResolvedDependency(groupId, artifactId) == null) {
g = (G.CompilationUnit) new org.openrewrite.gradle.AddDependencyVisitor(groupId, artifactId, version, null, "runtimeOnly", null, null, null, null)
.visitNonNull(g, ctx);
}
return g;
Expand Down Expand Up @@ -190,11 +194,18 @@ private Xml.Document maybeAddRuntimeDependency(Xml.Document d, ExecutionContext
return d;
}

String groupId = GLASSFISH_JAXB_RUNTIME_GROUP;
String artifactId = GLASSFISH_JAXB_RUNTIME_ARTIFACT;
String version = "2.3.x";
if ("sun".equals(runtime)) {
d = (Xml.Document) new org.openrewrite.maven.AddDependencyVisitor(SUN_JAXB_RUNTIME_GROUP, SUN_JAXB_RUNTIME_ARTIFACT, "2.3.x", null, Scope.Runtime.name().toLowerCase(), null, null, null, null, null)
groupId = SUN_JAXB_RUNTIME_GROUP;
artifactId = SUN_JAXB_RUNTIME_ARTIFACT;
}
if (getResolutionResult().findDependencies(groupId, artifactId, Scope.Runtime).isEmpty()) {
d = (Xml.Document) new org.openrewrite.maven.AddDependencyVisitor(groupId, artifactId, version, null, Scope.Runtime.name().toLowerCase(), null, null, null, null, null)
.visitNonNull(d, ctx);
} else {
d = (Xml.Document) new org.openrewrite.maven.AddDependencyVisitor(GLASSFISH_JAXB_RUNTIME_GROUP, GLASSFISH_JAXB_RUNTIME_ARTIFACT, "2.3.x", null, Scope.Runtime.name().toLowerCase(), null, null, null, null, null)
d = (Xml.Document) new org.openrewrite.maven.UpgradeDependencyVersion(groupId, artifactId, version, null, false, null).getVisitor()
.visitNonNull(d, ctx);
}
return d;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void addJaxbRuntimeOnce() {
dependencies {
implementation "jakarta.xml.bind:jakarta.xml.bind-api:%s"
runtimeOnly "org.glassfish.jaxb:jaxb-runtime:%s"
}
""".formatted(bindApiVersion, runtimeVersion);
Expand Down Expand Up @@ -480,4 +480,56 @@ void dontAddWhenJacksonPresent() {
)
);
}

@Test
void dontAddWhenTransientPresent() {
rewriteRun(
spec -> spec.beforeRecipe(withToolingApi()),
java(XML_ELEMENT_STUB),
java(CLASS_USING_XML_BIND),
buildGradle(
//language=gradle
"""
plugins {
id "java-library"
}
repositories {
mavenCentral()
}
dependencies {
implementation("jakarta.xml.bind:jakarta.xml.bind-api:2.3.3")
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.7.3'
}
"""
),
pomXml(
//language=xml
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic</artifactId>
<version>2.7.3</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
</parent>
<name>petclinic</name>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
</project>
"""
)
);
}
}