2010-09-22 83 views
7

我正在使用maven cobertura插件在我的多模塊項目中報告代碼覆蓋率。Maven cobertura插件 - 多模塊項目的一個報告

問題是我不知道如何爲項目中的所有模塊生成一個報告。

到目前爲止,我已經爲每個模塊生成了單獨的報告,但是對於整個項目有一個報告會很好。

我父POM配置:

<plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>cobertura-maven-plugin</artifactId> 
     <version>2.4</version> 
     <inherited>true</inherited> 
     <executions> 
      <execution> 
       <phase>test-compile</phase> 
       <goals> 
        <goal>clean</goal> 
        <goal>cobertura</goal> 
       </goals> 
      </execution> 
     </executions> 
    </plugin> 

回答

2

據我所知,這是目前不支持,請參閱MCOBERTURA-65。但是這個問題有一個補丁,可能試試吧。但我的建議是使用像Sonar這樣的東西來聚合指標。

+0

它現在支持。看到我的答案。 – vegemite4me 2013-09-23 14:00:58

0

我一直在使用Hudson作爲持續集成工具。 Cobertura插件允許我在檢查父項時查看所有子模塊的代碼覆蓋率。

0

詹金斯的Cobertura插件自動彙總的報告,但如果你有興趣在覆蓋文件本身你可以按照以下步驟做一些其他的原因:

  1. 下載的Cobertura從here

  2. 轉到您的項目工作區 - >查找所有.ser文件並重命名它們

    (i=0; find . | grep cobertura.ser$ | while read line;do echo $line; cp -i $line cobertura$i.ser;i=$(($i+1));done;) 
    
  3. 使用cobertura-merge.sh產生全球.ser文件

    ~/cobertura-2.0.3/cobertura-merge.sh --datafile cobertura.ser cobertura*.ser 
    
  4. 使用cobertura-report.sh對全球.ser文件

    ~/cobertura-2.0.3/cobertura-report.sh ./cobertura.ser --destination ./ --format xml 
    

生成報表時將在當前目錄下生成全球coverage.xml。 您可以進一步使用它進行任何類型的處理。

+0

這也可以通過命令行使用maven: 'mvn cobertura:cobertura -Dcobertura.aggregate = true -Dcobertura.report.format = xml' 您可以根據需要更改報告格式。 按照的Cobertura Maven插件的GitHub庫,此功能可用 [自V2.5(https://github.com/mojohaus/cobertura-maven-plugin/blob/master/src/main/java/org /codehaus/mojo/cobertura/CoberturaReportMojo.java#L126)(commit [64a8823](https://github.com/mojohaus/cobertura-maven-plugin/commit/64a8823866b4c8be74a44383162088d616c65185#diff-e4171be1b77f9a9b331e21a0661c1433R126))。 – clapsus 2016-07-27 13:00:34

16

由於此問題被問及(最後回答),現在通過父POM中的aggregate配置屬性啓用聚合報告,該插件已更新。

這產生了聚合覆蓋率報告target/site/cobertura/index.html,其中將包括所有模塊。

(每個模塊也將有它自己的報告製作,如果沒有任何用處的。)

父pom.xml的

<modules> 
    <module>moduleA</module> 
    <module>moduleB</module> 
    <module>moduleC</module> 
<modules> 
<build> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>cobertura-maven-plugin</artifactId> 
       <version>2.6</version> 
       <configuration> 
        <check/> 
        <formats> 
         <format>html</format> 
         <format>xml</format> 
        </formats> 
        <aggregate>true</aggregate> 
       </configuration> 
      </plugin> 
      ... 
    </pluginManagement> 
    <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>cobertura-maven-plugin</artifactId> 
     </plugin> 
    </plugins> 
... 
</build> 
+3

這應該是被接受的答案! – MKorsch 2016-05-19 13:02:50

+0

我應該在父模塊上運行'mvn cobertura:cobertura -Dcobertura.report.format = xml'命令,它會在父模塊中生成彙總報告嗎? – Varun 2016-06-23 10:49:52

+0

我在父包上運行了'mvn cobertura:cobertura -Dcobertura.report.format = xml'命令,它聚合了子模塊的報告,但是它沒有顯示該父模塊的子maven模塊中的類的覆蓋,如果該類是由來自此父模塊的不同子項目模塊的類覆蓋。 – Varun 2016-06-23 11:08:47