如何将插件Mojos(目标)绑定到默认生命周期的几个阶段? [英] How to bind plugin mojos (goals) to few phases of default lifecycle?
问题描述
我的自定义maven插件具有三个目标(mojos):
My custom maven plugin have three goals (mojos):
-
convert
分配给默认阶段:process-test-resources
-
generateStubs
分配给默认阶段:package
-
generateTests
分配给默认阶段:generate-test-sources
convert
assigned to default phase:process-test-resources
generateStubs
assigned to default phase:package
generateTests
assigned to default phase:generate-test-sources
如何将这三个mojo绑定到默认lifcycle阶段,因此用户可以简单地使用插件而无需进行特殊配置,也无需更改项目packaging
?
How to bind this three mojo to default lifcycle phase, so the user can simply use plugin without special configuration and any changes to project 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
),而且我不确定此解决方案是否在所有情况下均有效.
I can achieve this with components.xml
like below, but this requires some ugly hacks (specifing not existing phase - ugly-fix
) and I'm not sure, if this solution is working in all cases.
<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>
这是正确的吗?是进行这种配置的更好方法吗?
Is this correct? Is better way to do such configuration?
更多信息:
- 工作 components.xml .
- 使用此配置的示例项目: https://github.com/mariuszs/gs-rest-service-accurest
- Working components.xml.
- Sample project which is using this configuration: https://github.com/mariuszs/gs-rest-service-accurest
推荐答案
您可以通过将ugly-fix
替换为<phases>
标记中的正确目标来实现:
You can achieve that by replacing ugly-fix
with correct goals in <phases>
tag:
<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>
<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>
</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>
这篇关于如何将插件Mojos(目标)绑定到默认生命周期的几个阶段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!