SlideShare a Scribd company logo
Apache Maven,
a software project management tool
@QuadraticBEJul. 2014
So it’s done...
I’m Renato Primavera from Quadratic
I write software that helps customers to manage and
make use of their geographical data
@RenatoPrimavera
renato.primavera@quadratic.be
www.quadratic.be
Maven can manage a project's
build, reporting and
documentation
from a central piece
of information: the “POM”
The concept of POM, for
Project Object Model
is the base of Maven
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
Here is a “POM”...
Maven makes the build process easy
> mvn clean
Deletes any build output (e.g. class files or JARs)
> mvn test
Runs the unit tests for the project
> mvn package
Build the project artifacts (e.g. JAR or WAR)
> mvn site
Creates project documentation (e.g. reports or Javadoc)
Maven provides a uniform build system
A project is always built using its
project object model (POM)
and a set of plugins that are shared by
all projects using Maven
Maven also provides guidelines for
best practices development
Keeping your test source code in a separate, but
parallel source tree
Using test case naming conventions to locate and
execute tests
Layout your project’s directory structure
(so that once you learn the layout, you can easily
navigate any other project that uses Maven and the
same defaults ! )
> Ok
> In practice now
Maven Installation
Prerequisite: Maven is a Java tool, so you must have
Java installed in order to use it. More precisely, you need a
JDK, the JRE is not sufficient
First...
Download Maven (tar.gz / zip)
http://maven.apache.org/download.cgi
Then…
Unzip the distribution archive to the
directory you wish to install Maven
Add the M2_HOME environment variable,
pointing to that directory
Append the value $M2_HOME/bin to the
PATH environment variable
#1
#2
#3
Make sure that JAVA_HOME exists as environment
variable and it is set to the location of your JDK
[Optional] add the MAVEN_OPTS environment
variable to specify JVM properties, e.g. the value
-Xms256m -Xmx512m. This can be used to supply
extra options to Maven
Open a command prompt and run mvn --version
to verify that it is correctly installed
#4
#5
#6
Maven is now installed. It’s quite simple, isn’t it?
Let’s create a project
> mvn archetype:generate
-DgroupId=com.mycompany.app
-DartifactId=my-app
-DarchetypeArtifactId=maven-archetype-quickstart
-DinteractiveMode=false
What has been generated?
(the project structure)
The POM file
The sources tree
The tests sources tree
What the POM file looks like...
What did you just do?
You executed the Maven goal “archetype:
generate”, and passed in various parameters to
that goal
The prefix “archetype” is the plugin that
contains the goal
The “generate” goal of the “archetype”
plugin created a simple project based upon
an archetype
Suffice it to say for now that a plugin is a collection of goals
with a general common purpose (e.g. the “release” plugin
provides goals that allow to release projects - updating the
POM and tagging in the SCM)
We can now Build that project
(and so generate a JAR artifact…)
> mvn package
...
[INFO]
------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Thu Jul 07 21:34:52 CEST 2011
[INFO] Final Memory: 3M/6M
[INFO]
------------------------------------------------------------------------
The command line will print out various actions, and end with the following:
Unlike the first command executed
(archetype:generate) you may notice the
second is simply a single word - “package”
Rather than a goal, this is a phase
A phase is a step in the build lifecycle
(which is an ordered sequence of phases)
When a phase is given, Maven will
execute every phase in the sequence
up to and including the one defined
For example, if we execute the compile phase,
the phases that actually get executed are:
- validate
- generate-sources
- process-sources
- generate-resources
- process-resources
- compile
These are the most common default
lifecycle phases executed
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
There are two other really useful
Maven lifecycles phases
clean: cleans up artifacts created by prior
builds
site: generates site documentation for this
project
You said… Repository ?
Sir, yes Sir
A repository in Maven is used
to hold build artifacts and
dependencies of varying types
There are strictly only two types of
repositories: local and remote
The local repository refers to a copy on your own
installation that is a cache of the remote
downloads, and also contains the temporary build
artifacts that you have not yet released
Local repository is
on your machine
It’s yours...
Remote repositories refer to any other
type of repository, accessed by a variety of
protocols such as file:// and http://
Such repository might be a truly remote
repository set up by a third party to provide their
artifacts for downloading
Other "remote" repositories may be
internal repositories set up on a file or
HTTP server within your company
These are used to share private artifacts
between development teams and for releases
mvn install: installs the package
into the local repository
(for use as a dependency in other
projects locally)
Reminder
mvn deploy: deploys the final package to the
remote repository ,i.e. the corporate one
(for sharing with other developers and projects)
Before deploying any artifact
to a remote repository, you must
configure that repo !
Using the distributionManagement
section in your POM
or using the repositories
section in your settings.xml file
<distributionManagement>
<!-- use the following if you're not using a snapshot version. -->
<repository>
<id>repo</id>
<name>Repository Name</name>
<url>scp://host/path/to/repo</url>
</repository>
<!-- use the following if you ARE using a snapshot version. -->
<snapshotRepository>
<id>repo</id>
<name>Repository Name</name>
<url>scp://host/path/to/repo</url>
</snapshotRepository>
</distributionManagement>
in thePOM
More about...
POM
The POM contains all necessary
information about a project, as well as
configurations of plugins to be used
during the build process
It is, effectively, the declarative manifestation of
the “who”, “what” and “where” of your project
(while the build lifecycle is the “when” and “how”)
The Super POM is
Maven's default POM
All POMs extend the Super POM unless explicitly
set, meaning the configuration specified in the
Super POM is inherited by the POMs you created
for your projects
By default, the build directory is “target”
By default, the source directory is “src/main/java”
By default, the test source directory is “src/main/test”
and so on...
Examples for this
Super POM brings also the
basic plugins...
maven-compiler-plugin
maven-dependency-plugin
maven-deploy-plugin
maven-jar-plugin
maven-javadoc-plugin
...
One powerful aspect of Maven
is in its handling of
project relationships
That includes dependencies
(and transitive dependencies),
inheritance, and aggregation (multi-
module projects)
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.0</version>
<type>jar</type>
<scope>test</scope>
<optional>true</optional>
</dependency>
...
</dependencies>
in thePOM
The cornerstone of the POM is its
dependency list
Maven downloads and links
the dependencies for you
on compilation and other
goals that require them
As an added bonus, Maven brings in the
dependencies of those dependencies
(transitive dependencies), allowing your list
to focus solely on the dependencies your
project requires
One powerful addition that Maven
brings to build management is
the concept of
project
inheritance
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.mojo</groupId>
<artifactId>my-parent</artifactId>
<version>2.0</version>
<packaging>pom</packaging>
</project>
The packaging type required to be “pom”
for parent and aggregation
(multi-module) projects
<project xmlns="http://maven.apache.org/POM/4.0.0" ...>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.codehaus.mojo</groupId>
<artifactId>my-parent</artifactId>
<version>2.0</version>
<relativePath>../my-parent</relativePath>
</parent>
<artifactId>my-project</artifactId>
</project>
Parent POM still has to be referenced by
children
Default value, if omitted, is
“../pom.xml”
Useless if parent has
already been installed
Once defined, we may add
values to this parent POM,
which will be inherited by
its children
For instance, sections like
dependencyManagement (or
pluginManagement) can be defined
in the parent POM
Dependency management allows to directly specify the
versions of artifacts to be used when they are
encountered in transitive dependencies or in dependencies
of children POM and where no version has been specified
In another words, the dependency
management section is a mechanism
for centralizing dependency
information
When you have a set of projects that inherits a common
parent it's possible to put all information about the
dependency in the common POM and have simpler
references to the artifacts in the child POMs
<project>
...
<dependencyManagement>
<dependency>
<groupId>my.groupid</groupId>
<artifactId>my-artifact</artifactId>
<version>1.0</version>
<scope>runtime</scope>
</dependency>
</dependencyManagement>
</project>
In Parent POM
<project>
...
<dependencies>
<dependency>
<groupId>another.groupid</groupId>
<artifactId>another-artifact</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>my.groupid</groupId>
<artifactId>my-artifact</artifactId>
</dependency>
</dependencies>
</project>
In Children POM
A project with modules is known as
a multimodule, or aggregator
project
Modules are projects that this POM
lists, and are executed as a group
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.mojo</groupId>
<artifactId>my-parent</artifactId>
<version>2.0</version>
<packaging>pom</packaging>
<modules>
<module>my-project</module>
<module>another-project</module>
</modules>
</project>
An pom packaged project may
aggregate the build of a set of
projects by listing them as
modules, which are relative
directories to those projects
Sources
http://maven.apache.org/
http://en.wikipedia.org/wiki/Apache_Maven
Thanks

