BogoToBogo
  • Home
  • About
  • Big Data
  • Machine Learning
  • AngularJS
  • Python
  • C++
  • go
  • DevOps
  • Kubernetes
  • Algorithms
  • More...
    • Qt 5
    • Linux
    • FFmpeg
    • Matlab
    • Django 1.8
    • Ruby On Rails
    • HTML5 & CSS

Maven Life Cycle - 2021

Duke 512




Bookmark and Share





bogotobogo.com site search:


CD-CI-Tools.png

Maven Life Cycle

"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."

Apache Maven Project - Introduction

There are three built-in build lifecycles:

  1. default lifecycle handles project deployment.
  2. clean lifecycle handles project cleaning.
  3. site lifecycle handles the creation of project's site documentation.





Default lifecycle

The default lifecycle has the following build phases:


DefaultLifeCycle.png
  1. validate: validate the project is correct and all necessary information is available.
  2. compile: compile the source code of the project.
  3. test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
  4. package: take the compiled code and package it in its distributable format, such as a JAR.
  5. integration-test: process and deploy the package if necessary into an environment where integration tests can be run.
  6. verify: run any checks to verify the package is valid and meets quality criteria.
  7. install: install the package into the local repository, for use as a dependency in other projects locally.
  8. deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

These lifecycle phases (plus the other lifecycle phases not shown here) are executed sequentially to complete the default lifecycle.


Maven_LifeCycle_Table.png

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

$ mvn deploy

That is because if we call a build phase, it will execute not only that build phase, but also every build phase prior to the called build phase.






mvn clean install

The following command tells Maven to do the clean action in each module before running the install action for each module.

$ mvn clean install

In other words, mvn clean install clears any compiled files we have, making sure that we're really compiling each module from scratch.

Note that clean is in a separate lifecycle, so it's not called by default.

A target folder holds Maven-generated temporary files and artifacts. There are times when the target folder becomes huge or when certain files that have been cached need to be cleaned out of the folder. The clean goal accomplishes exactly that, as it attempts to delete the target folder and all its contents.





Maven goals vs phases

"Build processes generating artifacts typically require several steps and tasks to be completed successfully. Examples of such tasks include compiling source code, running a unit test, and packaging of artifacts. Maven uses the concept of goals to represent such granular tasks." - ref #2


Goalds-Phases-Table.png

Introduction to the Build Lifecycle



Goals in Maven are packaged in plug-ins, which are essentially a collection of one or more goals. For example, the compiler is the plug-in that provides the goal compile.

Some phases have goals bound to them by default. And for the default lifecycle, these bindings depend on the packaging value.

Goals are executed in phases which help determine the order goals get executed in.

This simplifies project dependency management greatly.

The default Maven lifecycle bindings show which goals get run in which phases by default. The compile phase goals will always be executed before the test phase goals which will always be executed before the package phase goals and so on.

A goal not bound to any build phase could be executed outside of the build lifecycle by direct invocation.

The order of execution depends on the order in which the goal(s) and the build phase(s) are invoked.

For example, consider the command below. The clean and package arguments are build phases, while the dependency:copy-dependencies is a goal (of a plugin).

$ mvn clean dependency:copy-dependencies package

If this were to be executed, the clean phase will be executed first (meaning it will run all preceeding phases of the clean lifecycle, plus the clean phase itself), and then the dependency:copy-dependencies goal, before finally executing the package phase (and all its preceeding build phases of the default lifecycle).









References
  1. Apache Maven Project - Built-in Lifecycle Bindings
  2. Introducing Maven










Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization

YouTubeMy YouTube channel

Sponsor Open Source development activities and free contents for everyone.

Thank you.

- K Hong







Java Tutorials



Java Tutorial Home

Basics - Compiling and Launching

Inner Classes

Constructor

Enums

Static & Finally

Default and Protected

Polymorphism

Exception Handling

Exception Handling II

String Class

Threads

Threads II - State Transition

Threads III - Synchronization

Object Class

File I/O

Serialization

ArrayList

Autoboxing

Java Graphics Interface I - Basics

Java Graphics Interface II - Labels, Text Fields, Layouts

Java Graphics Interface III - paintComponent

TCP Sockets Server/Client

Scala - Functional Java Programming

Apache CXF install

Tomcat 7 Ubuntu 14 Install on Amazon EC2 instance

What is Apache Maven?

Maven life cycle

Eclipse Maven 3 plugin on Ubuntu 14.04

Apache Maven 3 - Setting up and creating a project

Apache Maven 3 - Compile, build, and install a Maven project

Apache Maven 3 - Dependencies

Apache Maven 3 - Web Application

Apache Maven 3 - Plugins (compiler)

Apache Maven 3 - Plugins (Jetty)

Eclipse CDT / JNI (Java Native Interface) / MinGW



Spring Framework

Hello World App with Spring 4 & Maven 3 - Part I




Sponsor Open Source development activities and free contents for everyone.

Thank you.

- K Hong







Spring Boot



Spring Boot : Hello world with Mavan 3

Spring Boot : Hello world with Gradle 2

Spring Boot (Gradle 2) : Hello world with Authentication

Spring Boot : Deploying War file to Tomcat 8's webapps

How to Setup Apache as Reverse Proxy for Tomcat Server using mod proxy

Maven : mvn command cheat sheet

Spring-Boot REST API with CORS App Maven war file deploy to Tomcat

Spring-Boot / Spring Security with AngularJS - Part I (Introduction)

Spring-Boot / Spring Security with AngularJS - Part II (Dynamic resource load from Angular)

Spring-Boot / Spring Security with AngularJS : Part III (Form-based Authentication)





JUnit & Maven Tutorial



JUnit 4 Introduction (Hello World)

JUnit 4 Test with Eclipse Luna (Hello World)

JUnit 4 Test with Maven (Hello World)











Contact

BogoToBogo
contactus@bogotobogo.com

Follow Bogotobogo

About Us

contactus@bogotobogo.com

YouTubeMy YouTube channel
Pacific Ave, San Francisco, CA 94115

Pacific Ave, San Francisco, CA 94115

Copyright © 2024, bogotobogo
Design: Web Master