【发布时间】:2016-08-25 01:03:39
【问题描述】:
我的custom maven plugin 有三个目标(mojos):
-
convert分配给默认阶段:process-test-resources -
generateStubs分配给默认阶段:package -
generateTests分配给默认阶段:generate-test-sources
如何将这三个mojo绑定到default lifcycle phase,这样用户就可以简单地使用插件,无需特殊配置和对项目packaging进行任何更改?
用户只需添加:
<plugin>
<groupId>io.codearte.accurest</groupId>
<artifactId>accurest-maven-plugin</artifactId>
<extensions>true</extensions>
</plugin>
而不是
<plugin>
<groupId>io.codearte.accurest</groupId>
<artifactId>accurest-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>convert</goal>
<goal>generateStubs</goal>
<goal>generateTests</goal>
</goals>
</execution>
</executions>
</plugin>
我可以使用components.xml 来实现这一点,如下所示,但这需要一些丑陋的技巧(指定不存在的阶段 - ugly-fix),我不确定这个解决方案是否适用于所有情况。
<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.Lifecycle</role>
<implementation>org.apache.maven.lifecycle.Lifecycle</implementation>
<role-hint>accurest</role-hint>
<configuration>
<id>accurest</id>
<phases>
<phase>ugly-fix</phase> // plugin fail without this
</phases>
<default-phases>
<process-test-resources>
io.codearte.accurest:accurest-maven-plugin:${project.version}:convert
</process-test-resources>
<generate-test-sources>
io.codearte.accurest:accurest-maven-plugin:${project.version}:generateTests
</generate-test-sources>
<package>
io.codearte.accurest:accurest-maven-plugin:${project.version}:generateStubs
</package>
</default-phases>
</configuration>
</component>
</components>
</component-set>
这是正确的吗?进行此类配置是否有更好的方法?
更多信息:
【问题讨论】:
标签: maven maven-3 maven-plugin