不能創建無需編寫Maven插件自定義的生命週期。
並且在沒有黑客入侵Maven的情況下,至少從Maven 3.0.5開始,通過插件向Maven添加自定義階段是不可能的。在處理任何插件之前,這些階段將由Maven的核心從其配置加載。
如果你真的想用一個命令來做你想做的事,那麼寫一個插件是唯一的方法。在您的settings.xml
中有一些pluginGroup mappings,這可以變得更簡單(您可以指定mvn my:plugin
而不是mvn com.mygroupid:plugin
)。
但是,如果您願意在命令行中使用稍微冗長的語法,您可以通過配置文件和exec maven plugin來實現您想要的功能。
向使用exec插件運行自身的模塊B添加配置文件。
事情是這樣的:
<project>
...
<profiles>
<!-- This profile uses local webapp security instead of the BlueCoat device, useful for testing -->
<profile>
<id>execb</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>runb</id>
<goals>
<goal>java</goal>
</goals>
<phase>verify</phase> <!-- Anything after package phase -->
<configuration>
<!-- Exec plugin configuration goes here -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
你需要取決於你如何運行你的JAR,更多信息here配置Exec插件。
這是做什麼是運行exec插件作爲模塊B的內部的一部分,但只有當execb
配置文件被激活。
現在,當你只是想建立項目(不加任何可執行程序),打造像正常(例如mvn install
)。
如果你想建立和運行,使用命令行:
mvn install -Pexecb
,它會做的高管作爲構建的一部分。
這聽起來像集成測試Maven中存在的所需。存在預集成測試生命週期階段和集成測試生命週期階段,因此您可以將exec插件綁定到該階段並運行** mvn verify ** – khmarbaise