0

i have a java project called Customer, under this i have another 8 modules, among these 5 modules have junit test classes and have separate ant build files for each modules. I have created(generated unit test reports) jacoco.exec for each project, now, i like to combine these 5 modules' unit test reports into one report and display (or) display unit test reports for each module wise in sona coverage section. Can you please provide any suggestion for this.

Thanks, Joseph

G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76

3 Answers3

0

What you want to do is read each module's test report. You can do that with multi-module project configuration. It will probably be most straight-forward if you handle it all from your main build.xml. I've not tested this from Ant, but something like this should work

<property name="sonar.projectKey" ...
<!-- all normal properties here -->
<property name="sonar.modules" value="module1,module2..." />
<property name="module1.sonar.jacoco.reportPath" value="...

Note that if the Jacoco reports are all in a standard location, you may not even need to specify them because child modules inherit their parents' properties. The docs for multi-module project configuration aren't written with Ant syntax in mind, but you should be able to work through that as long as you keep this in mind from the SonarQube Scanner for Ant docs:

The SonarQube Scanner for Ant is an Ant Task that is wrapper of SonarQube Scanner, which works by invoking SonarQube Scanner and passing to it all properties named following a sonar.* convention. This has the downside of not being very Ant-y, but the upside of providing instant availability of any new analysis parameter introduced by a new version of a plugin or of SonarQube itself.

G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
  • Thanks a lot Ann, i will try the approach, what you mentioned above "module1.sonar.jacco.reportPath" and so... – Joseph Rayappan Apr 14 '16 at 01:24
  • Now, i am getting this error, while i run my project with sonar-runner in jenkins, ERROR: Caused by: Unable to load component class org.sonar.batch.repository.ProjectRepositories ERROR: Caused by: Error 500 on http://localhost:9000/batch/project.protobuf?key=aimia-java-sonar-runner – Joseph Rayappan Apr 14 '16 at 13:03
  • You might do best taking that to the Google Group: https://groups.google.com/forum/#!forum/sonarqube – G. Ann - SonarSource Team Apr 14 '16 at 13:20
  • Sure, thanks Ann.. And my earlier issue got resolved as you suggested to have module name for each subproject... – Joseph Rayappan Apr 14 '16 at 19:41
0

Thanks a lot. again to Ann.. It works to me, my issues resolved(coverage and multiple languages for each module) after added separate module for each sub project in sonar-project.properties as mentioned below.. getting 'coverage' results for modules in Sonarqube..

# Modules
sonar.modules=common,help,mobile,partners

common.sonar.projectBaseDir=C:/dev/workspaces/hg/customer
common.sonar.sources=common/src/main/java,common/web
common.sonar.tests=common/src/test/java
common.sonar.binaries=common/bin
common.sonar.junit.reportsPath=common/test/reports/junitreport   
common.sonar.surefire.reportsPath=common/test/reports/junitreport
common.sonar.jacoco.reportPath=common/coverage/common.exec

help.sonar.projectBaseDir=C:/dev/workspaces/hg/customer
help.sonar.sources=help/src/main/java,help/web
help.sonar.tests=help/src/test/java
help.sonar.binaries=help/bin
help.sonar.junit.reportsPath=help/test/reports/junitreport   
help.sonar.surefire.reportsPath=help/test/reports/junitreport
help.sonar.jacoco.reportPath=help/coverage/help.exec
  • If you specify the properties at the top level you won't have to override them for each module: https://github.com/SonarSource/sonar-examples/blob/master/projects/multi-module/sonar-runner/java-sonar-runner-modules-different-structures/sonar-project.properties – jondro Mar 27 '17 at 08:52
0

This worked for me:

sonar.modules=common,help
sonar.sources=./src/main/java
sonar.binaries=./target/classes
sonar.tests=./src/test/java
sonar.junit.reportsPath=./target/surefire-reports

The path should be relative because sonar automatically navigates to the basedir/module_name/target/surefire-reports

Dhivya
  • 1
  • 1