在 Maven 中使用 findbugs-slf4j 插件
Using findbugs-slf4j plugin with maven
我正在尝试 findbugs-slf4j
插件与 Maven。正如他们在 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:findbugs
然后 mvn 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)]
有人可以告诉我我做错了什么吗?
错误的插件和任务
this page is outdated and differs from the 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.
你有一个占位符和一个参数,因此根据[=17]没有违反SLF4J_PLACE_HOLDER_MISMATCH
=],这就是为什么您没有看到任何错误报告的原因。 请记住,Throwable 实例并非如此,因为它们不需要占位符。
尝试使用文档中的测试用例来查看插件是否在您的设置中正常工作。
将您的 <plugin>...</plugin>
从 <reporting><plugins>
移动到 <build><plugins>
。 <reporting>
内的插件只会在你踢 site
球时触发。
我正在尝试 findbugs-slf4j
插件与 Maven。正如他们在 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:findbugs
然后 mvn 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)]
有人可以告诉我我做错了什么吗?
错误的插件和任务
this page is outdated and differs from the 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.
你有一个占位符和一个参数,因此根据[=17]没有违反SLF4J_PLACE_HOLDER_MISMATCH
=],这就是为什么您没有看到任何错误报告的原因。 请记住,Throwable 实例并非如此,因为它们不需要占位符。
尝试使用文档中的测试用例来查看插件是否在您的设置中正常工作。
将您的 <plugin>...</plugin>
从 <reporting><plugins>
移动到 <build><plugins>
。 <reporting>
内的插件只会在你踢 site
球时触发。