【问题标题】:Ignoring report generation for specific classes in cobertura maven plugin忽略cobertura maven插件中特定类的报告生成
【发布时间】:2011-07-10 05:28:54
【问题描述】:

我一直在使用 Cobertura 插件来生成报告和检测(使用肯定的)。 这是我面临的问题:

我无法让插件忽略我项目中特定类的报告生成。

在 pom.xml 的相关摘录下方的 PF,我添加了忽略标记,但这只是忽略了被忽略类的检测。

我希望根本不生成特定项目的报告。

首先,由于我对 Maven 和 Conberture 的了解有限,我想知道这是否可能,如果是,那么我需要在 pom.xml 中进行哪些更改。

pom.xml

<report>
    <!-- other plugins exist but are not important to be listed here I guess -->   
    <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <skipTests>false</skipTests>
            <systemProperties>
                <property>
                <name>net.sourceforge.cobertura.datafile</name>
                <value>target/cobertura/cobertura.ser</value>
                </property>
            </systemProperties>
        </configuration>
    </plugin>
    <!-- The following is the plugin for cobertura, which takes care of integration and report generation-->
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <configuration>
            <check>
                <branchRate>50</branchRate>
                <lineRate>50</lineRate>
                <haltOnFailure>true</haltOnFailure>
                <totalBranchRate>50</totalBranchRate>
                <totalLineRate>50</totalLineRate>
                <packageLineRate>50</packageLineRate>
                <packageBranchRate>50</packageBranchRate>
            </check>
            <instrumentation>
                <ignores>
                  <ignore>deshaw.dportal.alert.*</ignore>
                  <ignore>deshaw.dportal.atc.*</ignore>
                  <ignore>deshaw.dportal.basket.*</ignore>
                  <ignore>deshaw.dportal.fcs.*</ignore>
                  <ignore>deshaw.dportal.event.*</ignore>
                  <ignore>deshaw.dportal.filings.*</ignore>
                  <ignore>deshaw.dportal.glg.*</ignore>
                  <ignore>deshaw.dportal.icp.*</ignore>
                </ignores>
            </instrumentation>
        </configuration>
    </plugin>
</report>

编辑:

这是我的目录结构:

module
|
|-apps
|    |-alert
|    |    |-src
|    |    |-target
|    |    |-pom.xml
|    |-------------------
|    |-company
|    |    |-src
|    |    |-target
|    |    |-pom.xml
|-----------------------
|-jobs
|    |-job1
|    |    |-src
|    |    |-target
|    |    |-pom.xml
|    |-job2
|    |    |-src
|    |    |-target
|    |    |-pom.xml

我在 module/pom.xml 中尝试了以下内容

<instrumentation>
    <excludes>
        <exclude>**/apps/*.*</exclude>
    </excludes>
</instrumentation>

我仍然可以在警报和公司目录中生成报告。

可能排除正则表达式不正确?

【问题讨论】:

    标签: maven-2 code-coverage maven-plugin instrumentation cobertura


    【解决方案1】:

    在将 cobertura-maven-plugin 版本从 2.6 更改为 2.4 后,通过忽略项目中的 *Test 文件,我可以成功生成 cobertura 覆盖率报告(如上述 cmets 中的 Stjin geukens 所述)。强>

    请在下面找到完整的 maven 插件详细信息:

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>cobertura-maven-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <instrumentation>
                            <excludes>
                                <exclude>com/services/impl/*Test.class</exclude>
                                <exclude>com/exceptions/*Test.class</exclude>
                                <exclude>com/services/*Test.class</exclude>
                                <exclude>com/utils/*Test.class</exclude>
                            </excludes>
                        </instrumentation>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>cobertura</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
    

    P.S:我不确定 2.6 版本的插件有什么问题

    【讨论】:

      【解决方案2】:

      我遇到了类似的问题,发现了一个很有帮助的教程:http://www.java-tutorial.ch/software-testing/maven-cobertura

      该解决方案与 rdvdijk 发布的答案非常接近。插件信息应该在构建部分和报告部分中。但是排除信息应该放在 pom 的 build 部分。

      【讨论】:

      • 请详细说明您在外部链接中发布的任何内容。
      • 你的链接现在失效了:(
      【解决方案3】:

      您可以通过将&lt;plugin&gt; 块从&lt;reporting&gt; 块移动到&lt;build&gt; 块中的&lt;build&gt; 块从您的cobertura 报告中exclude 类。

      【讨论】:

        【解决方案4】:

        Cobertura maven 插件不尊重报告生成的排除和忽略。但它在检测时这样做。

        已知错误报告于:http://jira.codehaus.org/browse/MCOBERTURA-52

        【讨论】:

        • 我自己正在研究这个问题。它非常烦人,因为我得到了很多未被忽视的报道。任何已知的解决方法?
        • 到目前为止,我唯一可能的解决方法是,包括子 POM 中的插件,用于您希望生成报告的孩子。除此之外,没有其他可行的方法来完成 AFAIK。
        • 这个错误最近已在 cobertura maven 插件的 2.5.2 版本中得到修复
        【解决方案5】:

        使用排除 i.o.忽略。
        这就是我从 cobertura 中排除特定类的方式:

        <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.4</version>
        <configuration>
            <instrumentation>
                <excludes>
                    <exclude>com/bnpp/ecom/**/*Test.class</exclude>
                    <exclude>com/lrc/web/WicketApplication.class</exclude>
                    <exclude>com/lrc/service/HeartBeatWebServiceMock.class</exclude>
                </excludes>
            </instrumentation>
        </configuration>
        

        问候,
        斯蒂金

        【讨论】:

        • 也试过了。它似乎根本不排除。更新我的帖子以包括我尝试的更改。
        • 您是否尝试指定插件的版本?
        • 不。应该有所作为吗?
        • 试试看,这是我看到的你的配置和我的配置之间的唯一区别,你的正则表达式似乎没问题。
        • 我挖得更深一点,才知道,排除和检测仅适用于检测而不是报告生成。在答案中发布了一个链接。
        猜你喜欢
        • 2014-12-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-02
        • 2012-03-13
        • 2010-11-03
        • 2010-10-10
        • 2013-04-27
        相关资源
        最近更新 更多