Let’s assume a few think before we begin.
- SonarQube is installed somewhere and works.
- The task « Invoke Standalone Sonar Analysis » is available in Jenkins.
- Your project is using Maven so it has a pom.xml.
To begin, we’ll add configuration in our pom.xml.
<properties> <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin> <sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath> <sonar.language>java</sonar.language> </properties>
We’re using JUnit to run tests.
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> </dependencies>