mojohaus / cobertura-maven-plugin

Cobertura Maven Plugin
https://www.mojohaus.org/cobertura-maven-plugin/
25 stars 20 forks source link

Feature: Ability to generate reports as part of regular build (not site) #39

Open msiemczyk opened 6 years ago

msiemczyk commented 6 years ago

I've have been using Cobertura via maven site goal for very long time and maven-site-plugin is nothing but trouble. Our project are large with many different dependencies, with many jar including different version of libraries like Guava, etc.

The maven-site-plugin seems to load plugins and dependencies into class path differently, which causes all kinds of random build failures while doing static code analysis. The normal build (mvn clean install) will pass, but mvn site will fail.

For this reason I really wanted to be able to wire cobertura into normal build life cycle. Turns out that we can already wire the instrument goal, but not the report generation (cobertura.ser --> cobertura.xml) that can be consumed by the Jenkins plugin. Adding new generate-report goal allowed me to wire Cobertura directly into build (mvn clean install).

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>${coberturaPlugin.version}</version>
    <executions>
        <execution>
            <id>cobertura-clean</id>
            <goals>
                <goal>clean</goal>
            </goals>
        </execution>
        <execution>
            <id>cobertura-instrument-code</id>
            <phase>process-classes</phase>
            <goals>
                <goal>instrument</goal>
            </goals>
        </execution>
        <execution>
            <id>cobertura-generate-report</id>
            <phase>verify</phase>
            <goals>
                <goal>generate-report</goal>
            </goals>
        </execution>
    </executions>
</plugin>

I added this new generate-report a while back and it has been working rather good. There was some projects with our custom OSGI plugins that I had to exclude because I couldn't figure out what is the problem. Also because Cobertura actually modified the target class path in the maven environment I had to also add this 'hack' to maven-bundle-plugin.

image

msiemczyk commented 6 years ago

https://github.com/msiemczyk/cobertura-maven-plugin/commit/23a6fca53f58cb7d873f65cedf5fceab592825fa

Added generate-report goal that can be used as part of normal build.

Using maven-site-plugin to generate cobertura was causing all kinds of weird dependency issues so we need alternative means of generating the cobertura.xml report. The report is generated based on previously generated cobertura.ser file that is created by calling cobertura:instrument first.