2021年3月31日 | Leave a comment 问题: sonar 需要导入外部的覆盖报告 解决: 搭建好 sonar 创建好项目 拿到服务器 及 token maven 项目中通过 pom.xml 配置 jacoco <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.6</version> <configuration> <includes> <include>**/rest/**</include> <include>**/impl/**</include> </includes> </configuration> <executions> <execution> <id>default-prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>default-report</id> <goals> <goal>report</goal> </goals> </execution> <execution> <id>default-check</id> <goals> <goal>check</goal> </goals> <configuration> <rules> <rule> <element>BUNDLE</element> <limits> <limit> <counter>COMPLEXITY</counter> <value>COVEREDRATIO</value> <minimum>0.60</minimum> </limit> </limits> </rule> </rules> </configuration> </execution> </executions> </plugin> </plugins> 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.6</version> <configuration> <includes> <include>**/rest/**</include> <include>**/impl/**</include> </includes> </configuration> <executions> <execution> <id>default-prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>default-report</id> <goals> <goal>report</goal> </goals> </execution> <execution> <id>default-check</id> <goals> <goal>check</goal> </goals> <configuration> <rules> <rule> <element>BUNDLE</element> <limits> <limit> <counter>COMPLEXITY</counter> <value>COVEREDRATIO</value> <minimum>0.60</minimum> </limit> </limits> </rule> </rules> </configuration> </execution> </executions> </plugin> </plugins> dd mvn clean test -Dmaven.test.failure.ignore=true jacoco:report sonar:sonar -Dsonar.projectKey=com.telsafe:std-provider -Dsonar.host.url=http://10.0.4.56:9000 -Dsonar.login=bceb1e4c75476e5a5148426142173ab63188ee53 1 mvn clean test -Dmaven.test.failure.ignore=true jacoco:report sonar:sonar -Dsonar.projectKey=com.telsafe:std-provider -Dsonar.host.url=http://10.0.4.56:9000 -Dsonar.login=bceb1e4c75476e5a5148426142173ab63188ee53 参考: https://www.jacoco.org/jacoco/trunk/doc/ https://docs.sonarqube.org/latest/analysis/coverage/