i'm trying generate unit test code coverage data sonar multi-module maven project, , not getting correct results.
the project structure similar following:
- project
- parentpom
- modulea
- moduleb
- module b1
- module b2
- module c
i using jacoco maven plugin generate jacoco.exec files, , sonar maven plugin analyse code (including jacoco.exec files).
these files generated during process-tests phase, follows:
<properties> <jacoco.report.path>${project.build.directory}/jacoco.exec</jacoco.report.path> <sonar.jacoco.reportpath>${jacoco.report.path}</sonar.jacoco.reportpath> </properties> <plugin> <groupid>org.jacoco</groupid> <artifactid>jacoco-maven-plugin</artifactid> <version>0.7.4.201502262128</version> <executions> <execution> <id>default-prepare-agent</id> <phase>process-test-classes</phase> <goals> <goal>prepare-agent</goal> </goals> <configuration> <destfile>${jacoco.report.path}</destfile> </configuration> </execution> </executions> </plugin> when run mvn clean install can see there jacoco.exec file created each module:
$ find . -name '*.exec' ./modulea/target/jacoco.exec ./moduleb/moduleb1/target/jacoco.exec ./moduleb/moduleb2/target/jacoco.exec ./modulec/target/jacoco.exec when run mvn sonar:sonar see jacoco sensor runs modules, seems work first module. subsequent modules show coverage information not collected:
[info] [17:13:58.333] sensor jacocosensor [info] [17:13:58.350] analysing modulea\target\jacoco.exec [info] [17:13:58.374] no information coverage per test. [info] [17:13:58.374] sensor jacocosensor (done) | time=41ms ... [info] [17:14:02.202] sensor jacocosensor [info] [17:14:02.261] analysing moduleb\moduleb1\target\jacoco.exec [warn] [17:14:02.334] coverage information not collected. perhaps forget include debug information compiled classes? [info] [17:14:02.334] sensor jacocosensor (done) | time=132ms ... i'm not sure why there's no coverage information in second , subsequent modules, since maven-compiler-plugin includes debug information default, , safe ran mvn clean install -dmaven.compiler.debug=true got same results.
as consequence of this, when inspect project in sonar server shows code coverage first module: modulea. no code coverage information other modules present.
apparently solution here generate single jacoco.exec file, when jacoco-maven-plugin executes appends result each module file, sonar can work magic correctly.
accordingly, modified parentpom/pom.xml file follows:
<properties> <!-- single jacoco.exec file relative root directory of project --> <jacoco.report.path>${session.executionrootdirectory}/code-coverage/jacoco.exec</jacoco.report.path> <sonar.jacoco.reportpath>${jacoco.report.path}</sonar.jacoco.reportpath> </properties> <plugin> <groupid>org.jacoco</groupid> <artifactid>jacoco-maven-plugin</artifactid> <version>0.7.4.201502262128</version> <executions> <execution> <id>default-prepare-agent</id> <phase>process-test-classes</phase> <goals> <goal>prepare-agent</goal> </goals> <configuration> <destfile>${jacoco.report.path}</destfile> <append>true</append> <!-- appending single jacoco.exec file --> </configuration> </execution> </executions> </plugin> this means after unit tests have run, jacaco agent invoked when run mvn clean install see 1 jacoco.exec file:
$ find . -name '*.exec' ./code-coverage/target/jacoco.exec but when run mvn sonar:sonar jacocosensor not seem invoked , project on sonar server has no code coverage @ all.
what doing wrong here? how sonar analyse code coverage modules in maven project?
do need modify maven-surefire-plugin in way?
i using sonarqube 5.1, jdk 1.8, jacoco-maven-plugin 0.7.4.201502262128
jacoco sensor load coverage classes covered in module.
this means if reason jacoco.exec in module b not contain coverage information .class files of module won't load coverage (even if covered classes in module).
Comments
Post a Comment