最外層POM配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<forkMode>once</forkMode>
<reuseForks>true</reuseForks>
<useSystemClassLoader>false</useSystemClassLoader>
<argLine>@{argLine}</argLine>
<includes>
<include>**/*Test.java</include>
<include>**/*Test*.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<id>my-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>my-report</id>
<phase>test</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
本地統(tǒng)計代碼單元測試覆蓋率
mvn test jacoco:prepare-agent jacoco:report jacoco:report-aggregate
遠端SonarQube執(zhí)行
jenkis服務(wù)器需要配置Jacoco
mvn test jacoco:prepare-agent jacoco:report jacoco:report-aggregate sonar:sonar -Dsonar.projectKey=xxxxx -Dsonar.projectName=xxx
注意事項
Q1 target目錄下未編譯test目錄下的代碼
常見報錯:
Not compiling test sources
Skipping JaCoCo execution due to missing execution data file.文章來源:http://www.zghlxwxcb.cn/news/detail-698933.html
修改插件配置文章來源地址http://www.zghlxwxcb.cn/news/detail-698933.html
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.compiler.plugin}</version>
<configuration>
<!--.....-->
<skip>false</skip><!--注意此處-->
<!--.....-->
</configuration>
</plugin>
到了這里,關(guān)于Springboot 多模塊項目集成Jacoco統(tǒng)計單元測試覆蓋率的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!