可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I am having issues with sonar picking up the jacoco analysis report. Jenkins however is able to pick up the report and display the results. My project is a maven build, built by Jenkins. The jacoco report is generated by maven (configured in the pom). Sonar is executed by using the Jenkins plugin.
This is what i see on SonarQube:
This is the report i can see of the project in jenkins.
The maven plugin config:
org.jacocojacoco-maven-plugin0.6.4.201312101107default-prepare-agentprepare-agentdefault-reportprepare-packagereportdefault-checkcheck
Jenkins Sonar Plugin config
回答1:
You were missing a few important sonar properties, Here is a sample from one of my builds:
sonar.jdbc.dialect=mssql sonar.projectKey=projectname sonar.projectName=Project Name sonar.projectVersion=1.0 sonar.sources=src sonar.language=java sonar.binaries=build/classes sonar.tests=junit sonar.dynamicAnalysis=reuseReports sonar.junit.reportsPath=build/test-reports sonar.java.coveragePlugin=jacoco sonar.jacoco.reportPath=build/test-reports/jacoco.exec
The error in Jenkins console output can be pretty useful for getting code coverage to work.
Project coverage is set to 0% since there is no directories with classes.
Indicates that you have not set the Sonar.Binaries property correctly
No information about coverage per test
Indicates you have not set the Sonar.Tests property properly
Coverage information was not collected. Perhaps you forget to include debug information into compiled classes? Indicates that the sonar.binaries property was set correctly, but those files were not compiled in debug mode, and they need to be
回答2:
Based on https://github.com/SonarSource/sonar-examples/blob/master/projects/tycho/pom.xml, the following POM works for me:
jacocoreuseReports${project.basedir}/../target/jacoco.execorg.jacocojacoco-maven-plugin0.7.0.201403182114prepare-agent${sonar.jacoco.reportPath}
- Setting the destination file to the report path ensures that Sonar reads exactly the file JaCoCo generates.
- The report path should be outside the projects' directories to take cross-project coverage into account (e.g. in case of Tycho where the convention is to have separate projects for tests).
- The
reuseReports
setting prevents the deletion of the JaCoCo report file before it is read! (Since 4.3, this is the default and is deprecated.)
Then I just run
mvn clean install mvn sonar:sonar
回答3:
Jenkins does not show coverage results as it is a problem of version compatibilities between jenkins jacoco plugin and maven jacoco plugin. On my side I have fixed it by using a more recent version of maven jacoco plugin
org.jacocojacoco-maven-plugin0.7.9
回答4:
Include the sunfire and jacoco plugins in the pom.xml and Run the maven command as given below.
mvn jacoco:prepare-agent jacoco:report sonar:sonar
2.170.7.2.201409121644
org.apache.maven.pluginsmaven-surefire-plugin${surefire.version}org.jacocojacoco-maven-plugin${jacoco.version}default-prepare-agentprepare-agentdefault-reportprepare-packagereport