maven-2 - 在 Maven 中覆盖 'clean' 生命周期

我正在阅读一本解释如何覆盖 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' 目标。

最佳答案

对于您所描述的,在 clean 阶段阻止 maven-clean-plugin 运行并将 customPlugin 附加到 clean 更简单 阶段代替。这比缩短整个生命周期更简单,并将所有 maven 配置保存在 pom 中。

1 阻止 maven-clean-plugin

<plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.4.1</version>
    <configuration>
        <skip>true</skip>
    </configuration>
</plugin>

2 将您自己的插件附加到 clean 阶段

<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-2 - 在 Maven 中覆盖 'clean' 生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5171950/

相关文章:

java - ANT 等待文件创建

android - 错误 JSON.simple : java. util.zip.ZipExcep

build - 如何在 intellij idea 中构建一个 java swing 应用程序

ant - 什么是好的 Ant 目标命名约定?

build - 更改 TFS 2010 中构建通知的轮询间隔

android - 使用 Eclipse 从命令行构建 Android 项目

ios - Xcode 4.5 中的代码签名是如何完成的

build - 寻找 .NET BuildServer SaaS

build - 如何重建已下载的已编辑 perl6 模块?

android - 使用ant构建Android项目时如何在build.properties中指定多