Adding phases to the maven lifecycle?

maven lifecycle mapping
which of the following is not a true description about the maven's default lifecycle phases?
maven goals eclipse
maven skip lifecycle phase
maven build command
maven phase vs goal
mvn clean
exec-maven-plugin phase

I try to add some additional phases to the maven lifecycle. Mainly to add some additional test levels:

<phases>
    <phase>initialize</phase>
    <phase>process-resources</phase>
    <phase>compile</phase>
    <phase>process-test-resources</phase>
    <phase>test-compile</phase>
    <phase>test</phase>
    <phase>prepare-package</phase>
    <phase>package</phase>
    <phase>pre-integration-test</phase>
    <phase>integration-test</phase>
    <phase>post-integration-test</phase>
    <phase>pre-application-test</phase>
    <phase>application-test</phase>
    <phase>post-application-test</phase>
    <phase>pre-system-test</phase>
    <phase>system-test</phase>
    <phase>post-system-test</phase>
    <phase>finalize-tests</phase>
    <phase>install</phase>
    <phase>deploy</phase>
</phases>

Above contains new application-test and system-test phase (including pre- and post-).

I've started a test plugin at: codezoo-lifecycle-maven-plugin The pom I use for testing is in the src/it folder.

It seems the new phases or somewhat picked up but there are some weird things going on:

mvn post-application-test

This works. Also the echo plugin that I added for testing is executed. But there are some warnings (using maven 3.3.9).

mvn install

Executes the default lifecycle skipping the new phases.

If I change the id of the lifecycle fomr "test-levels" to "default" the phases are executed twice.

The warnings issued are:

[WARNING] Duplicated lifecycle phase package. Defined in default but also in test-levels
[WARNING] Duplicated lifecycle phase pre-integration-test. Defined in default but also in test-levels
[WARNING] Duplicated lifecycle phase integration-test. Defined in default but also in test-levels
....

The source code that issues this warning indicates the lifecycle is not properly namespaced. But I cannot figure out how that is done.

I found some hints on the web: create-a-new-phase (Stackoverflow) or in other plugins like the maven-scm-publish-plugin or the docker-maven-plugin. But those are either creating a complete new lifecycle or just change the plugin mapping from the default maven lifecycle.

All other stuff on the web regarding this topic seems to be at least 4 years old...

So:

  • how can I add additional phases to the maven default lifecycle (If I have to repeat the default plugin mappings: I can live with that)
  • how can I namespace the new lifecycle? It seems I create my own packaging (which is referenced as role-hint in the configuration). But still maven has some fallback to the default lifecycle.
  • can the default maven phases not be re-used?

The current state of the test plugin is on github.

Thanks!

Build Lifecycle - Apache Maven, On the other hand, clean life cycle consists of 3 phases, while the site lifecycle is made up of 4 phases. 3. Maven Phase. 4. I try to add some additional phases to the maven lifecycle. Mainly to add some additional test levels: <phases> <phase>initialize</phase> <phase>process-resources</phase> <phase>compile</phase> <phase>process-test-resources</phase> <phase>test-compile</phase> <phase>test</phase> <phase>prepare-package</phase> <phase>package</phase> <phase>pre-integration-test</phase> <phase>integration-test</phase> <phase>post-integration-test</phase>

Usually in case when you need additional build phases - it's the signal that you need to split your code and move part of it to additional maven module that dedicated to separate functionality.

Add dependency between modules, so in result after start build Maven build graph of modules and build them in expected order, one by one.

Maven Goals and Phases, Maven - Build Life Cycle - A Build Lifecycle is a well-defined sequence of phases, which define the order in which the goals are to be executed. Here phase  A Build Lifecycle is a well-defined sequence of phases, which define the order in which the goals are to be executed. Here phase represents a stage in life cycle. As an example, a typical Maven Build Lifecycle consists of the following sequence of phases. Resource copying can be customized in this phase.

you can take a look at the mvn-finisher plug-in which adds several phases to be called on maven build end (for success, failure and interruption)

Maven - Build Life Cycle, Creating a custom Maven lifecycle mapping for your project's build mojo binding is added to the generate-resources lifecycle phase like this: Let Start with Life Cycle vs Phase. We will see the relationship between these two. Life Cycle VS Phase. Maven has 3 life cycles: – Clean – Default – Site. You may think that when you run this command: mvn clean. It will call the Clean life cycle. That is wrong. Actually, it is called the Clean phase in the clean life cycle! (yep, a well

Create a Customized Build Process in Maven, Maven :: How do I add a site to a project using the archetype plugin? Maven :: How do I generate Maven Changelog Plugin reports for a site? Maven :: How do I​  The default build life cycle consists of 23 phases as it's the main build lifecycle. On the other hand, clean life cycle consists of 3 phases, while the site lifecycle is made up of 4 phases. 3. Maven Phase. A Maven phase represents a stage in the Maven build lifecycle. Each phase is responsible for a specific task.

What are the phases of the maven site lifecycle?, Great, we now know a bit more about the build lifecycle and its phases, plugin goals and executions, and that there's a set of plugins configured  Maven: Build Life Cycle of clean phase. As mentioned above, this clean phase is used to clean up the project and make it ready for the fresh compile and deployment. The command used for the same is mvn post-clean. When this command is invoked, maven executes the below tasks via executing the below commands internally : mvn pre-clean; mvn clean

Mastering Maven: Adding Plugins, The default life cycle is the build life cycle which is done by simply adding the build phase after the mvn  The maven builds executed through the command line runs a set of phases and goals. The pom.xml configuration plays a major role in setting up the project build lifecycle. The packaging value of pom.xml file defines the set of goals to be executed by the maven build.

Comments
  • thanks for the reply! I had given up hope. As you say option 2 is closest to what I wanted to achieve. At the time that would have meant to implement one for ear, war, jar. But today extending jar might be enough - so better chances. I'll check out that blog post you linked. Just a second :)
  • as i mentioned above its mainly to add some additional test levels. To have more structure there. I'm not a fan of moving test sources away from its code and repeating the failsafe plugin in several executions does not bring the level of flexibility I want to achieve for the developers.
  • Ok, some unit tests should be in the same module as code, some integration test for Spring context for example - too. But some functional tests could be placed in another separate module