Maven cobertura plugin - one report for multimodule project

后端 未结 4 425
不思量自难忘°
不思量自难忘° 2021-01-05 01:40

I\'m using maven cobertura plugin to report code coverage in my multimodule project.

The problem is that I don\'t know how to generate one report for all modules in

相关标签:
4条回答
  • 2021-01-05 01:57

    The Jenkins Cobertura plugin aggregates the report automatically but if you are interested in the coverage file itself for some other reasons you can do by following below procedure:

    1. Download Cobertura from here

    2. Go to your project workspace -> find all the .ser files and rename them

      (i=0; find . | grep cobertura.ser$ | while read line;do echo $line; cp -i $line cobertura$i.ser;i=$(($i+1));done;)
      
    3. use cobertura-merge.sh to generate global .ser file

      ~/cobertura-2.0.3/cobertura-merge.sh --datafile cobertura.ser cobertura*.ser
      
    4. use cobertura-report.sh to generate report on global .ser file

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

    You will have the global coverage.xml generated in the current directory. You can use it for any kind of processing further.

    0 讨论(0)
  • 2021-01-05 01:58

    To my knowledge, this is currently not supported, see MCOBERTURA-65. But the issue has a patch attached, maybe try it. But my suggestion would be to use something like Sonar to aggregate metrics.

    0 讨论(0)
  • 2021-01-05 02:01

    I have been using Hudson as a Continuous Integration tool. The Cobertura plugin allows me to see code coverage of all of the child modules when checking on the parent.

    0 讨论(0)
  • 2021-01-05 02:11

    The plugin has been updated since this question was asked (and last answered) to now enable aggregated reporting, via the aggregate configuration property in the parent POM.

    This produces the aggregated coverage report at target/site/cobertura/index.html which will include all modules.

    (Each module will also have it's own report produced, if that is of any use.)

    Parent 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>
    
    0 讨论(0)
提交回复
热议问题