本文介绍了如何在Maven3中禁用默认生命周期阶段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过禁用,我的意思是完全、完全地将该阶段从生命周期中删除,这样甚至不会调用它。

我可能需要自定义生命周期,但我找不到一种简单的方法在我的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:projHelpDesk
eposrcmain
esources
[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:projHelpDesk
epo	argethelpdesk]
[INFO] Processing war project
[INFO] Copying webapp resources [d:projHelpDesk
eposrcmainwebapp]
[INFO] Webapp assembled in [40 msecs]
[INFO] Building war: d:projHelpDesk
epo	argethelpdesk.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:projHelpDesk
eposrcmain
esources
[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:projHelpDesk
epo	argethelpdesk]
[INFO] Processing war project
[INFO] Copying webapp resources [d:projHelpDesk
eposrcmainwebapp]
[INFO] Webapp assembled in [40 msecs]
[INFO] Building war: d:projHelpDesk
epo	argethelpdesk.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

推荐答案

如果要继续使用预定义的包(JAR、WAR等)。您不能完全删除它们。您可以将包装保留为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的问题都很好。通常,更改现有的预置生命周期不是最佳做法。

这篇关于如何在Maven3中禁用默认生命周期阶段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 20:27