Agenda
Automation Build Tool
A bit of history
Why Maven?
An Introduction to Maven
Drawbacks of Maven
Best practices
Maven in software development suite
Examples
Q&A
Automation Build Tool
Since the early days of modern
engineering, automation of build
processes has been the key to:
Productivity improvements
Quality insurance
Eliminate dependencies on key
personnel
Save time and money
Why would software development
be any different?
Automation Build Tool
How do you really enable automation of
build?
Build has to be reproducible
Build has to produce the final production artifact
Build has to be as easy to maintain as possible
and well documented
Agenda
Automation Build Tool
A bit of history
Why Maven?
An Introduction to Maven
Drawbacks of Maven
Best practices
Maven in software development suite
Examples
Q&A
A bit of history
A simple script (.sh, .bat) is already a possible
solution
More advanced command-line tools have been
available for a long time
make created in 1977 at Bells Labs by Stuart
Feldman. Still very much used nowadays
Apache Ant created by James Duncan Davidson
A bit of history
Two main categories in current tools:
Scripting tools
Ant
Rake (Ruby based)
Gradle (Groovy based)
… many others
Artifact oriented tools
Maven
Debian Package Creation
A bit of history
Maven 1.x is now almost 12 years old
project, mostly motionless since 2007 (I cannot
find anybody still using it or committing to it)
Maven 2.x was the de facto standard for Java and
Java EE build
Most open source projects were switched to
Maven for their build system
It’s now seven years old
Maven 3.x is used in > 90% of Java (EE) startup
applications.
It’s now two years old
Last release – ver. 3.0.3
Agenda
Automation Build Tool
A bit of history
Why Maven?
An Introduction to Maven
Drawbacks of Maven
Best practices
Maven in software development suite
Examples
Q&A
Why Maven?
If you are not already using it:
Now is the best moment to start being aware
Maven is mature
Maven is getting better and better
Maven can be used online and offline
If you are already using it:
Hang on! The best is yet to come!
Focus on necessary things and don’t get
frustrated by petty details
Agenda
Automation Build Tool
A bit of history
Why Maven?
An Introduction to Maven
Drawbacks of Maven
Best practices
Maven in software development suite
Examples
Q&A
An Introduction to Maven
Maven is a tool with multiple facets:
a BUILD tool
a DEPENDENCY MANAGEMENT tool
a DOCUMENTATION tool
An Introduction to Maven
Project Object Model
pom.xml
Maven’s working …
Generated artifacts (jar, war, ear…),
Documentation, statistics (test
results, quality metrics, javadoc, web
site)…
An Introduction to Maven
A project can easily be cut into modules
thanks to Maven
By simply declaring project metadata and
optionally configuring a few plug-ins, you can:
Build your project (compile, generate
sources…)
Launch tests and gather results
(Junit, TestNG, Selenium…etc)
Package (Jar, War, Ejb, War…etc)
Document and generate reports
An Introduction to Maven
Project Object Model (POM)
Basic project information
groupId, artifactId, version…
Inheritance, or Aggregation through sub-modules
(will explain the difference later on)
Build section
Project layout (sources and resources folders… etc)
Build plugins configuration
Reporting section
Reports configuration
Some other advanced environment settings
An Introduction to Maven
A plug-in is made of a MOJO (Maven POJO)
which is simply a java class with Maven-
specific metadata.
A plug-in can define goals and reports
Goals can be called directly:
mvn plugin:goal
Goals can be bound to one or multiple phases
Reports are used during site generation
mvn site
An Introduction to Maven
When you invoke a phase, Maven will go
through all the phases until the one
specified, executing the bound goals:
mvn package
An Introduction to Maven
There are many more phases than in
previous examples in the default lifecycle
By default, all the basic necessary plug-ins
for the build phase are already bound to
phases
It is easy to have information about plugins:
mvn help:describe
So….. what’s left to do, and what’s all the
fuss about the complexity of Maven?
An Introduction to Maven
Dependencies: A blessing and a curse
Blessing:
Transitive dependencies
easier to find/discover/use java libraries
Curse:
Transitive dependencies can rapidly trigger
a dependency hell!
Harder to stabilize builds
An Introduction to Maven
What really made Maven different from other
builds systems in the first place?
REPOSITORIES!!!
Before Maven, it was really hard to find java
libraries, and harder to ensure a coherent use
of these libraries
Nowadays, it’s still very hard to find some jars
with a decent/coherent versioning, let alone to
find their sources or javadocs
An Introduction to Maven
Local repository:
Local cache for artifacts
Contain temporary build artifacts
It’s possible to erase it regularly
Very useful for offline builds
By default in user home’s .m2/repository folder
Can be moved to another place through
Maven runtime’ settings.xml file
$MAVEN_HOME/conf/settings.xml
An Introduction to Maven
Corporate repository/proxy
Access via file:// and http://
The first necessary step towards a corporate use of
maven
The local and remote repositories are structured
the same
Even better: install a repository management tool
Can proxy external repositories
Can filter unwanted artifacts
An Introduction to Maven
Public repositories
Good for dependencies’ harvesting
A lot of mis-configured dependencies
A lot of alpha/beta Maven plugins and
libraries
Be cautious when adding public repositories to
a build process!
Should be proxied in corporate
An Introduction to Maven
Other key features of Maven:
POM Inheritance/Aggregation
Archetypes
Launching Tests
… many more…
An Introduction to Maven
POM – Project Object Model
Super POM
Inheritance
Aggregation
Inheritance vs Aggregation
An Introduction to Maven
Project Archetypes
You can build template projects and make them
available as artifacts in the repositories
mvn archetype:create-from-project
Allows to share best practices without neither
inheritance nor aggregation
mvn archetype:generate
Many Archetypes already configured in the default
catalog
You can easily build a custom or corporate catalog
mvn archetype:generate
–DarchetypeCatalog=http://www.corporate.com/archetypes.xml
An Introduction to Maven
Archetype ArtifactIds Description
maven-archetype-archetype An archetype which contains a sample
archetype.
maven-archetype-j2ee-simple An archetype which contains a simplifed sample
J2EE application.
maven-archetype-mojo An archetype which contains a sample a sample
Maven plugin.
maven-archetype-plugin An archetype which contains a sample Maven
plugin.
maven-archetype-plugin-site An archetype which contains a sample Maven
plugin site.
maven-archetype-portlet An archetype which contains a sample JSR-268
Portlet.
maven-archetype-quickstart An archetype which contains a sample Maven
project.
maven-archetype-simple An archetype which contains a simple Maven
project.
maven-archetype-site An archetype which contains a sample Maven
site which demonstrates some of the supported
document types like APT, XDoc, and FML and
demonstrates how to i18n your site.
maven-archetype-site-simple An archetype which contains a sample Maven
site.
maven-archetype-webapp An archetype which contains a sample Maven
Webapp project.
An Introduction to Maven
Launching Tests
Maven allows to launch various types of tests:
Unit tests: Junit 3.x or 4.x, TestNG, …
UI Tests: Selenium, Canoo Webtest
Functional tests: Fitnesse, Greenpepper
WebServices tests: SOAPUi
And many more…
Agenda
Automation Build Tool
A bit of history
Why Maven?
An Introduction to Maven
Drawbacks of Maven
Best practices
Maven in software development suite
Examples
Q&A
Drawbacks of Maven
Library repositories are not always safe.
Maven Conventions
Hard to find some things about maven and
plugins
A huge output log
Sequential build (Lyfecycle)
Learning Maven is long in comparison of Ant.
Agenda
Automation Build Tool
A bit of history
Why Maven?
An Introduction to Maven
Drawbacks of Maven
Best practices
Maven in software development suite
Examples
Q&A
Best practices
Embrace the standardization brought by Maven, don’t
fight it
Use POM Inheritance and <dependencyManagement>
(with import scope), <pluginManagement>
Use a Repository Manager:
Sonatype Nexus: http://nexus.sonatype.org
Jfrog Artifactory: http://artifactory.jfrog.org
…
Best practices
Keep your build as simple as possible
Launch your builds regularly and possibly in a neutral
zone
Use the “dependency” and “versions” plugins
Generate test statistics data and other metrics data in
order to exploit them in Software quality tools:
Sonar: http://sonar.codehaus.org
Squale: http://www.squale.org
…
Agenda
Automation Build Tool
A bit of history
Why Maven?
An Introduction to Maven
Drawbacks of Maven
Best practices
Maven in software development suite
Examples
Q&A
Maven in a Software development
suite
Maven is now very well integrated in IDEs
NetBeans 6.5+ now has very good support for
Maven
Eclipse 3.x has very good support also.
IntelliJ IDEA seems to have excellent support
also (though this is why you pay for it isn’t it?)
Maven works very well with Quality
monitoring tools
Continuous integration
References and Thanks
Documentation and information:
Site http://maven.apache.org
Plugins
http://maven.apache.org/plugins
http://mojo.codehaus.org/
http://code.google.com/
And many others…
Project Wiki
http://docs.codehaus.org/display/MAVEN/
Users’ Wiki
http://docs.codehaus.org/display/MAVENUSER
References and Thanks
Books
Free electronic editions:
Definitive Guide: http://www.sonatype.com/books
Better Builds with Maven:
http://www.maestrodev.com/better-build-maven
Upcoming book by Arnaud Héritier and Nicolas De Loof
http://www.pearson.fr/livre/?GCOI=27440100730370
Thanks
Many thanks to Pierre-Antoine Grégoire for its
presentation on YaJUG
Thanks to Jason van Zyl for its Maven 3 presentation
http://www.sonatype.com/people/author/jason