我正在尝试从命令行而不是pom.xml来配置JaCoCo maven插件。到目前为止,我已经设法用命令执行了prepare-agent:
mvn -X -Djacoco.destFile=./coverage/jacoco.exec clean org.jacoco:jacoco-maven-plugin:prepare-agent install带输出:
[DEBUG] Configuring mojo org.jacoco:jacoco-maven-plugin:0.7.6.201602180812:prepare-agent from plugin realm ClassRealm[plugin>org.jacoco:jacoco-maven-plugin:0.7.6.201602180812, parent: sun.misc.Launcher$AppClassLoader@70dea4e]
[DEBUG] Configuring mojo 'org.jacoco:jacoco-maven-plugin:0.7.6.201602180812:prepare-agent' with basic configurator -->
[DEBUG] (f) destFile = /src/coverage/jacoco.exec
...这会创建./coverage/jacoco.exec文件,现在我正在尝试运行report stage,但我无法设置此stage的属性。我正在运行命令:
mvn -X -Djacoco.dataFile=./coverage/jacoco.exec -Djacoco.outputDirectory=./jacoco_ut org.jacoco:jacoco-maven-plugin:report或
mvn -X -DdataFile=./coverage/jacoco.exec -DoutputDirectory=./jacoco_ut org.jacoco:jacoco-maven-plugin:report和在jacoco:report中一样,在jacoco:prepare-agent中没有user property。
我有如下输出:
[DEBUG] Configuring mojo 'org.jacoco:jacoco-maven-plugin:0.7.6.201602180812:report' with basic configurator -->
[DEBUG] (f) dataFile = /src/target/jacoco.exec
[DEBUG] (f) outputDirectory = /src/target/site/jacoco
[DEBUG] (f) outputEncoding = UTF-8
[DEBUG] (f) project = MavenProject: project:3.2.0-SNAPSHOT @ /src/pom.xml
[DEBUG] (f) skip = false
[DEBUG] (f) sourceEncoding = UTF-8
[DEBUG] -- end configuration --使用默认值。
发布于 2016-04-20 19:54:27
更新至0.7.8
自jacoco-maven-plugin的version 0.7.8起,GitHub issue 322已被解析。从这个版本开始,您可以使用用户属性jacoco.dataFile,因此问题中的命令将按原样工作。
要在命令行上强制执行版本,您应该具备:
mvn -Djacoco.destFile=./coverage/jacoco.exec clean org.jacoco:jacoco-maven-plugin:0.7.8:prepare-agent install您还可以在您的POM中配置jacoco-maven-plugin并显式指定此版本。
或者保留缺省值
在0.7.8版本之前,dataFile属性没有user property,因此您无法做到这一点。调用时正确地覆盖了默认值
mvn -Djacoco.destFile=./coverage/jacoco.exec clean org.jacoco:jacoco-maven-plugin:prepare-agent install因为jacoco.destFile是与prepare-agent目标的destFile属性关联的用户属性的名称。
但是,report目标的相应dataFile属性没有用户属性。所以你最好的选择就是保留默认设置。
发布于 2020-05-15 09:53:04
当你不能使用属性时,你可以使用环境变量。
当我获得Jacoco Diff覆盖率时,jacoco:report includes cannot use属性。
因此,我使用${inc_files}
Shell:
echo "+++git diff+++"
inc_files=`git diff --name-only master | grep -oP 'com/languoguang/xxclouds/quark.*.java' | xargs | sed 's/.java/.class/g' | xargs | sed -e 's/ /,/g'`;
echo ${inc_files};
echo "---git diff---";
echo "+++maven test jacoco+++";
mvn -B -f pom.xml -Dinc_files=${inc_files} clean test -Dmaven.test.failure.ignore=true;
echo "---maven test jacoco---";pom.xml:
<execution>
<configuration>
<title>quark-frameworks-coverage-inc</title>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-aggregate/jacoco-aggregate-inc/</outputDirectory>
<includes>${inc_files}</includes>
</configuration>
<id>report-aggregate-inc</id>
<phase>test</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>我希望这将是有用的。
发布于 2020-05-15 10:05:53
我们使用以下代码:
mvn clean devtestcov:atest -Dactive.devtest -Dmaven.test.failure.ignore=true -Djacoco-agent.destfile=target/jacoco.exechttps://stackoverflow.com/questions/36742797
复制相似问题