Maven DP
Maven DP
Maven DP
TO
MAVEN
DURGA ADIMULAM
September 8,
September 8, 2020
2020
PURPOSE OF THE SESSION
The purpose of this Maven session is to make you understand how Maven
works. Therefore this tutorial focuses on the core concepts of Maven.
Once you understand the core concepts, it is much easier to lookup detailed
information in the Maven documentation, or search for it on the internet.
Common Problems and Activities
• Multiple Jars
• Dependencies and Versions
• Project Structure
• Building, Publishing and deploying
WHAT IS MAVEN?
• Default lifecycle
generate-sources/generate-resources
Compile
Test
Package
Install
Deploy
• Clean lifecycle
• Site lifecycle
Maven Build Lifecycle Phases
• 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.
Maven Archetype
• When executing a task or goal, Maven looks for the POM in the current
directory. It reads the POM, gets the needed configuration information,
then executes the goal.
POM.xml
Minimal POM
The minimum requirement for a POM are the following:
• project root
• modelVersion - should be set to 4.0.0
• groupId - the id of the project's group.
• artifactId - the id of the artifact (project)
• version - the version of the artifact under the specified group
How Maven uses POM.xml
Example Maven Goals
• mvn install
- Invokes generate* and compile, test, package, integration-test, install
• mvn clean
- Invokes just clean
• mvn clean compile
- Cleans old builds and execute generate* and compile
• mvn compile install
- Invokes generate*, compile, test, integration-test, package, install
• mvn test clean
- Invokes generate*, compile, test then cleans the build
DEMO of Maven
• Installation
• Setting environment variable – M2_HOME
• Setting PATH variable
• Creating the Project using Maven
• Compiling the source code using Maven
• Packaging the source code using Maven
• Running the sample code
Home Task
• Create a sample maven project from command prompt with quick start
archetype
• Also use Maven life cycle to execute and verify the files/folders generated.
Resources
• https://maven.apache.org/
• https://maven.apache.org/maven-features.html
• https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
Q&A
THANK YOU
DURGA ADIMULAM