2

Nullaway 是一个帮助防止 NPE 的工具,作为一个容易出错的插件实现。他们的文档采用 gradle 构建配置。

我如何使它与 Maven 一起工作?

4

2 回答 2

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>
于 2017-11-09T15:17:04.190 回答
0

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

于 2017-11-10T18:55:21.253 回答