在Maven多模块项目中合并声纳指标 [英] Merging sonar metrics across a maven multi-module project
问题描述
我继承了一个奇怪的Maven多模块项目.标准的业务类和单元测试位于名为代码"的模块中,我们对该模块有很好的简单声纳指标.第二个模块包含针对已部署的glassfish服务器运行的各种集成样式测试,这些测试在integ-test模块中作为单元测试运行.
I've inherited an odd maven multi module project. The standard business classes and unit tests are in a module called 'code' and we've nice simple working sonar metrics for this module. The second module holds various integration style tests which run against a deployed glassfish server, these run as unit test in the integ-test module.
pom.xml // root level,
code // business code and unit tests :-)
moduleA
moduleB
integ-test // ;-(
moduleA
moduleB
我知道最简单的选择是将'integ-test'类移到'code'模块中,并将其重构为真正的集成测试,但是目前这不是一个选择.
I know the simplest option is to move the 'integ-test' classes into the 'code' module and refactor them as real integration tests but for the moment this isn't an option.
我想出了一种方法,可以通过使用jacoco:dump目标将jacococ.exec下载到integ-test模块中来记录"integ-tests"模块的代码覆盖水平.
I've figured out a way to record the level of code coverage for the 'integ-tests' module by using the jacoco:dump goal to download the jacococ.exec to the integ-test modules.
我的maven pom结构现在看起来像这样
My maven pom structure now looks like this
pom.xml // defined jacoco verify -> report goal
code // business code and unit test
moduleA
target/jacoco.exec - unit test coverage
pom.xml
pom.xml - defines standard jacoco prepare-agent goal
integ-test //
moduleA
target/jacoco.exec - really integration test coverage
pom.xml
pom.xml- defines jacoco dump and merge
我当前的方法是合并"integ-test"模块中的所有jacococ.exec文件,并使用"destFile"值将代码"模块中的这些详细信息另存为jacoco-it.exec文件.然后,标准的sonar:sonar目标应该拾取该文件并将其用作集成测试范围.
My current approach is to merge all the jacococ.exec files in the 'integ-test' module and use the 'destFile' value to save these details the 'code' module as a jacoco-it.exec file. The standard sonar:sonar goal should then pick up this file and use it as the integration test coverage.
pom.xml
integ-test
moduleA
target/jacoco.exec - really integration test coverage modA
moduleB
target/jacoco.exec - really integration test coverage modB
code
moduleA
moduleB
target/jacoco-it.exec - This should be the merged content of the two files above
pom.xml
我的根级别pom.xml定义了这个jacoco-maven-plugin配置
My root level pom.xml defines this jacoco-maven-plugin config
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<append>true</append>
<includes>
<include>com/a/b/c/**</include>
</includes>
</configuration>
<executions>
<execution>
<id>jacoco-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-dump</id>
<phase>pre-integration-test</phase>
<goals>
<goal>dump</goal>
</goals>
</execution>
<execution>
<id>jacoco-merge</id>
<phase>post-integration-test</phase>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<fileSets>
<fileSet implementation="org.apache.maven.shared.model.fileset.FileSet">
<directory>${project.basedir}/integ-test</directory>
<includes>
<include>*.exec</include>
</includes>
</fileSet>
</fileSets>
<destFile>${sonar.jacoco.itReportPath}</destFile>
</configuration>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<sonar.jacoco.itReportPath>${project.basedir}/../target/jacoco-it.exec</sonar.jacoco.itReportPath>
我已经将jacoco:merge目标链接到了maven集成后测试阶段,以确保合并在测试运行后发生,但是"jacoco-it.exec"文件始终在"integ-测试"文件夹.
I've linked the jacoco:merge goal to the maven post-integration-test phase to ensure the merge happens after the tests are run, but the 'jacoco-it.exec' file is always created within the 'integ-test' folder.
有什么建议吗?
推荐答案
如何指向主pom目标目录中的destFile?只需定义
What about pointing to destFile in target directory of the master pom? Just define
<configuration>
<append>true</append>
<destFile>${project.basedir}/../target/jacoco-it.exec</destFile>
<propertyName>jacoco.integrationtest.arguments</propertyName>
</configuration>
在子项目中.所有coverage数据都将附加在jacoco-it.exec文件中. 该文件由sonarqube提取,您将看到此覆盖范围是IT覆盖范围. 您也可以使用jacoco.exec作为文件名.
in the sub-projects. All coverage data will be appended in the jacoco-it.exec file. This file is picked up by sonarqube and you will see the coverage as IT coverage. You can use jacoco.exec as file name as well.
这篇关于在Maven多模块项目中合并声纳指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!