压倒一切的“干净” Maven 中的生命周期
我正在阅读一本解释如何覆盖 Maven 的“默认”生命周期的书。
它说:要为打包类型定义新的生命周期,您需要在 Plexus 中配置 LifecycleMapping 组件。在您的插件项目中,在 src/main/resources 下创建 META-INF/plexus/components.xml。在 Components.xml 中添加如下所示的内容,就完成了。通过以下配置,我可以自定义“jar”打包类型的默认生命周期。现在如果我执行
$ mvn 包
它直接执行“package”阶段,跳过默认生命周期的所有其他阶段,并执行“maven-zip-plugin”的“echo”目标。
<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>zip</role-hint>
<implementation>
org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
</implementation>
<configuration>
<phases>
<package>org.sonatype.mavenbook.plugins:maven-zip-plugin:echo
</package>
</phases>
</configuration>
</component>
</components>
</component-set>
我的问题是:如何定制“干净”的生命周期。例如,假设有人输入
$ mvn 干净
我不想运行 clean:clean 来执行“maven-clean-plugin”插件的“clean”目标,而是想执行“customPlugin”的“customClean”目标。
I was going through a book that explain how to override 'default' lifecycle of Maven.
It says: To define a new lifecycle for a packaging type, you'll need to configure a LifecycleMapping component in Plexus. In your plugin project, create a META-INF/plexus/components.xml under src/main/resources. In components.xml add the content as shown below, and you're done. With below configuration, I'm able to customize the default lifecycle for 'jar' packaging type. Now If I exeute
$ mvn package
It straigh away executes 'package' phase skipping all other phases of default lifecycle and executes 'echo' goal of 'maven-zip-plugin'.
<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>zip</role-hint>
<implementation>
org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
</implementation>
<configuration>
<phases>
<package>org.sonatype.mavenbook.plugins:maven-zip-plugin:echo
</package>
</phases>
</configuration>
</component>
</components>
</component-set>
My question is: How can I customize 'clean' lifecycle. For example, assume when some one types
$ mvn clean
Instead of running clean:clean that will execute 'clean' goal of 'maven-clean-plugin' plugin, I wanted to execute 'customClean' goal of 'customPlugin'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于您所描述的情况,更简单的方法是阻止
maven-clean-plugin
在clean
阶段运行,并将 customPlugin 附加到clean
> 相代替。这比短路整个生命周期更简单,并将所有 Maven 配置保留在 pom.xml 中。1 阻止 maven-clean-plugin
2 将您自己的插件附加到 clean 阶段
For what you describe, it is simpler to just prevent the
maven-clean-plugin
from running during theclean
phase, and attach customPlugin to theclean
phase instead. This is simpler than short-circuiting the whole lifecycle, and keeps all your maven config in your pom.1 prevent the maven-clean-plugin
2 attach your own plugin to the clean phase