[英]How to configure JaCoCo maven plugin from command line
我正在嘗試從命令行配置 JaCoCo maven 插件,而不是使用pom.xml
。 到目前為止,我已經成功地使用命令執行了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
階段,但我無法為此階段設置屬性。 我正在運行命令:
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中沒有user property
如jacoco:prepare-agent 。
我有如下輸出:
[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 --
帶有默認值。
GitHub 問題 322已在jacoco-maven-plugin
的jacoco-maven-plugin
版中得到解決。 從這個版本開始,您可以使用用戶屬性jacoco.dataFile
,因此問題中的命令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
屬性沒有用戶屬性,因此您將無法這樣做。 您在調用時正確覆蓋了默認值
mvn -Djacoco.destFile=./coverage/jacoco.exec clean org.jacoco:jacoco-maven-plugin:prepare-agent install
因為jacoco.destFile
是與prepare-agent
目標的destFile
屬性關聯的用戶屬性的名稱。
但是, report
目標的相應dataFile
屬性沒有用戶屬性。 所以你最好的選擇是保持默認值。
當您不能使用屬性時,您可以使用環境變量。
當我得到 Jacoco Diff Coverage jacoco:report includes cannot use property。
所以我使用 ${inc_files}
外殼:
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>
我希望這會很有用。
我們使用以下代碼:
mvn clean devtestcov:atest -Dactive.devtest -Dmaven.test.failure.ignore=true -Djacoco-agent.destfile=target/jacoco.exec
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.