[英]How to execute maven plugin in a certain phase and with certain configurations through command line?
我做了一個maven插件,我想通過命令行執行插件而不改變基准項目中的任何東西(例如,pom.xml)。 目前,我正在使用mvn groupId:artifactId:version:goal test
(我想與測試一起執行我的插件)。 但這里有問題:
我不知道如何通過命令行配置我的插件。 例如,如果允許更改 pom,在<configuration>
有很多用戶定義的配置要設置,例如:
<plugin> <groupId>...</groupId> <artifactId>...</artifactId> <version>...</version> <configuration> <debug>true</debug> <packageNamePrefix>com/foo/bar</packageNamePrefix> </configuration> <executions> <execution> <goals> <goal>...</goal> </goals> </execution> </executions> </plugin>
如何使用命令行在<configuration>
配置這些屬性?
我想在某個階段啟動我的插件(特別是在LifecyclePhase.PROCESS_TEST_CLASSES
)。 例如,我的 mojo 類是這樣實現的:
@Mojo(name = "goal", defaultPhase = LifecyclePhase.PROCESS_TEST_CLASSES, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true) @Execute(phase = LifecyclePhase.PROCESS_TEST_CLASSES) public class myMojo extends MyAbstractMojo { ... }
當我使用mvn groupId:artifactId:version:goal test
或mvn test groupId:artifactId:version:goal
,我遺憾地發現我的插件在不正確的階段啟動。 如何解決? 有沒有辦法在這些命令行中明確聲明欲望階段?
對於第一個問題:
您可以讀取插件中的屬性,也可以使用-Dproperty=value
在命令行上設置屬性。
對於第二個問題:
如果直接在命令行調用插件(如groupId:artifactId:version:goal
),它不屬於任何階段。 所以如果你跑
mvn groupId:artifactId:version:goal test
首先運行插件,然后是從開始到test
所有階段,如果你運行
mvn test groupId:artifactId:version:goal
然后首先運行test
所有階段,然后運行您的插件。
您不能在命令行上為插件指定階段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.