有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用带有maven的findbugsslf4j插件

我正在用maven尝试findbugs-slf4j插件。正如他们在documentation中提到的,我在我的` pom'中添加了以下内容。xml

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>findbugs-maven-plugin</artifactId>
        <version>3.0.1</version>
        <configuration>
          <plugins>
            <plugin>
              <groupId>jp.skypencil.findbugs.slf4j</groupId>
              <artifactId>bug-pattern</artifactId>
              <version>1.2.4</version>
            </plugin>
          </plugins>
        </configuration>
      </plugin>

为了测试这一点,我在代码中添加了如下日志

logger.error("Could not send inventory data to collector. Exception: {}", e); // where e is an instance of Exception

但是在编译项目,然后执行mvn findbugs:findbugsmvn findbugs:gui时,我没有看到任何与SLF4J_PLACE_HOLDER_MISMATCH相关的错误

编辑 正如其中一个答案中所建议的,我将插件依赖性更改为

<reporting>
        <plugins>
            <plugin>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs-maven-plugin</artifactId>
                <version>3.1.0-RC7</version>
                <configuration>
                    <plugins>
                        <plugin>
                            <groupId>jp.skypencil.findbugs.slf4j</groupId>
                            <artifactId>bug-pattern</artifactId>
                            <version>1.2.4</version>
                        </plugin>
                    </plugins>
                </configuration>
            </plugin>
        </plugins>
    </reporting>

但是在运行mvn spotbugs:spotbugs时,它给了我下面的错误

No plugin found for prefix 'spotbugs' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/Users/dmanna/.m2/repository), central (http://artifactory.srk.local:8080/plugins-release), snapshots (http://artifactory.srk.local:8080/plugins-snapshot)]

有人能告诉我我做错了什么吗


共 (2) 个答案

  1. # 2 楼答案

    错误的插件和任务

    看起来this page上的文档已经过时,并且与README不同,后者显然是正确的。 您应该使用以下工件包含插件:

    <groupId>com.github.spotbugs</groupId>
    <artifactId>spotbugs-maven-plugin</artifactId>
    <version>3.1.0-RC7</version>
    

    与此任务一起使用的正确maven任务是spotbugs:spotbugs,而不是findbugs:findbugs

    旧答案

    让我们看看SLF4J_PLACE_HOLDER_MISMATCH规则检查了什么

    This pattern checks how placeholder is used. Alert if count of placeholder does not match to count of parameter.

    您有一个占位符和一个参数,因此根据documentation没有违反SLF4J_PLACE_HOLDER_MISMATCH,这就是为什么您没有看到任何报告的错误请记住,对于可丢弃的实例,这是不正确的,因为它们不需要占位符

    尝试使用文档中的测试用例,看看插件在您的设置中是否正常工作