Questions tagged [maven-lifecycle]

For questions regarding the different lifecycle stages and their execution phases in building projects with Apache Maven.

For questions regarding the different lifecycle stages and their execution phases in building projects with Apache Maven.

Maven is based around the central concept of a build lifecycle. What this means is that the process for building and distributing a particular artifact (project) is clearly defined.

For the person building a project, this means that it is only necessary to learn a small set of commands to build any Maven project, and the POM will ensure they get the results they desired.

There are three built-in build lifecycles: default, clean and site. The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, while the site lifecycle handles the creation of your project's web site.

Each of these build lifecycles is defined by a different list of build phases, wherein a build phase represents a stage in the lifecycle.

For example, the default lifecycle comprises of the following phases (for a complete list of the lifecycle phases, refer to the Lifecycle Reference):

  • validate - validate the project is correct and all necessary information is available
  • compile - compile the source code of the project
  • test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package - take the compiled code and package it in its distributable format, such as a JAR.
  • verify - run any checks on results of integration tests to ensure quality criteria are met
  • install - install the package into the local repository, for use as a dependency in other projects locally
  • deploy - done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

See for all details the source of the above text: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

28 questions
127
votes
7 answers

Maven: Lifecycle vs. Phase vs. Plugin vs. Goal

Relatively new developer here, even though I've been using it for a little while, I'm hoping to solidify my Maven fundamentals. Part of my problem is that I have no experience with Ant, which seems to be from where many explanations stem. I've been…
Jeff Levine
  • 2,083
  • 9
  • 30
  • 38
57
votes
2 answers

What is the difference between 'mvn verify' vs 'mvn test'?

I'm bit confused with mvn verify phase. I've created a Spring Boot project (a simple project, without any explicit configurations added). I've created a few JUnit unit tests which are run with both the mvn verify and mvn test commands. There isn't…
Vivek
  • 11,938
  • 19
  • 92
  • 127
18
votes
2 answers

How to skip maven phase pre-integration-test if skipITs is set?

I have some integration tests that depend on test data. This test data is created in phase pre-integration-test and removed in phase post-integration-test. My problem is that these phases are still executed if I use -DskipITs on the Maven…
17
votes
4 answers

Adding phases to the maven lifecycle?

I try to add some additional phases to the maven lifecycle. Mainly to add some additional test levels: initialize process-resources compile process-test-resources
wemu
  • 7,952
  • 4
  • 30
  • 59
16
votes
2 answers

Maven lifecycle within jenkins pipeline - how to best separate responsibilities?

When working with jenkins 2 (declarative) pipelines and maven I always have a problem with how to organize things within the pipeline to make it resusable and flexible. On the one side I would like to seperate the pipepline into logical stages…
PowerStat
  • 3,757
  • 8
  • 32
  • 57
11
votes
1 answer

Is it possible to resolve dependencies in maven plugin from p2 repo

I am developing one maven plugin which will be used to override the default maven lifecycles and will use my code instead. I have multiple jar dependencies (eclipse and my another application plugins) for the same. I have p2 repo for those jars. How…
Disha
  • 822
  • 1
  • 10
  • 39
4
votes
5 answers

How to skip the maven antrun copy/shade:shade goal dynamically?

I am using maven for configuration of an application consisting of multiple small services. Most of the services developed in java share the same maven configuration, as in the same build lifecycle, some shared resources (like spring AMQP). So I…
2
votes
1 answer

Where is the JAR packaging Maven lifecycle defined?

I'm creating a custom Maven packaging based on the lifecycle of the JAR packaging. I'd like to known where this lifecycle is defined (i.e. components.xml source code location).
Fernando Costa
  • 669
  • 1
  • 9
  • 31
2
votes
1 answer

Maven lifecycle understanding

I have a JavaEE, maven application. In this application I use classes generated from XSD, and mappers via Mapstruct. In my EJB module, the maven build should do the following: generate the java classes from XSD by jaxb2-maven-plugin add these…
victorio
  • 6,224
  • 24
  • 77
  • 113
2
votes
0 answers

How to create a custom lifecycle mapping to facilitate releases

I've been working with the release plugin, but am trying to automate its solution a little for our needs. At the moment, all our builds run the following command: mvn clean initialize release:prepare release:perform While that's functional, it's…
Eric B.
  • 23,425
  • 50
  • 169
  • 316
2
votes
1 answer

IntelliJ maven lifecycle - can I modify "Basic Tasks Only" list?

In the IntelliJ Maven Projects tree-view pane, you can see the Lifecycle tasks for all of the maven modules. By default, these show "Basic Tasks Only". I can untick this, but then I see everything..... Is it possible to add just one task…
vikingsteve
  • 38,481
  • 23
  • 112
  • 156
1
vote
0 answers

How to execute Maven plugins dynamically?

I am using maven-remote-resources-plugin, which retrieves the remote resources (such as css file) from another project to a specific directory in the current project. Since I am developing the css files, I would really like to see the changes in…
somenickname
  • 539
  • 7
  • 19
1
vote
1 answer

Phase name collisions in custom lifecycles in Maven?

AFAIK, you can create a custom build lifecycle in maven. Also, AFAIK, you cannot tell maven to execute a lifecycle. You can either: Tell maven to execute a phase: In this case, maven finds in which lifecycle this phase is, and then executes all…
Utku
  • 2,025
  • 22
  • 42
1
vote
0 answers

Skip recompile when test single Class with Maven

I was writing very long time test driven code with Ant. A while ago decided to give maven a try. Now I'm very comfortable with maven, in special with dependency management. But now I'm wondering if its possible to test a single class without…
AdemC
  • 406
  • 6
  • 16
1
vote
0 answers

How to create a custom Maven packaging type with custom plugin configurations

I have created a custom packaging type foo and foo has a LifecycleMapping where it calls several plugins. Is it possible to provide default or pom.xml for these plugins and phases? I want to add a default configuration for the…
Thomas Beauvais
  • 1,546
  • 2
  • 16
  • 30
1
2