10

我一直在使用Cobertura插件進行報告生成和檢測(具有surefire)。 這裏是我所面臨的問題:忽略爲cobertura maven插件中的特定類生成報告

我無法把這個插件忽略報表生成在我的項目的具體類別。

PF低於pom.xml的相關摘錄,我已經添加了忽略標記,但這只是忽略了忽略類的檢測。

我希望特定項目的報告根本不會生成。首先,由於我對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 

我試着在模塊/ pom.xml中以下

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

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

也許排除正則表達式是不正確的?

回答

4

的Cobertura Maven插件不尊重排斥和忽視的報告generation.It這樣做的儀器雖然。

已知的bug報道:http://jira.codehaus.org/browse/MCOBERTURA-52

+0

我正在調查這個問題。而且它非常惱人,因爲我得到了很多不被忽視的報道。任何已知的解決方法? – 2011-03-25 13:05:59

+1

我到現在爲止唯一可能的解決方法是,包括兒童POM中的插件,用於要生成報告的兒童。除此之外,沒有其他可行的方法可以完成AFAIK。 – Neeraj 2011-03-26 02:25:21

+1

這個bug現在已經在cobertura maven插件的版本2.5.2中最近修復了 – Ben 2012-11-07 23:34:27

1

使用不包括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> 

格爾茨,
斯泰恩

+0

試過too.It似乎並不排除更新我的帖子以包含我嘗試的更改。 – Neeraj 2011-03-07 15:09:16

+0

您是否嘗試指定插件的版本? – 2011-03-07 16:24:05

+0

不。請問有什麼區別? – Neeraj 2011-03-08 05:41:07

4

你可以從你的Cobertura報告exclude類通過在pom.xml<reporting><plugin>塊移動到你<build>塊。

3

我也有類似的問題,發現了一個非常有用的教程:http://www.java-tutorial.ch/software-testing/maven-cobertura

解決的辦法很接近rdvdijk張貼的答案。插件信息應位於構建部分以及報告部分。但排除信息應放置在pom的構建部分。

+0

plz詳細說明了您在外部鏈接中發佈的任何內容。 – 2012-12-28 11:08:53

0

我能成功地生成忽略從項目中*測試文件改變從2.6的Cobertura Maven的插件版本到2.4後(由Stjin geukens在上述評論提到)一個覆蓋面的Cobertura報告。

請在下面找到完整的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> 

PS:我不知道什麼是2.6版本的插件問題

相關問題