Repository: openrewrite/rewrite (Java)

Issue:
Rewrite Recipe to remove build cache configuration for Develocity
## What problem are you trying to solve?
Presently there is a rewrite recipe for Gradle projects that removes the `develocity` or `gradleEnterprise` configuration from `settings.gradle(.kts)` or `build.gradle(.kts) file`. However, users can also have a buildCache method configured inside the settings or build.gradle file.

This new recipe will remove the build cache configuration from the settings or build.gradle file.

## What precondition(s) should be checked before applying this recipe?
The recipe should be only applied on settings or build.gradle file, using the precondition: 
`or(new IsBuildGradle<>(), new IsSettingsGradle<>())`

## Describe the situation before applying the recipe
<!-- Ideally as a self-contained code example, as a start to the recipe unit tests. -->
```groovy
buildCache {
  remote(HttpBuildCache) {
    url = "some-url"
    push = true
    enabled = true
  }
}
```

## Describe the situation after applying the recipe
<!-- Ideally as a self-contained code example, as a start to the recipe unit tests. -->
```groovy
// buildCache configuration removed
```

## Have you considered any alternatives or workarounds?
<!-- Any other ways to solve the problem, or ways to work around the problem. -->
Currently there does not seem to be any alternative recipes. 

## Are you interested in [contributing this recipe to OpenRewrite](https://github.com/openrewrite/.github/blob/main/CONTRIBUTING.md#adding-new-recipes)?
<!-- Indicate if this is something you would like to work on, and how we can best support you in doing so. -->
Yes, would like to contribute the recipe in case of no workarounds.



Discussion: hi @div-bargali ; thanks for the suggestion! From looking at the existing recipe you referenced it should be fairly straightforward to add a parallel recipe to remove buildCache as well.
https://github.com/openrewrite/rewrite/blob/dd2886c193ea20f416171b5b280a49086e969710/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/RemoveDevelocityConfiguration.java#L30-L57
Here's a quick attempt:
- https://github.com/openrewrite/rewrite/pull/5826



Fix (patch):
diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/RemoveExtension.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/RemoveExtension.java
new file mode 100644
index 0000000000..1bfdff470a
--- /dev/null
+++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/RemoveExtension.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2025 the original author or authors.
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle;
+
+import lombok.EqualsAndHashCode;
+import lombok.Value;
+import org.jspecify.annotations.Nullable;
+import org.openrewrite.*;
+import org.openrewrite.java.JavaIsoVisitor;
+import org.openrewrite.java.tree.J;
+
+import static org.openrewrite.Preconditions.or;
+
+@Value
+@EqualsAndHashCode(callSuper = false)
+public class RemoveExtension extends Recipe {
+
+    @Override
+    public String getDisplayName() {
+        return "Remove build extension by name";
+    }
+
+    @Override
+    public String getDescription() {
+        return "Remove a Gradle build extension from `settings.gradle(.kts)` or `build.gradle(.kts)` files.";
+    }
+
+    @Option(displayName = "Method name",
+            description = "The name of the build extension to remove, e.g., `buildCache`.",
+            example = "buildCache")
+    String methodName;
+
+    @Override
+    public TreeVisitor<?, ExecutionContext> getVisitor() {
+        return Preconditions.check(or(new IsBuildGradle<>(), new IsSettingsGradle<>()), new JavaIsoVisitor<ExecutionContext>() {
+                    @Override
+                    public J.@Nullable MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
+                        if (methodName.equals(method.getSimpleName())) {
+                            return null;
+                        }
+                        return super.visitMethodInvocation(method, ctx);
+                    }
+                }
+        );
+    }
+}
diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/RemoveDevelocityConfiguration.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/RemoveDevelocityConfiguration.java
index 356c2dfab4..fea32d7a38 100644
--- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/RemoveDevelocityConfiguration.java
+++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/RemoveDevelocityConfiguration.java
@@ -15,17 +15,11 @@
  */
 package org.openrewrite.gradle.plugins;
 
-import org.jspecify.annotations.Nullable;
-import org.openrewrite.ExecutionContext;
-import org.openrewrite.Preconditions;
 import org.openrewrite.Recipe;
-import org.openrewrite.TreeVisitor;
-import org.openrewrite.gradle.IsBuildGradle;
-import org.openrewrite.gradle.IsSettingsGradle;
-import org.openrewrite.java.JavaIsoVisitor;
-import org.openrewrite.java.tree.J;
+import org.openrewrite.gradle.RemoveExtension;
 
-import static org.openrewrite.Preconditions.or;
+import java.util.Arrays;
+import java.util.List;
 
 public class RemoveDevelocityConfiguration extends Recipe {
     @Override
@@ -39,19 +33,9 @@ public String getDescription() {
     }
 
     @Override
-    public TreeVisitor<?, ExecutionContext> getVisitor() {
-        return Preconditions.check(
-                or(new IsBuildGradle<>(), new IsSettingsGradle<>()),
-                new JavaIsoVisitor<ExecutionContext>() {
-                    @Override
-                    public J.@Nullable MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
-                        if ("develocity".equals(method.getSimpleName()) ||
-                            "gradleEnterprise".equals(method.getSimpleName())) {
-                            return null;
-                        }
-                        return super.visitMethodInvocation(method, ctx);
-                    }
-                }
-        );
+    public List<Recipe> getRecipeList() {
+        return Arrays.asList(
+                new RemoveExtension("develocity"),
+                new RemoveExtension("gradleEnterprise"));
     }
 }