rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Groovy Parser Error breaks custom gradle task

Open edward3h opened this issue 3 years ago • 3 comments

Here's a minimal project that reproduces the issue: https://github.com/edward3h/gradle_rewrite_bug

I have a custom task defined in build.gradle and ran the org.openrewrite.java.cleanup.Cleanup recipe. It changes the custom task in a way that breaks Gradle build.

diff --git a/build.gradle b/build.gradle
index 05f1221..e4ef94f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -27,7 +27,7 @@ task install {
     dependsOn installDist
     doLast {
         ant.mkdir(dir: "${rootDir}/bin")
-        ant.symlink(resource: "${(installDist.outputs.files as List).first()}/bin/${application.applicationName}", link: "${rootDir}/bin/${application.applicationName}")
+        ant.symlink(resource: "${(installDist.outputs.files as List)installDist.outputs}bin${application////}bin${application.filesfirst}/bin/",link, link: "${rootDir}/bin/${application.applicationName}")
     }
 }
 
@@ -39,4 +39,4 @@ clean.dependsOn cleanBin
 
 rewrite {
     activeRecipe("org.openrewrite.java.cleanup.Cleanup")
-}
\ No newline at end of file
+}

edward3h avatar Sep 15 '22 15:09 edward3h

Workaround: exclude build.gradle from rewrite

diff --git a/build.gradle b/build.gradle
index 05f1221..f488ca0 100644
--- a/build.gradle
+++ b/build.gradle
@@ -39,4 +39,5 @@ clean.dependsOn cleanBin
 
 rewrite {
     activeRecipe("org.openrewrite.java.cleanup.Cleanup")
-}
\ No newline at end of file
+    exclusion('**/build.gradle')
+}

edward3h avatar Sep 15 '22 15:09 edward3h

@edward3h, thanks so much for the sample project!

pway99 avatar Sep 15 '22 16:09 pway99

this looks like a groovy parsing error, its showing up in the EmptyNewlineAtEndOfFile recipe because it changes the file. check out the TypeCast expression below: image

pway99 avatar Sep 15 '22 21:09 pway99