What is the default lifecycle in Maven

2.3k Views Asked by At

I am trying to learn maven, and going through below statement from Maven docs

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 site documentation.

and also another statement that says:

default (or build):This is used to build the application.

I was able to run the commands mvn clean & mvn site successfully. But when I run the below commands then I am getting exceptions:

Commands:

mvn default & mvn build

Error details:

[WARNING] 
[WARNING] Some problems were encountered while building the effective model for org.hibernate.tutorials:hibernate-tutorial:jar:1.0.0-SNAPSHOT
[WARNING] The expression ${artifactId} is deprecated. Please use ${project.artifactId} instead.
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 

[ERROR] Unknown lifecycle phase "build". 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>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-site, site, post-site, site-deploy, pre-clean, clean, post-clean. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException
3

There are 3 best solutions below

5
On BEST ANSWER

You haven't read it all :

To do all those, you only need to call the last build phase to be executed, in this case, deploy:

mvn deploy

In fact the default lifecycle contains the phases (in that order) :

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.
integration-test - process and deploy the package if necessary into an environment where integration tests can be run
verify - run any checks to verify the package is valid and meets quality criteria
install - install the package into the local repository, for use as a dependency in other projects locally
deploy - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

And you need to specify to the command line the last step you want to execute and it will execute all the step that come before this one and this one. For exemple, if you do :

mvn install

It will execute : validate, compile, test, package, integration-test, verify and install (and some other phases, see complete list).

1
On

For the first warning - check your pom to see if you are using the expression ${artifactId}, its deprecated and should instead be ${project.artifactId}

For the error - build is not a maven lifecycle phase. You need do a mvn clean install to build your project. These are basic maven features and very well documented

2
On

Recommend you to go through this tutorial which will get you started (and more) with maven.

http://www.tutorialspoint.com/maven/maven_build_life_cycle.htm

From the same link -

A typical Maven Build Lifecycle consists of following sequence of phases:

  1. prepare-resources : Resource copying can be customized in this phase.
  2. compile : Source code compilation is done in this phase.
  3. package : This phase creates the JAR / WAR package as mentioned in packaging in POM.xml.
  4. install : This phase installs the package in local / remote maven repository.