mvn -Dmaven.test.skip=false -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -U clean verify sonar:sonar -Dsonar.projectKey=code-diff -Dsonar.host.url=https://test-sonarqube.internal.com -Dsonar.token=sqa_37c31**** -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml
下面的pom 内容需要加入到项目的pom中,否则不会上传生成覆盖率数据
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.7.0.1746</version>
</plugin>
需要切到根目录下,再执行脚本
image.png
数据将会上传到sonarqube
image.png
测试用例 如果是junit包 需要改成
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.5</version>
<scope>test</scope>
</dependency>
不然可能会不运行测试用例,实际的测试执行可能是0
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest(classes = CodeDiffApplication.class)
public class CodeDiffApplicationTest {
@Test
void contextLoads() {
}
}
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.3</version>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<skip>false</skip>
<skipTests>false</skipTests>
</configuration>
</plugin>