diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/AddDependency.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/AddDependency.java index e4e5745b2ef..910fdd80547 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/AddDependency.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/AddDependency.java @@ -210,7 +210,9 @@ public TreeVisitor getVisitor(Scanned acc) { Set tmpConfigurations = new HashSet<>(resolvedConfigurations); for (String tmpConfiguration : tmpConfigurations) { GradleDependencyConfiguration gdc = gp.getConfiguration(tmpConfiguration); - if (gdc == null || gdc.findRequestedDependency(groupId, artifactId) != null) { + + if (gdc == null || gdc.getRequested().stream().filter(d -> d.getGroupId().equals(groupId) + && d.getArtifactId().equals(artifactId)).findFirst().isPresent()) { resolvedConfigurations.remove(tmpConfiguration); } } @@ -220,7 +222,9 @@ public TreeVisitor getVisitor(Scanned acc) { GradleDependencyConfiguration gdc = gp.getConfiguration(tmpConfiguration); for (GradleDependencyConfiguration transitive : gp.configurationsExtendingFrom(gdc, true)) { if (resolvedConfigurations.contains(transitive.getName()) || - (Boolean.TRUE.equals(acceptTransitive) && transitive.findResolvedDependency(groupId, artifactId) != null)) { + (Boolean.TRUE.equals(acceptTransitive) && gdc.getRequested().stream() + .filter(d -> d.getGroupId().equals(groupId) + && d.getArtifactId().equals(artifactId)).findFirst().isPresent())) { resolvedConfigurations.remove(transitive.getName()); } } diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/Assertions.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/Assertions.java index 9a7d928dade..cfcbb41ed10 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/Assertions.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/Assertions.java @@ -110,7 +110,7 @@ public static UncheckedConsumer> withToolingApi(@Nullable Strin for (int i = 0; i < sourceFiles.size(); i++) { SourceFile sourceFile = sourceFiles.get(i); if (sourceFile.getSourcePath().toString().endsWith(".gradle") && !sourceFile.getSourcePath().endsWith("settings.gradle")) { - OpenRewriteModel model = OpenRewriteModelBuilder.forProjectDirectory(projectDir.toFile(), tempDirectory.resolve(sourceFile.getSourcePath()).toFile()); + OpenRewriteModel model = OpenRewriteModelBuilder.forProjectDirectory(projectDir.toFile()); GradleProject gradleProject = GradleProject.fromToolingModel(model.gradleProject()); sourceFiles.set(i, sourceFile.withMarkers(sourceFile.getMarkers().add(gradleProject))); }