禁用Maven生命周期中的阶段

时间:2013-03-06 14:02:41

标签: maven maven-3

如何在Maven 3默认生命周期中禁用不需要的阶段?

通过禁用我的意思是完全完全切断了生命周期中的阶段,因此甚至没有调用它。

我可能需要一个自定义生命周期,但我找不到一种简单的方法来直接在pom.xml中定义它。看来我需要编写一个插件来列出我想要的阶段。

例如,我希望default-testResourcesdefault-testCompiledefault-test阶段永远不会发生,并从此处转换我的构建日志:

[INFO] ------------------------------------------------------------------------
[INFO] Building HelpDesk Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ helpdesk ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory d:\proj\HelpDesk\repo\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ helpdesk ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ helpdesk ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ helpdesk ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ helpdesk ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-war-plugin:2.3:war (default-war) @ helpdesk ---
[INFO] Packaging webapp
[INFO] Assembling webapp [helpdesk] in [d:\proj\HelpDesk\repo\target\helpdesk]
[INFO] Processing war project
[INFO] Copying webapp resources [d:\proj\HelpDesk\repo\src\main\webapp]
[INFO] Webapp assembled in [40 msecs]
[INFO] Building war: d:\proj\HelpDesk\repo\target\helpdesk.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

进入这个:

[INFO] ------------------------------------------------------------------------
[INFO] Building HelpDesk Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ helpdesk ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory d:\proj\HelpDesk\repo\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ helpdesk ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-war-plugin:2.3:war (default-war) @ helpdesk ---
[INFO] Packaging webapp
[INFO] Assembling webapp [helpdesk] in [d:\proj\HelpDesk\repo\target\helpdesk]
[INFO] Processing war project
[INFO] Copying webapp resources [d:\proj\HelpDesk\repo\src\main\webapp]
[INFO] Webapp assembled in [40 msecs]
[INFO] Building war: d:\proj\HelpDesk\repo\target\helpdesk.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

1 个答案:

答案 0 :(得分:13)

如果您想继续使用预定义的包装(罐子,战争等),您无法完全删除它们。您可以将包装保留为pom并通过将所需目标绑定到所需阶段来定义自己的生命周期,或者您可以完全定义自己的生命周期。您还可以将默认目标绑定到阶段none,以防止目标执行任何实际工作。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <executions>
        <execution>
            <id>default-testResources</id>
            <phase>none</phase>
        </execution>
    </executions>
</plugin>

所有这一切 - khmarbaise的问题很好。通常,改变现有的预建生命周期不是最佳做法。