Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable phases in Maven lifecycle

Tags:

maven

maven-3

By disable I mean completely, entirely cut the phase from the lifecycle, so that it is not even invoked.

I might need a custom lifecycle but I could not find an easy way to define it straight in my pom.xml. It appears I need to write a plugin just to list phases I want.

For example, I would like default-testResources, default-testCompile and default-test phases to never happen and turn my build log from this:

[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] ------------------------------------------------------------------------

into this:

[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] ------------------------------------------------------------------------
like image 544
Alex Avatar asked Mar 06 '13 14:03

Alex


People also ask

Which phases is present in site Maven life cycle?

There are three standard lifecycles in Maven: clean, default (sometimes called build) and site.

How many phases are there in default life cycle of Maven?

The default build lifecycle consists of 23 phases, as it's the main build lifecycle. On the other hand, the clean life cycle consists of 3 phases, while the site lifecycle is made up of 4 phases.

Which are the applicable Maven phases?

Any maven build phases that come before the specified phase is also executed. For example, if we run mvn package then it will execute validate, compile, test, and package phases of the project.

How do you specify a valid lifecycle phase in Maven?

You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>.


1 Answers

If you want to continue using a predefined packaging (jar, war, etc.) you cannot totally remove them. You may leave the packaging as pom and define your own lifecycle by binding the goals you want to the desired phases, or you may define your own lifecycle entirely. You may also bind a default goal to phase none to prevent the goal from doing any real work as shown.

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

All that said - khmarbaise's question is a good one. Generally it's not a best practice to change the existing pre-built lifecycles.

like image 192
user944849 Avatar answered Oct 22 '22 12:10

user944849