3. Maven Defined
• Maven is a software project management
and comprehension tool.
• Based on the concept of a project object
model (POM), Maven can manage a
project's build, reporting and documentation
from a central piece of information.
4. Why Maven?
Web Site Reporting
Documentation Dependencies
Tests JAR WAR
Continuous Integration Resources
Integration Tests Deployment
Conditional Builds
5. Maven “versus” Ant?
Maven
Create Artifacts
(e.g. JARs, WARs, EARs, etc...)
Ant
General Purpose Tooling
6. Maven = Convention
over Configuration
• Directories
• Source, Tests, Resources
• Goals
• Clean, Test, Install, Package, Deploy, Site...
• But... you have to learn the conventions!
• Maven’s learning curve in a nutshell
7. Back to Basics
• Let’s create a JAR
• Let’s create a WAR
• Let’s link the two!
8. Goals and Plugins
Goal = One Word Target
e.g. clean, test, compile, deploy
Plugin = Two Word Action
e.g. compile:compile, jar:test-jar, jetty:run
9. Ok...
• Built-in super pom.xml (in Maven install)
• Local settings.xml
• Project pom.xml (with packaging)
• Type a goal, and the lifecycle runs the
bound plugins
11. Repositories
• Local Internet
• ~/.m2/repository (ibiblio)
• Remote Artifactory
• Servers that hold released
binaries Local
(file system)
• e.g. Artifactory, Nexus
13. Deployment
• Single Command To Deploy
• Pushes artifact to server
• (Almost) Single Command To Release
• Housekeeping + deployment
mvn --batch-mode release:prepare release:perform
15. All Star Directories
Example
• Most complex project (business-logic)
• Conditional builds (data-migration, integration tests)
• ~20 compile, ~15 test dependencies = apx 75 resolved dependencies
• Automatic releases via Hudson, including JAR, Test JAR, attached sources,
MD5 hashes
• Build stamps SVN version # in manifest
• Database wipe and reset, including DbUnit Fixture generation as part of
clean - with data extracted from a dependency JAR
• Site documentation (auto-gen) includes Cobertura code coverage,
CheckStyle, PMD, FindBugs, full schema info for ~160 tables (including
diagrams), Javadoc (with autogen UML class diagrams)
• How many lines of XML?
786 lines (including comments)