问题描述
我要通过一本书,说明如何重写的Maven的默认的生命周期。
I was going through a book that explain how to override 'default' lifecycle of Maven.
它说:要定义包装类型的新的生命周期,你需要在丛配置LifecycleMapping组件。在你的插件项目中,创建在src /主/资源META-INF /丛/ components.xml文件。在components.xml中添加的内容如下图所示,就大功告成了。下面的配置,我能够自定义'罐子'包装类型的默认生命周期。现在,如果我exeute结果
$ MVN包
结果
它straigh程执行时一揽子阶段跳过默认的生命周期的所有其他阶段并执行回响的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>
我的问题是:我如何自定义'干净'的生命周期。例如,假设在某一个类型的结果
$ MVN清洁
结果
而不是运行清洁:清洁,将执行的Maven的清理插件插件'干净'的目标,我想执行的customPlugin'customClean'的目标。
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'.
推荐答案
有关你的描述,这是简单的只是prevent的 Maven的清理插件
从在清洁
阶段运行,并连接customPlugin到清洁
阶段来代替。这比短路的整个生命周期更简单,并保持所有的Maven的配置在你的POM。
For what you describe, it is simpler to just prevent the maven-clean-plugin
from running during the clean
phase, and attach customPlugin to the clean
phase instead. This is simpler than short-circuiting the whole lifecycle, and keeps all your maven config in your pom.
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
2附上自己的插件,以干净的阶段
<plugin>
<artifactId>maven-customPlugin-plugin</artifactId>
<version>customPlugin-version</version>
<executions>
<execution>
<id>customised-clean</id>
<goals>
<goal>customClean</goal>
</goals>
<phase>clean</phase>
</execution>
</executions>
</plugin>
这篇关于在Maven的重写'干净'的生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!