I’ve read a lot of threads about multi-module projects and code coverage but I think I’m not in this situation and I’m really stuck.
I have an independent maven project containing some tests classes which test classes that are not in that project at all. They are just defined as dependencies in the project pom.
To include coverage of those classes in the jacoco report I’m using the property “jacoco.includes”.
It works perfectly and the jacoco report show me the coverage on those classes.
The report jacoco.xml also contain this coverage.
Now, when I’m importing this jacoco.xml file in sonar (with SonarScanner for Maven, the debug log indicate that my xml file is read correctly), Sonarqube server only show me the coverage on the classes in the test project. I don’t understand why it does not import all the informations contained in the jacoco.xml file ?
Clément.
EDIT :
Sonarqube server version : 7.7
Sonarqube scanner version : 3.6.0.1398
Jacoco maven plugin : 0.8.4
Sorry if i was not clear in my first post. I’ll try to better explain my case.
I have two separate maven projects :
projectA
src/main/java/com/mycompany/classA
pom.xml
projectB
src/main/java/com/mycompany/classB
src/test/java/com/mycompany/classATest
src/test/java/com/mycompany/classBTest
pom.xml <- dependency on projectA
Jacoco maven plugin in projectB is configured with option <jacoco.includes>projectA</jacoco.includes>.
The jacoco report of projectB show coverage on classA and classB correctly.
But, when I’m running sonarscanner on projectB, sonarqube only show me coverage on classB.
What happens when you run the analysis of projectA with the same report? I am not familiar with “jacoco.includes” option, can you share relevant part of your pom.xml?
Ok, the build configuration of project B was more tricky than I though before. The property “jacoco.includes” is not what I understood.
I’ll try to explain how it works.
Take the projectA et projectB as described in my previous post.
projectA generate a jar with compiled classes and a jar with sources
projectB :
have a dependency on jar with classes and jar with sources
jar with classes is unpacked in target/classes directory
jar with sources is unpacked in target/generated-sources/jacoco
the jacoco.includes (renamed “my.includes” in the sample) property is used by the two previous step to defined which dependencies will be unpacked…
the path target/generated-sources/jacoco is added to the source paths to be available during jacoco analysis
So, for Jacoco, it’s just like sources and classes of projectA is part of projectB…
Don’t know how sonar could handle that.
@saberduck : to answer your question, if I run scanner over projectA with report of projectB, the coverage is correctly reported over classes of projectA. So informations of coverage on thoses classes is really available in the report.
indeed, this will not show the coverage, because we exclude coverage for generated sources. There was recently a request to change this behavior, however I find this rather unusual, to measure coverage on generated code, if you think this is relevant, you can add vote here
thanks for the tip. The solution suggested in the link is enough for me, I will just add manually the path with the sources to analyze with the sonar.sources property. It will do the trick