[英]Is prepare-agent goal is necessary in jacoco-maven-plugin?
在我的項目中,如果我寫這樣的pom:
...
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>post-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
...
運行mvn install后,它不會在我的項目中生成報告。
但我改變它
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>pre-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
有效!!
我想知道有什么不同?
我在這里閱讀了官方文檔: http : //www.jacoco.org/jacoco/trunk/doc/prepare-agent-mojo.html
目標prepare-agent只是針對jvm代理的set屬性,而不是啟動jvm代理,為什么有必要?
那么你所分享的鏈接prepare:agent
已經讀了很多:
Prepares a property pointing to the JaCoCo runtime agent that can be passed as a VM argument to the application under test.
因此,如果目標沒有綁定到插件執行,那么對於打包類型eclipse-test-plugin,屬性的默認行為可以是argLine
或tycho.testArgLine
。
在您的情況下,如果我們假設其argLine
,並且您的項目定義了用於測試執行的VM參數,則需要確保它們包含此屬性。
在maven-surefire-plugin的情況下執行此操作的方法之一是使用語法進行后期屬性評估:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{argLine} -your -extra -arguments</argLine>
</configuration>
</plugin>
詳細的Java Agent
文檔可以幫助您更深入地了解Jacoco如何使用自己的代理提供一種機制,允許在類加載期間獨立於應用程序框架對所有類文件進行內存預處理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.