1.pom中加jacoco依赖
<dependency> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.7.8</version> </dependency>
2.pom的build增加
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>3.7</version> <configuration> <skipEmptyReport>false</skipEmptyReport> </configuration> <executions> <execution> <phase>verify</phase> <goals> <goal>check</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.7.8</version> <executions> <execution> <goals> <goal>prepare-agent</goal> <goal>report</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
3.jenkins中POST STEP 选择Execute SonarQube Scanner,Analysis properties中增加下面配置,配置内容有多余的,不过不影响
sonar.projectKey=testjunit
sonar.projectName=testjunit
sonar.projectVersion=1.0
sonar.language=java
sonar.scm.disabled=true
sonar.projectBaseDir=$WORKSPACE
# src
sonar.sources=.
sonar.java.source=.
# binDir
sonar.binaries=.
sonar.java.binaries=
sonar.modules=
sonar.sources=src/main/java
sonar.sourceEncoding=UTF-8
sonar.tests=src/test/java
sonar.java.binaries=target
sonar.core.codeCoveragePlugin=jacoco
sonar.jacoco.reportPaths=target/jacoco.exec
4.构建后操作选择Record JaCoCo coverage report,