Skip to content

Commit

Permalink
AddJaxwsRuntime should not always add jaxws-rt (#363)
Browse files Browse the repository at this point in the history
The Gradle recipe should only add the runtime dependency if the API dependency `jakarta.xml.ws:jakarta.xml.ws-api` is already present. This is already how the Maven recipe operates.
  • Loading branch information
knutwannheden authored Dec 4, 2023
1 parent 8733da7 commit 0e3ff9f
Showing 1 changed file with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,29 @@ public G.CompilationUnit visitCompilationUnit(G.CompilationUnit cu, ExecutionCon
.orElseThrow(() -> new RuntimeException("Gradle build scripts must have a GradleProject marker"));

Set<String> apiConfigurations = getTransitiveDependencyConfiguration(gp, JAKARTA_JAXWS_API_GROUP, JAKARTA_JAXWS_API_ARTIFACT);
Set<String> runtimeConfigurations = getTransitiveDependencyConfiguration(gp, SUN_JAXWS_RUNTIME_GROUP, SUN_JAXWS_RUNTIME_ARTIFACT);

if (runtimeConfigurations.isEmpty()) {
if (gp.getConfiguration("compileOnly") != null) {
g = (G.CompilationUnit) new org.openrewrite.gradle.AddDependencyVisitor(SUN_JAXWS_RUNTIME_GROUP, SUN_JAXWS_RUNTIME_ARTIFACT, "2.3.x", null, "compileOnly", null, null, null, null)
.visitNonNull(g, ctx);
}
if (gp.getConfiguration("testImplementation") != null) {
g = (G.CompilationUnit) new org.openrewrite.gradle.AddDependencyVisitor(SUN_JAXWS_RUNTIME_GROUP, SUN_JAXWS_RUNTIME_ARTIFACT, "2.3.x", null, "testImplementation", null, null, null, null)
.visitNonNull(g, ctx);
}
} else {
for (String apiConfiguration : apiConfigurations) {
GradleDependencyConfiguration apiGdc = gp.getConfiguration(apiConfiguration);
List<GradleDependencyConfiguration> apiTransitives = gp.configurationsExtendingFrom(apiGdc, true);
for (String runtimeConfiguration : runtimeConfigurations) {
GradleDependencyConfiguration runtimeGdc = gp.getConfiguration(runtimeConfiguration);
List<GradleDependencyConfiguration> runtimeTransitives = gp.configurationsExtendingFrom(runtimeGdc, true);
if (apiTransitives.stream().noneMatch(runtimeTransitives::contains)) {
g = (G.CompilationUnit) new org.openrewrite.gradle.AddDependencyVisitor(SUN_JAXWS_RUNTIME_GROUP, SUN_JAXWS_RUNTIME_ARTIFACT, "2.3.x", null, apiConfiguration, null, null, null, null)
.visitNonNull(g, ctx);
if (!apiConfigurations.isEmpty()) {
Set<String> runtimeConfigurations = getTransitiveDependencyConfiguration(gp, SUN_JAXWS_RUNTIME_GROUP, SUN_JAXWS_RUNTIME_ARTIFACT);
if (runtimeConfigurations.isEmpty()) {
if (gp.getConfiguration("compileOnly") != null) {
g = (G.CompilationUnit) new org.openrewrite.gradle.AddDependencyVisitor(SUN_JAXWS_RUNTIME_GROUP, SUN_JAXWS_RUNTIME_ARTIFACT, "2.3.x", null, "compileOnly", null, null, null, null)
.visitNonNull(g, ctx);
}
if (gp.getConfiguration("testImplementation") != null) {
g = (G.CompilationUnit) new org.openrewrite.gradle.AddDependencyVisitor(SUN_JAXWS_RUNTIME_GROUP, SUN_JAXWS_RUNTIME_ARTIFACT, "2.3.x", null, "testImplementation", null, null, null, null)
.visitNonNull(g, ctx);
}
} else {
for (String apiConfiguration : apiConfigurations) {
GradleDependencyConfiguration apiGdc = gp.getConfiguration(apiConfiguration);
List<GradleDependencyConfiguration> apiTransitives = gp.configurationsExtendingFrom(apiGdc, true);
for (String runtimeConfiguration : runtimeConfigurations) {
GradleDependencyConfiguration runtimeGdc = gp.getConfiguration(runtimeConfiguration);
List<GradleDependencyConfiguration> runtimeTransitives = gp.configurationsExtendingFrom(runtimeGdc, true);
if (apiTransitives.stream().noneMatch(runtimeTransitives::contains)) {
g = (G.CompilationUnit) new org.openrewrite.gradle.AddDependencyVisitor(SUN_JAXWS_RUNTIME_GROUP, SUN_JAXWS_RUNTIME_ARTIFACT, "2.3.x", null, apiConfiguration, null, null, null, null)
.visitNonNull(g, ctx);
}
}
}
}
Expand Down Expand Up @@ -199,13 +201,15 @@ public Xml.Document visitDocument(Xml.Document document, ExecutionContext ctx) {

//Find the highest scope of a transitive dependency on the JAX-WS API (if it exists at all)
Scope apiScope = getTransitiveDependencyScope(mavenModel, JAKARTA_JAXWS_API_GROUP, JAKARTA_JAXWS_API_ARTIFACT);
//Find the highest scope of a transitive dependency on the JAX-WS runtime (if it exists at all)
Scope runtimeScope = getTransitiveDependencyScope(mavenModel, SUN_JAXWS_RUNTIME_GROUP, SUN_JAXWS_RUNTIME_ARTIFACT);

if (apiScope != null && (runtimeScope == null || !apiScope.isInClasspathOf(runtimeScope))) {
String resolvedScope = apiScope == Scope.Test ? "test" : "provided";
d = (Xml.Document) new AddDependencyVisitor(SUN_JAXWS_RUNTIME_GROUP, SUN_JAXWS_RUNTIME_ARTIFACT,
"2.3.x", null, resolvedScope, null, null, null, null, null).visit(d, ctx);
if (apiScope != null) {
//Find the highest scope of a transitive dependency on the JAX-WS runtime (if it exists at all)
Scope runtimeScope = getTransitiveDependencyScope(mavenModel, SUN_JAXWS_RUNTIME_GROUP, SUN_JAXWS_RUNTIME_ARTIFACT);

if (runtimeScope == null || !apiScope.isInClasspathOf(runtimeScope)) {
String resolvedScope = apiScope == Scope.Test ? "test" : "provided";
d = (Xml.Document) new AddDependencyVisitor(SUN_JAXWS_RUNTIME_GROUP, SUN_JAXWS_RUNTIME_ARTIFACT,
"2.3.x", null, resolvedScope, null, null, null, null, null).visit(d, ctx);
}
}

return d;
Expand Down

0 comments on commit 0e3ff9f

Please sign in to comment.