我已经在我的项目中集成了jacoco-maven-plugin,基于这个出色的指南:http://www.petrikainulainen.net/programming/maven/creating-code-coverage-reports-for-unit-and-integration-tests-with-the-jacoco-maven-plugin/
jacoco插件运行正常。但是,maven-site-plugin不包含网站中的jacoco报告。更具体地说:“项目报告”部分未列出jacoco报告。 jacoco报告本身可在target / site / jacoco-ut和target / site / jacoco-it目录中找到。
这就是我所做的(到目前为止没有成功)。
首先,将jacoco-maven-plugin作为插件包含在我的pom.xml的 build 部分中,如上面引用的指南中所述。我正在使用jacoco版本0.6.4.201312101107。
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.plugin.version}</version>
<executions>
<!-- scissors... -->
<!-- report goal is bound to the pre-site phase -->
</executions>
</plugin>
其次,在我的pom.xml的报告部分包含了jacoco-maven-plugin:没有成功。
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.plugin.version}</version>
</plugin>
第三,尝试在报告部分的jacoco-maven-plugin中添加 reportsets 部分:没有成功。
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.plugin.version}</version>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
有人可以帮我制作maven-site-plugin参考网站“项目报告”部分中jacoco生成的报道报告吗?
答案 0 :(得分:4)
我发现jacoco非常棘手,下面的配置对我有用,我把它从博客中的点点滴滴放在一起 在属性
<jacoco.reportPath>${main.basedir}/target/jacoco.exec</jacoco.reportPath>
<jacoco.itReportPath>${main.basedir}/target/jacoco-it.exec</jacoco.itReportPath>
内部构建
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.4.201312101107</version>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<propertyName>utCoverageAgent</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${sonar.jacoco.reportPath}</dataFile>
</configuration>
</execution>
<!-- prepare agent for measuring integration tests -->
<execution>
<id>agent</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${sonar.jacoco.itReportPath}</destFile>
<propertyName>itCoverageAgent</propertyName>
</configuration>
</execution>
<execution>
<id>jacoco-site</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${sonar.jacoco.itReportPath}</dataFile>
</configuration>
</execution>
</executions>
</plugin>
<!-- Reporting plugins -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>${plugin.site.version}</version>
<configuration>
<attach>true</attach>
<reportPlugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changelog-plugin</artifactId>
<version>2.2</version>
<configuration>
<type>range</type>
<range>1</range>
<!--<displayFileDetailUrl>${project.scm.url}/tree/master/%FILE%</displayFileDetailUrl>-->
<headingDateFormat>MM-dd-yyyy</headingDateFormat>
<outputEncoding>${project.reporting.outputEncoding}</outputEncoding>
</configuration>
<reports>
<report>changelog</report>
</reports>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.7</version>
<configuration>
<dependencyDetailsEnabled>false</dependencyDetailsEnabled>
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
</configuration>
<!-- simpler configuration without reportSets available for usual cases -->
<!-- distribution-management, index, dependencies, help, issue-tracking, plugins, cim,
license, dependency-management, mailing-list, project-team, dependency-convergence,
scm, plugin-management, modules, summary -->
<reports>
<report>index</report>
<report>dependencies</report>
<report>issue-tracking</report>
<report>scm</report>
<report>summary</report>
</reports>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.4</version>
<configuration>
<aggregate>true</aggregate>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<reports>
<report>javadoc</report>
<report>aggregate</report>
</reports>
<configuration>
<failOnError>false</failOnError>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.4.201312101107</version>
</plugin>
</reportPlugins>
</configuration>
<executions>
<execution>
<id>attach-descriptor</id>
<goals>
<goal>attach-descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
希望有所帮助!
答案 1 :(得分:0)
我所做的是将两个执行文件(jacoco-ut.exec
和jacoco-it.exec
)合并为一个名为jacoco.exec
的文件,然后将该文件设置为插件的dataFile
首先,让我们定义以下属性:
<jacoco.it.execution.data.file>${project.build.directory}/coverage-reports/jacoco-it.exec</jacoco.it.execution.data.file>
<jacoco.ut.execution.data.file>${project.build.directory}/coverage-reports/jacoco-ut.exec</jacoco.ut.execution.data.file>
<jacoco.execution.data.file>${project.build.directory}/coverage-reports/jacoco.exec</jacoco.execution.data.file>
然后,连同生成报告的配置一起,包含以下代码段以创建合并的文件:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-plugin.version}</version>
<executions>
...
<execution>
<id>merge</id>
<phase>verify</phase>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<fileSets>
<fileSet>
<directory>${project.build.directory}/coverage-reports</directory>
<includes>
<include>*.exec</include>
</includes>
</fileSet>
</fileSets>
<destFile>${jacoco.execution.data.file}</destFile>
</configuration>
</execution>
<execution>
<id>report-merge</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${jacoco.execution.data.file}</dataFile>
</configuration>
</execution>
</executions>
</plugin>
最后,在reporting
部分中配置插件,以从该合并文件生成报告:
<reporting>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<dataFile>${jacoco.execution.data.file}</dataFile>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
...
</plugins>
</reporting>