Feature: Gradle Plugin #157
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Initial gradle plugin support.
This is a rough implementation of the gradle plugin.
I likely won't have any more time to work on this for a while.
All code examples are written with Kotlin DSL
Building the jar
If you aren't using a published version of the plugin, you need to create the jar manually. Otherwise you can skip this
mvn install
./refactor-first-gradle-plugin/gradlew shadowJar
./refactor-first-gradle-plugin/build/libs/refactor-first-gradle-plugin-<version>-all.jar
and place it in your gradle project root.Using the plugin
If you are using a jar:
In your project's
build.gradle.kts
you would add:buildscript { dependencies { classpath(files("refactor-first-gradle-plugin-<version>-all.jar")) } }
If you are using the gradle plugin portal:
In your project's
build.gradle.kts
you would add:Will probably also need to implement it.
Load the plugin
Once you've synced gradle, you should see some new tasks within your root.

Run them like you would any other tasks.
TODO:
Attempt
I attempted to run the gradle plugin on my game engine, and got the following error:
The error
Caused by: java.lang.NoSuchMethodError: 'void org.openrewrite.java.tree.J$VariableDeclarations$NamedVariable.<init>(java.util.UUID, org.openrewrite.java.tree.Space, org.openrewrite.marker.Markers, org.openrewrite.java.tree.VariableDeclarator, java.util.List, org.openrewrite.java.tree.JLeftPadded, org.openrewrite.java.tree.JavaType$Variable)' at org.openrewrite.java.isolated.ReloadableJava21ParserVisitor.visitVariables(ReloadableJava21ParserVisitor.java:1765) at org.openrewrite.java.isolated.ReloadableJava21ParserVisitor.visitVariable(ReloadableJava21ParserVisitor.java:1679) at org.openrewrite.java.isolated.ReloadableJava21ParserVisitor.visitVariable(ReloadableJava21ParserVisitor.java:76) at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1040) at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92) at org.openrewrite.java.isolated.ReloadableJava21ParserVisitor.convert(ReloadableJava21ParserVisitor.java:1839) ... 156 more org.openrewrite.java.JavaParsingException: Failed to convert for the following cursor stack:--- BEGIN PATH --- JCCompilationUnit(sourceFile = /path/to/some/class.java) --- END PATH ---
The error
org.openrewrite.java.JavaParsingException: Failed symbol entering or attribution at org.openrewrite.java.isolated.ReloadableJava21Parser.parseInputsToCompilerAst(ReloadableJava21Parser.java:244) at org.openrewrite.java.isolated.ReloadableJava21Parser.parseInputs(ReloadableJava21Parser.java:173) at org.openrewrite.java.Java21Parser.parseInputs(Java21Parser.java:39) at org.openrewrite.Parser.parse(Parser.java:59) at org.hjug.graphbuilder.JavaGraphBuilder.processWithOpenRewrite(JavaGraphBuilder.java:76) at org.hjug.graphbuilder.JavaGraphBuilder.getClassReferences(JavaGraphBuilder.java:38) at org.hjug.cbc.CycleRanker.generateClassReferencesGraph(CycleRanker.java:30) at org.hjug.cbc.CycleRanker.performCycleAnalysis(CycleRanker.java:40) at org.hjug.refactorfirst.report.SimpleHtmlReport.generateReport(SimpleHtmlReport.java:208) at org.hjug.refactorfirst.report.SimpleHtmlReport.execute(SimpleHtmlReport.java:109) at org.hjug.gradlereport.HtmlReportTask.generate(HtmlReportTask.java:23) //123 internal lines Caused by: java.lang.AssertionError at com.sun.tools.javac.util.Assert.error(Assert.java:155) at com.sun.tools.javac.util.Assert.checkNonNull(Assert.java:62) at com.sun.tools.javac.util.ListBuffer.append(ListBuffer.java:127) at com.sun.tools.javac.comp.Attr$1.visitYield(Attr.java:1637) at com.sun.tools.javac.tree.JCTree$JCYield.accept(JCTree.java:1677) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:58) at com.sun.tools.javac.comp.Attr.lambda$visitSwitchExpression$7(Attr.java:1644) //24 internal lines at org.openrewrite.java.isolated.ReloadableJava21Parser.parseInputsToCompilerAst(ReloadableJava21Parser.java:240) ... 135 more org.openrewrite.internal.RecipeRunException: java.lang.NullPointerException: Cannot invoke "org.openrewrite.java.tree.JRightPadded.getElement()" because "this.containing" is null at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:290) at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:157) at org.openrewrite.java.JavadocVisitor.javaVisitorVisit(JavadocVisitor.java:38) at org.openrewrite.java.JavadocPrinter.visitInlinedValue(JavadocPrinter.java:148) at org.openrewrite.java.JavadocPrinter.visitInlinedValue(JavadocPrinter.java:29) at org.openrewrite.java.tree.Javadoc$InlinedValue.acceptJavadoc(Javadoc.java:282) at org.openrewrite.java.tree.Javadoc.accept(Javadoc.java:39) at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250) //33 internal lines at org.openrewrite.java.isolated.ReloadableJava21Parser.lambda$parseInputs$1(ReloadableJava21Parser.java:192) at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133) //7 internal lines at org.hjug.graphbuilder.JavaGraphBuilder.processWithOpenRewrite(JavaGraphBuilder.java:77) at org.hjug.graphbuilder.JavaGraphBuilder.getClassReferences(JavaGraphBuilder.java:38) at org.hjug.cbc.CycleRanker.generateClassReferencesGraph(CycleRanker.java:30) at org.hjug.cbc.CycleRanker.performCycleAnalysis(CycleRanker.java:40) at org.hjug.refactorfirst.report.SimpleHtmlReport.generateReport(SimpleHtmlReport.java:208) at org.hjug.refactorfirst.report.SimpleHtmlReport.execute(SimpleHtmlReport.java:109) at org.hjug.gradlereport.HtmlReportTask.generate(HtmlReportTask.java:23 //112 internal lines
I than attempted it with https://github.com/Mojang/DataFixerUpper and got the same issues.
I'm not sure if this is gradle related or not.