More Related Content

What's hot

Get the Most out of Testing with Spring 4.2
Get the Most out of Testing with Spring 4.2Get the Most out of Testing with Spring 4.2
Get the Most out of Testing with Spring 4.2
Sam Brannen
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
Mike Desjardins
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
MD Sayem Ahmed
 
Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylight
OpenDaylight
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 features
Angel Ruiz
 
PHP Unit Testing in Yii
PHP Unit Testing in YiiPHP Unit Testing in Yii
PHP Unit Testing in Yii
IlPeach
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
Smita Prasad
 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
Joao Pereira
 
Java Builds with Maven and Ant
Java Builds with Maven and AntJava Builds with Maven and Ant
Java Builds with Maven and Ant
David Noble
 
JUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyondJUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyond
Sam Brannen
 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersSelenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And Answers
Ajit Jadhav
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
James Cellini
 
Testing Web Apps with Spring Framework
Testing Web Apps with Spring FrameworkTesting Web Apps with Spring Framework
Testing Web Apps with Spring Framework
Dmytro Chyzhykov
 
JUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVMJUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVM
Sam Brannen
 
Open Source Software Testing Tools
Open Source Software Testing ToolsOpen Source Software Testing Tools
Open Source Software Testing Tools
Varuna Harshana
 
Introduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS worldIntroduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS world
Dmitry Bakaleinik
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
Sid Anand
 
