0

I've inherited an odd maven multi module project. The standard business classes and unit tests are in a module called 'code' and we've nice simple working sonar metrics for this module. The second module holds various integration style tests which run against a deployed glassfish server, these run as unit test in the integ-test module.

pom.xml // root level,
    code // business code and unit tests :-)
        moduleA
        moduleB
    integ-test // ;-(
        moduleA
        moduleB

I know the simplest option is to move the 'integ-test' classes into the 'code' module and refactor them as real integration tests but for the moment this isn't an option.

I've figured out a way to record the level of code coverage for the 'integ-tests' module by using the jacoco:dump goal to download the jacococ.exec to the integ-test modules.

My maven pom structure now looks like this

 pom.xml // defined jacoco verify -> report goal
     code // business code and unit test
         moduleA
            target/jacoco.exec - unit test coverage
            pom.xml
     pom.xml - defines standard jacoco prepare-agent goal
     integ-test //
         moduleA
            target/jacoco.exec - really integration test coverage
            pom.xml
     pom.xml- defines jacoco dump and merge

My current approach is to merge all the jacococ.exec files in the 'integ-test' module and use the 'destFile' value to save these details the 'code' module as a jacoco-it.exec file. The standard sonar:sonar goal should then pick up this file and use it as the integration test coverage.

 pom.xml
     integ-test
         moduleA
            target/jacoco.exec - really integration test coverage modA
         moduleB
            target/jacoco.exec - really integration test coverage modB
     code
         moduleA
         moduleB
     target/jacoco-it.exec - This should be the merged content of the two files above
     pom.xml

My root level pom.xml defines this jacoco-maven-plugin config

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <configuration>
        <append>true</append>
        <includes>
            <include>com/a/b/c/**</include>
        </includes>
    </configuration>
    <executions>

        <execution>
            <id>jacoco-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>

        <execution>
            <id>jacoco-dump</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>dump</goal>
            </goals>
        </execution>

        <execution>
            <id>jacoco-merge</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>merge</goal>
            </goals>
            <configuration>
                <fileSets>
                    <fileSet implementation="org.apache.maven.shared.model.fileset.FileSet">
                        <directory>${project.basedir}/integ-test</directory>
                        <includes>
                            <include>*.exec</include>
                        </includes>
                    </fileSet>
                </fileSets>
                <destFile>${sonar.jacoco.itReportPath}</destFile>
            </configuration>
        </execution>

        <execution>
            <id>jacoco-site</id>
            <phase>verify</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
    </executions>
</plugin>

<sonar.jacoco.itReportPath>${project.basedir}/../target/jacoco-it.exec</sonar.jacoco.itReportPath>

I've linked the jacoco:merge goal to the maven post-integration-test phase to ensure the merge happens after the tests are run, but the 'jacoco-it.exec' file is always created within the 'integ-test' folder.

Any suggestions?

emeraldjava
  • 10,894
  • 26
  • 97
  • 170
  • If you are looking for merging multi module Maven projects metrics into Sonar then you are doing the right thing, you might need some tweaks but if you are looking for merging/getting combined Sonar metrics across projects/teams/by project type/by a team/by a DEV manager etc, then try Views Portfolio Management plugin within SonarQube. It's a commercial one but treats each analyzed projects as a component and then you can create custom views, measures, filters to create combined reports in Sonar itself. – AKS Jul 13 '15 at 17:39

1 Answers1

0

What about pointing to destFile in target directory of the master pom? Just define

<configuration>
    <append>true</append>
    <destFile>${project.basedir}/../target/jacoco-it.exec</destFile>
    <propertyName>jacoco.integrationtest.arguments</propertyName>
</configuration>

in the sub-projects. All coverage data will be appended in the jacoco-it.exec file. This file is picked up by sonarqube and you will see the coverage as IT coverage. You can use jacoco.exec as file name as well.

Frank
  • 741
  • 1
  • 10
  • 24