From e1469b6ebca871b76f35a9a3af6ff2d196bdb229 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Thu, 23 Jan 2025 22:57:43 +0100 Subject: [PATCH] Only continue for matching configuration --- .../openrewrite/gradle/ChangeDependencyConfiguration.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyConfiguration.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyConfiguration.java index 371acda3914..f7e1674bd3d 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyConfiguration.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyConfiguration.java @@ -70,7 +70,7 @@ public String getInstanceNameSuffix() { @Override public String getDescription() { return "A common example is the need to change `compile` to `api`/`implementation` as " + - "[part of the move](https://docs.gradle.org/current/userguide/upgrading_version_6.html) to Gradle 7.x and later."; + "[part of the move](https://docs.gradle.org/current/userguide/upgrading_version_6.html) to Gradle 7.x and later."; } @Override @@ -96,7 +96,11 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu GradleDependency.Matcher gradleDependencyMatcher = new GradleDependency.Matcher() .configuration(configuration); - if (!gradleDependencyMatcher.get(getCursor()).isPresent() && !dependencyDsl.matches(m)) { + boolean matchesConfiguration = gradleDependencyMatcher.get(getCursor()).isPresent(); + if (!matchesConfiguration && configuration != null) { + return m; + } + if (!matchesConfiguration && !dependencyDsl.matches(m)) { return m; }