不耐烦的更新:很简单,package.-
用于分包扫描而不是package.*
,按照martoe的回答如下!
我似乎无法onlyAnalyze
为我的多模块项目工作:无论我设置什么包(或模式),maven-findbugs-plugin 都不会像我期望的那样评估子包包名。*。
为了证明我自己或插件有问题(尽管我一直认为是前者!),我设置了一个具有以下结构的小型 Maven 项目:
pom.xml
src/
main/java/acme/App.java
main/java/acme/moo/App.java
main/java/no_detect/App.java
这很简单!
POM 具有以下 findbugs 配置:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.4.0</version>
<executions>
<execution>
<phase>verify</phase>
<goals><goal>findbugs</goal><goal>check</goal></goals>
</execution>
</executions>
<configuration>
<debug>true</debug>
<effort>Max</effort>
<threshold>Low</threshold>
<onlyAnalyze>acme.*</onlyAnalyze>
</configuration>
</plugin>
</plugins>
</build>
每个 App.java 都有以下代码,有两个明显的违规行为:
package acme;
import java.io.Serializable;
public class App implements Serializable
{
private static final class NotSer {
private String meh = "meh";
}
private static final NotSer ns = new NotSer();// Violation: not serializable field
public static void main( String[] args )
{
ns.meh = "hehehe";// Vilation: unused
System.out.println( "Hello World!" );
}
}
请注意,no_detect.App
它的内容与上面相同,但我的期望是它不会被 findbugs 评估,因为我设置了“onlyAnalyze”选项acme.*
,我假设它会评估acme.App
,acme.moo.App
没有别的。
我现在执行 amvn clean install
来清理、构建、测试、运行 findbugs、打包、安装,这会生成以下 findbugs 报告(为简洁起见)并导致构建失败,这是预期的,因为acme.App
and acme.moo.App
:
<BugInstance category='BAD_PRACTICE' type='SE_NO_SERIALVERSIONID' instanceOccurrenceMax='0'>
<ShortMessage>Class is Serializable, but doesn't define serialVersionUID</ShortMessage>
<LongMessage>acme.App is Serializable; consider declaring a serialVersionUID</LongMessage>
<Details>
<p> This field is never read.&nbsp; Consider removing it from the class.</p>
</Details>
<BugPattern category='BAD_PRACTICE' abbrev='SnVI' type='SE_NO_SERIALVERSIONID'><ShortDescription>Class is Serializable, but doesn't define serialVersionUID</ShortDescription><Details>
<BugCode abbrev='UrF'><Description>Unread field</Description></BugCode><BugCode abbrev='SnVI'><Description>Serializable class with no Version ID</Description></BugCode>
总结一下:只有acme.App
被分析,acme.moo.App
不是(坏),也不是no_detect.App
(好)。
我尝试在onlyAnalyze
选项中使用两个通配符,但这会产生成功的构建,但会出现 findbugs 错误(Dangling meta character '*'
等)。
我尝试使用onlyAnalyze
set to acme.*,acme.moo.*
which 分析所有预期的类(acme.App
和acme.moo.App
),这意味着它“有效”但不像我预期的那样;即,我必须为要分析的类显式声明所有父包:在多模块项目中,这可能会变得很大且难以维护!
我是否必须定义我想要分析的每个包,或者我可以声明一个通配符/正则表达式模式来满足我的需求?
我宁愿不使用包含/排除 XML,因为这需要更多的设置和推理,而我目前没有时间......