M2Eclipse complains about the lifecycle with I use 'javac-with-errorprone' as the compiler

288 views Asked by At

My team has recently decided to use javac-with-errorprone, and Eclipse complains about not being able to map it to the lifecycle. How can I resolve this without telling Eclipse to ignore it as is the "normal" way to deal with missing m2e connectors?

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <compilerId>javac-with-errorprone</compilerId>
        <forceJavacCompilerUse>true</forceJavacCompilerUse>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-compiler-javac-errorprone</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>com.google.errorprone</groupId>
            <artifactId>error_prone_core</artifactId>
            <version>2.0.8</version>
        </dependency>
    </dependencies>
</plugin>
1

There are 1 answers

0
Captain Man On BEST ANSWER

It appears that in the default life cycle mapping for the maven-compiler-plugin it looks for compilerId being "javac", so when you change it to "javac-with-errorprone" it suddenly doesn't know what to do.

The solution is to make a lifecycle mapping, but instead of the usual thing (ignoring the goals), use the same configurator as the mapper did before (org.eclipse.m2e.jdt.javaConfigurator).

Unfortunately this does not give you error highlighting as Eclipse is still using its special compiler. However, you can rest assured knowing you aren't ignoring the compiler plugin in Eclipse.

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-compiler-plugin</artifactId>
                                    <versionRange>[3.3,)</versionRange>
                                    <goals>
                                        <goal>compile</goal>
                                        <goal>testCompile</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <configurator>
                                        <id>org.eclipse.m2e.jdt.javaConfigurator</id>
                                    </configurator>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>