M2Eclipse 抱怨我使用 'javac-with-errorprone' 作为编译器的生命周期

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

我的团队最近决定使用 javac-with-errorprone,Eclipse 抱怨无法将其映射到生命周期。我怎样才能在不告诉 Eclipse 忽略它的情况下解决这个问题,就像 "normal" 处理丢失的 m2e 连接器的方法一样?

<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>

它似乎在 maven-compiler-plugin 的默认生命周期映射中查找 compilerId being "javac",所以当您将其更改为“javac-with-errorprone”时它突然不知道是什么去做。

解决方案是做一个生命周期映射,但不是通常的事情(忽略目标),use the same configurator as the mapper did before (org.eclipse.m2e.jdt.javaConfigurator).

不幸的是,这不会给您错误突出显示,因为 Eclipse 仍在使用其特殊的编译器。但是,您可以放心,您不会忽略 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>