2012-02-13 72 views
4

更新不耐烦:很简单,使用package.-的子包扫描代替package.*,作为每下面martoe的回答!Maven的Codehaus的FindBugs的插件“onlyAnalyze”选项工作不正常

我似乎无法得到onlyAnalyze我的多模块项目的工作:不管什么包(或模式)我设置,Maven的FindBugs的-插件作为我从它传递PACKAGENAME预期不计算子包。*。

为了证明自己或者或故障插件(虽然我总是假设是前者!),我安装具有以下结构的小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.Appacme.moo.App而没有任何el SE。

我现在执行mvn clean install清理,构建,测试,运行FindBugs的,包装,安装,产生预计在构建失败以下FindBugs的报告(剪断,为了简洁)和结果,因为acme.Appacme.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> 
    &lt;p&gt; This field is never read.&amp;nbsp; Consider removing it from the class.&lt;/p&gt; 
</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设置为acme.*,acme.moo.*,其分析所有预期的类(acme.Appacme.moo.App),这意味着它“作品”,而不是如我所料;即我必须明确声明我想分析的类的所有父包:这可能会在多模块项目中变得很大且难以维护!

我是否必须定义每个我想要分析的软件包,或者我可以声明一个通配符/正则表达式模式,以实现我想要的功能?

,因为这需要更多的设置和推理,我目前没有时间......

回答

9

举了Findbugs manual我宁可不使用包含/排除XML:“替换*带。 - 也分析所有子包“

+0

在我的挫折和疯狂的搜索我设法不实际RTFM - 尽管公平我从来没有实际上找到自己的文档。谢谢! – 2012-02-15 09:54:23