![](/img/trans.png)
[英]Running a specific Maven plugin goal from the command line in a sub-module of a multi-module reactor project
[英]Maven calling maven plugin goal from command line
您能告訴我如何使用以下配置在命令行中調用maven surefire嗎?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<id>Custom tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<classesDirectory>target/generated/classes/normalCase/</classesDirectory>
<reportsDirectory>target/generated/reports/normalCase/</reportsDirectory>
</configuration>
</execution>
</executions>
</plugin>
當在我的pom.xml中定義了surefire並執行階段測試時,它完全按照我希望的方式工作:它嘗試在位於target / generated / classes / normalCase中的類上運行我的測試。
所以我嘗試了以下命令行:
mvn surefire:test -DclassesDirectory="target/generated/classes/normalCase/"
但是,不,它會繼續檢查默認值目錄中的類“ target / classes”。
那么如何在命令行中實現呢?
回顧一下你的情況。 您將在構建期間生成源代碼的多個版本,這些版本的每個版本最終都位於target
下的單獨文件夾中。 對於每個版本,您都希望使用maven-surefire-plugin
執行單元測試。 讓我們考慮一下基本目錄為target/generated/classes
。 這意味着每個版本都有多個子目錄target/generated/classes/version1
, target/generated/classes/version2
...。
一種可能的解決方案是使用iterator-maven-plugin
遍歷文件夾的所有子目錄,然后從所有這些子目錄調用maven-surefire-plugin
。 變量@item@
保存當前項目。
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>iterator-maven-plugin</artifactId>
<version>0.3</version>
<executions>
<execution>
<id>iterate</id>
<phase>test</phase>
<goals>
<goal>iterator</goal>
</goals>
<configuration>
<folder>target/generated/classes</folder>
<pluginExecutors>
<pluginExecutor>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>
<goal>test</goal>
<configuration>
<classesDirectory>target/generated/classes/@item@</classesDirectory>
<reportsDirectory>target/generated/reports/@item@</reportsDirectory>
</configuration>
</pluginExecutor>
</pluginExecutors>
</configuration>
</execution>
</executions>
</plugin>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.