Skip to content

Instantly share code, notes, and snippets.

@aoudiamoncef
Last active April 30, 2024 11:20
Show Gist options
  • Save aoudiamoncef/50935d14709c1bc11cacf5c1ac333112 to your computer and use it in GitHub Desktop.
Save aoudiamoncef/50935d14709c1bc11cacf5c1ac333112 to your computer and use it in GitHub Desktop.
Maven Jacoco(0.8.3) && SonarQube(7.7) integration with unit && integration tests
...
<properties>
...
<sonar.scanner.maven.version>3.6.0.1398</sonar.scanner.maven.version>
<sonar.host.url>http://localhost:9000</sonar.host.url>
<sonar.projectName>lahzouz</sonar.projectName>
<sonar.language>java</sonar.language>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.sources>${project.basedir}/src/main/java/</sonar.sources>
<sonar.exclusions>
${project.basedir}/src/test/**,
${project.basedir}/src/it/**
</sonar.exclusions>
<sonar.tests>
${project.basedir}/src/test/java/,
${project.basedir}/src/it/
</sonar.tests>
<sonar.test.exclusions>${project.basedir}/src/main/**</sonar.test.exclusions>
<sonar.exclusions>
${project.basedir}/src/main/resources/**,
${project.basedir}/src/test/resources/**
</sonar.exclusions>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.coverage.jacoco.xmlReportPaths>${project.build.directory}/site/jacoco/jacoco.xml
</sonar.coverage.jacoco.xmlReportPaths>
<sonar.junit.reportPaths>
${project.build.directory}/surefire-reports,
${project.build.directory}/failsafe-reports
</sonar.junit.reportPaths>
</properties>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- Force alphabetical order to have a reproducible build -->
<runOrder>alphabetical</runOrder>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
<executions>
<execution>
<id>failsafe-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<dataFile>${project.build.directory}/coverage-merged/merged.exec</dataFile>
</configuration>
<executions>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>pre-test</id>
<phase>process-test-classes</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco-ut.exec</destFile>
</configuration>
</execution>
<execution>
<id>pre-itest</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco-it.exec</destFile>
</configuration>
</execution>
<execution>
<id>merge</id>
<phase>post-integration-test</phase>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<includes>
<include>*.exec</include>
</includes>
<excludes>
<exclude>merged.exec</exclude>
</excludes>
</fileSet>
</fileSets>
<destFile>${project.build.directory}/coverage-merged/merged.exec</destFile>
</configuration>
</execution>
</executions>
</plugin>
...
<pluginManagement>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${sonar.scanner.maven.version}</version>
</plugin>
</plugins>
</pluginManagement>
...
//mvn clean verify sonar:sonar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment