如何将Nullaway的errorprone插件添加到Maven构建中?

时间:2017-11-09 15:17:04

标签: maven errorprone

Nullaway是一个帮助预防NPE的工具,作为errorprone插件实现。他们的文档假定了一个gradle构建配置。

如何让它与Maven一起使用?

2 个答案:

答案 0 :(得分:3)

比较https://github.com/google/error-prone/blob/master/examples/plugin/maven/hello/pom.xml

至少需要3.5版的maven编译器插件。

    <profile>
        <id>errorprone</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.5.1</version>
                    <configuration>
                        <compilerId>javac-with-errorprone</compilerId>
                        <forceJavacCompilerUse>true</forceJavacCompilerUse>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                        <debug>${compile.debug}</debug>
                        <debuglevel>${compile.debuglevel}</debuglevel>
                        <!-- Add custom checks to the annotation processor classpath. -->
                        <annotationProcessorPaths>
                            <path>
                                <groupId>com.uber.nullaway</groupId>
                                <artifactId>nullaway</artifactId>
                                <version>0.1.7</version>
                            </path>
                        </annotationProcessorPaths>
                        <compilerArgs>
                            <!--<compilerArg>-Xep:NullAway:ERROR</compilerArg>-->
                            <compilerArg>-XepOpt:NullAway:AnnotatedPackages=com.example</compilerArg>
                        </compilerArgs>
                    </configuration>
                  <dependencies>
                      <dependency>
                          <groupId>org.codehaus.plexus</groupId>
                          <artifactId>plexus-compiler-javac-errorprone</artifactId>
                          <version>2.8</version>
                      </dependency>
                      <!-- override plexus-compiler-javac-errorprone's dependency on
                           Error Prone with the latest version -->
                        <dependency>
                            <groupId>com.google.errorprone</groupId>
                            <artifactId>error_prone_core</artifactId>
                            <version>2.1.1</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </profile>

答案 1 :(得分:0)

我们在NullAway wiki中有一个例子:https://github.com/uber/NullAway/wiki/Configuration#maven