I am trying to create .refaster rules using Google Error Prone library for my project.
My project is using Maven & JDK 17 and has the following pom.xml:
<dependencies>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_refaster</artifactId>
<version>2.23.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>17</release>
<compilerArgs>
<arg>-Xplugin:RefasterRuleCompiler --out ${project.basedir}/../emptystring.refaster</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.23.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
When I'm executing the command mvn clean install
, the following error is thrown:
Compilation failure
plug-in not found: RefasterRuleCompiler
Also, I have added the following configuration in the .mvn/jvm.config to run with JDK 17 like indicated in the official documentation:
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
Note: I started a project with Error Prone Core before also and I have succeeded to run with JDK 17 but when I try to run the project with Error Prone Refaster, it's failing.
Also, I set the JAVA_HOME
to JDK 17 and tried running the project from the terminal, the error still persisted.
How to fix this?
Found the issue. Please read the docs properly.
I followed the Official Docs from Google Error Prone here.
Couple of things need to be fixed.
error_prone_refaster
dependency in yourannotationProcessorPaths
to make the plugin work.This will fix the error: Error: plug-in not found: RefasterRuleCompiler.
Note: This was not mentioned in the docs. I had to do hit and trial method to get to the solution.
Otherwise, you will face
Error: plug-in not found: RefasterRuleCompiler
if you don't adderror_prone_refaster
dependency to theannotationProcessorPaths
:So, it's mandatory to add it.
I saw that you missed to do it. So, fix this please.
Example on how I did:
Scratch Project for demonstration:
Project Structure (Before running
mvn clean install
):StringIsEmpty.java (example code taken from Google Error Prone):
Working pom.xml:
mvn clean install
success logs:Project Structure (after running
mvn clean install
):As you can see the .refaster file was generated :)