Infinum Android Talks #17 - Testing your Android applications by Ivan Kust
Infinum Android Talks #17 - Testing your Android applications by Ivan KustInfinum Android Talks #17 - Testing your Android applications by Ivan Kust
Infinum Android Talks #17 - Testing your Android applications by Ivan Kust
Infinum
 

What's hot (20)

Get the Most out of Testing with Spring 4.2
Get the Most out of Testing with Spring 4.2Get the Most out of Testing with Spring 4.2
Get the Most out of Testing with Spring 4.2
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
 
Maven Overview
Maven OverviewMaven Overview
Maven Overview
 
Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylight
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 features
 
Codeception
CodeceptionCodeception
Codeception
 
PHP Unit Testing in Yii
PHP Unit Testing in YiiPHP Unit Testing in Yii
PHP Unit Testing in Yii
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
 
Java Builds with Maven and Ant
Java Builds with Maven and AntJava Builds with Maven and Ant
Java Builds with Maven and Ant
 
JUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyondJUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyond
 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersSelenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And Answers
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Testing Web Apps with Spring Framework
Testing Web Apps with Spring FrameworkTesting Web Apps with Spring Framework
Testing Web Apps with Spring Framework
 
JUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVMJUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVM
 
Open Source Software Testing Tools
Open Source Software Testing ToolsOpen Source Software Testing Tools
Open Source Software Testing Tools
 
Introduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS worldIntroduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS world
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
 
Infinum Android Talks #17 - Testing your Android applications by Ivan Kust
Infinum Android Talks #17 - Testing your Android applications by Ivan KustInfinum Android Talks #17 - Testing your Android applications by Ivan Kust
Infinum Android Talks #17 - Testing your Android applications by Ivan Kust
 

Viewers also liked

Spring Core
Spring CoreSpring Core
Spring Core
Pushan Bhattacharya
 
Maven
Maven Maven
Maven
Khan625
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbt
Fabio Fumarola
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
Sandeep Chawla
 
An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to MavenVadym Lotar
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
NexThoughts Technologies
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
Dzmitry Naskou
 
Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)
Robert Scholte
 

Viewers also liked (9)

Spring Core
Spring CoreSpring Core
Spring Core
 
Maven
Maven Maven
Maven
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbt
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to Maven
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)
 

Similar to Apache maven, a software project management tool

Maven
MavenMaven
Maven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolMaven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolelliando dias
 
A-Z_Maven.pdf
A-Z_Maven.pdfA-Z_Maven.pdf
A-Z_Maven.pdf
Mithilesh Singh
 
Maven
MavenMaven
Maven
Emprovise
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
Mert Çalışkan
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
Onkar Deshpande
 
Mavennotes.pdf
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
AnkurSingh656748
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
Priyank
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with FlexPriyank
 
Maven
MavenMaven
Maven
MavenMaven
Maven
MavenMaven
Maven
Shraddha
 
Maven in mulesoft
Maven in mulesoftMaven in mulesoft
Maven in mulesoft
venkata20k
 
Introduction to maven
Introduction to mavenIntroduction to maven
Introduction to maven
Manos Georgopoulos
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
Mert Çalışkan
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topic
Gourav Varma
 
Build Automation using Maven
Build Automation using Maven Build Automation using Maven
Build Automation using Maven
Ankit Gubrani
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
Raghavan Mohan
 

Similar to Apache maven, a software project management tool (20)

Maven
MavenMaven
Maven
 
Maven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolMaven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension tool
 
Exploring Maven SVN GIT
Exploring Maven SVN GITExploring Maven SVN GIT
Exploring Maven SVN GIT
 
A-Z_Maven.pdf
A-Z_Maven.pdfA-Z_Maven.pdf
A-Z_Maven.pdf
 
Maven
MavenMaven
Maven
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Mavennotes.pdf
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Maven in mulesoft
Maven in mulesoftMaven in mulesoft
Maven in mulesoft
 
Introduction to maven
Introduction to mavenIntroduction to maven
Introduction to maven
 
P&MSP2012 - Maven
P&MSP2012 - MavenP&MSP2012 - Maven
P&MSP2012 - Maven
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topic
 
Build Automation using Maven
Build Automation using Maven Build Automation using Maven
Build Automation using Maven
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
 

Apache maven, a software project management tool