[英]maven site plugin does not include Jacoco reports
I've integrated the jacoco-maven-plugin in my project, based on this excellent guide: http://www.petrikainulainen.net/programming/maven/creating-code-coverage-reports-for-unit-and-integration-tests-with-the-jacoco-maven-plugin/我已经在我的项目中集成了 jacoco-maven-plugin,基于这个优秀的指南: http ://www.petrikainulainen.net/programming/maven/creating-code-coverage-reports-for-unit-and-integration- 使用 jacoco-maven-plugin 测试/
The jacoco plugin runs fine. jacoco 插件运行良好。 However, the maven-site-plugin does not include the jacoco reports in the site.但是,maven-site-plugin 不包括站点中的 jacoco 报告。 To be more specific: the 'Project Reports' section does not list the jacoco reports.更具体地说:“项目报告”部分没有列出 jacoco 报告。 The jacoco reports themselves are available in the target/site/jacoco-ut and target/site/jacoco-it directories. jacoco 报告本身在 target/site/jacoco-ut 和 target/site/jacoco-it 目录中可用。
Here's what I did (without success so far).这就是我所做的(到目前为止没有成功)。
First, included the jacoco-maven-plugin as a plugin in the build section of my pom.xml, as explained in the guide referenced above.首先,将 jacoco-maven-plugin 作为插件包含在我的 pom.xml 的构建部分中,如上面引用的指南中所述。 I'm using jacoco version 0.6.4.201312101107.我正在使用 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>
Second, included the jacoco-maven-plugin in the report section of my pom.xml: no success.其次,在我的 pom.xml 的报告部分中包含 jacoco-maven-plugin:没有成功。
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.plugin.version}</version>
</plugin>
Third, tried to add a reportsets section to the jacoco-maven-plugin in the report section: no success.第三,试图将reportsets部分添加到jacoco - Maven的插件在报告部分:没有成功。
<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>
Can anyone help me to make the maven-site-plugin reference the coverage reports generated by jacoco in the 'Project Reports' section of the site?任何人都可以帮助我使 maven-site-plugin 引用 jacoco 在站点的“项目报告”部分中生成的覆盖率报告吗?
I've found jacoco to be very tricky, the below config worked for me, i put it together from bits and pieces from blogs in the properties我发现 jacoco 非常棘手,下面的配置对我有用,我把它从属性中的博客的点点滴滴拼凑起来
<jacoco.reportPath>${main.basedir}/target/jacoco.exec</jacoco.reportPath>
<jacoco.itReportPath>${main.basedir}/target/jacoco-it.exec</jacoco.itReportPath>
inside the build在构建内部
<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>
Hope that helps !希望有帮助!
What I did was merge the two execution files ( jacoco-ut.exec
and jacoco-it.exec
) into a single file named jacoco.exec
and then set that file as the dataFile
of the plugin.我所做的是将两个执行文件( jacoco-ut.exec
和jacoco-it.exec
)合并到一个名为jacoco.exec
文件中,然后将该文件设置为插件的dataFile
。
First, let's define these properties:首先,让我们定义这些属性:
<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>
Then, along with the configuration to generate the reports, include this snippet to create the merged 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>
And, finally, configure the plugin in the reporting
section to generate the report from that merged file:最后,在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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.