Java 使用带有FindBugs Maven插件的自定义检测器
我有一些定制的FindBugs检测器,我想和FindBugs Maven插件一起使用。有一种方法可以通过Java 使用带有FindBugs Maven插件的自定义检测器,java,maven-2,findbugs,Java,Maven 2,Findbugs,我有一些定制的FindBugs检测器,我想和FindBugs Maven插件一起使用。有一种方法可以通过配置参数对插件执行此操作,但它只接受本地文件、URL或资源 我找到的唯一方法是以某种方式将我的JAR复制到本地文件(可能通过依赖插件),然后配置FindBugs插件,如下所示: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plug
配置参数对插件执行此操作,但它只接受本地文件、URL或资源
我找到的唯一方法是以某种方式将我的JAR复制到本地文件(可能通过依赖插件),然后配置FindBugs插件,如下所示:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<pluginList>${project.build.directory}/my-detectors.jar</pluginList>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.lptr.findbugs</groupId>
<artifactId>my-detectors</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
<assembly>
<id>doublepack</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>${project.build.directory}/${project.build.finalName}.jar</source>
<destName>my-detectors.jar</destName>
</file>
</files>
</assembly>
org.codehaus.mojo
findbugs maven插件
2.3.1
${project.build.directory}/my-detectors.jar
但这不是很灵活。有没有办法将Maven的依赖项管理功能与FindBugs的插件一起使用?我想用这样的东西:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<pluginList>${project.build.directory}/my-detectors.jar</pluginList>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.lptr.findbugs</groupId>
<artifactId>my-detectors</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
<assembly>
<id>doublepack</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>${project.build.directory}/${project.build.finalName}.jar</source>
<destName>my-detectors.jar</destName>
</file>
</files>
</assembly>
org.codehaus.mojo
findbugs maven插件
com.lptr.findbugs
我的探测器
1
…但这只是覆盖了
核心
FindBugs探测器。我发现这是可能的,尽管通过相当多的黑客攻击。FindBugs只能处理本地JAR中的插件,因此您必须为其创建一个插件,但是有一种更灵活的方法可以通过依赖插件来实现这一点
参数可以采用本地文件路径、URL或资源(即来自类路径的内容)。无论您给它什么,寻址文件都将复制到target/
,并传递给FindBugs本身。如果创建包含JAR文件的JAR文件,则可以向FindBugs传递JAR文件。您可以在my detectors
项目中通过具有以下描述符的汇编插件实现这一点:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<pluginList>${project.build.directory}/my-detectors.jar</pluginList>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.lptr.findbugs</groupId>
<artifactId>my-detectors</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
<assembly>
<id>doublepack</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>${project.build.directory}/${project.build.finalName}.jar</source>
<destName>my-detectors.jar</destName>
</file>
</files>
</assembly>
另一个解决方法是在本地存储库中提供插件的路径。本地存储库路径中有一个属性,因此它仍然是可移植的
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<pluginList>${settings.localRepository}/path/to/plugin/1.0-SNAPSHOT/artifact-1.0-SNAPSHOT.jar</pluginList>
</configuration>
</plugin>
org.codehaus.mojo
正是为了这个用例。因为一个新的git: