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; }