diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/UpgradeDependencyVersion.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/UpgradeDependencyVersion.java index 737e767abac..91159ede86f 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/UpgradeDependencyVersion.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/UpgradeDependencyVersion.java @@ -435,6 +435,9 @@ private J.MethodInvocation updateDependency(J.MethodInvocation method, Execution } } else if (arg instanceof J.Literal) { J.Literal literal = (J.Literal) arg; + if (literal.getType() != JavaType.Primitive.String) { + return arg; + } String gav = (String) literal.getValue(); if (gav == null) { getCursor().putMessage(UPDATE_VERSION_ERROR_KEY, new IllegalStateException("Unable to update version")); diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/UpgradeDependencyVersionTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/UpgradeDependencyVersionTest.java index a243296bf5c..4bbc006a4f6 100644 --- a/rewrite-gradle/src/test/java/org/openrewrite/gradle/UpgradeDependencyVersionTest.java +++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/UpgradeDependencyVersionTest.java @@ -882,4 +882,29 @@ void unknownConfiguration() { ) ); } + + @Test + @Issue("https://github.com/openrewrite/rewrite/issues/4275") + void noActionForNonStringLiterals() { + rewriteRun( + buildGradle( + """ + plugins { + id 'java' + } + + repositories { + mavenCentral() + } + + dependencies { + implementation(gradleApi()) + jar { + enabled(true) + } + } + """ + ) + ); + } }