【发布时间】:2021-01-23 11:12:38
【问题描述】:
我有两个模块 maven 项目,在本地运行时,我在 index.html 文件中都看不到。
但是我可以看到目标文件夹下的两个模块包(\target\coverage-reports\jacoco)。
下面是我的主要 POM。
<profile>
<id>coverage</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<run.profiles>test</run.profiles>
<skipTests>false</skipTests>
<checkstyle.skip>true</checkstyle.skip>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${argLine}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<destFile>${user.dir}/target/jacoco/${project.artifactId}.exec</destFile>
<excludes>
<exclude>**/*App*</exclude>
<exclude>**/test/**/*</exclude>
<exclude>**/it/**/*</exclude>
<exclude>**/*Config*</exclude>
<exclude>**/configuration/*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>agent-for-ut</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${user.dir}/target/jacoco/${project.artifactId}.exec</dataFile>
<outputDirectory>${user.dir}/target/coverage-reports/jacoco</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
我在单独的 POM 中进行 jacoco 合并
<artifactId>jacoco-merge</artifactId>
<name>jacoco-m
erge</name>
<packaging>pom</packaging>
<profiles>
<profile>
<id>coverage</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<!-- merge separate coverage files into single coverage file -->
<execution>
<id>merge-results</id>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<!-- This where the jenkins jacoco plugin expects the merged result -->
<destFile>${user.dir}/target/jacoco.exec</destFile>
<fileSets>
<fileSet>
<!-- This is where the individual builds put results -->
<directory>${user.dir}/target/jacoco</directory>
<includes>
<include>*.exec</include>
</includes>
</fileSet>
</fileSets>
</configuration>
<phase>test</phase>
</execution>
【问题讨论】:
标签: maven-3 sonarqube-scan maven-surefire-plugin jacoco-maven-plugin