1. Apache Maven 2 Overview
Part 2
Advanced Topics of Apache Maven 2
Anatoly Kondratyev
September 2012
30 January 2013
Exigen Services confidential Exigen Services confidential
2. The Goal
• Understand several Maven capabilities
• Build multi-module project with Maven
• Some special pom blocks
• Nexus configuration notes
Exigen Services confidential 2
3. Maven in real world
WORKING WITH MULTI-MODULE
PROJECTS
Exigen Services confidential 3
4. Project contents
GWT
application
EJB A EJB B
My Library
Exigen Services confidential 4
5. What to do with Maven?
• 4 independent artifacts with dependencies
• Build in one step?
• Organize versioning?
• Keeping up to date?
• Wrong!
• Maven Inheritance and Aggregation
• Solves the above problems
• Right!
Exigen Services confidential 5
6. Maven Inheritance & Aggregation
• <packaging>pom</packaging>
• Super pom
• Data in parent pom is inherited
• Maven dependency reactor
• Notes
• No cyclic dependencies
• No same modules
Exigen Services confidential 6
7. Maven Inheritance & Aggregation
Parent
pom
EJB A EJB B Gwt My library
ejb ejb war jar
Exigen Services confidential 7
9. Maven in action
• What about deployment?
• EAR needed
• Special step needed
• Maybe divide frontend and backend?
• NB! One pom – one artifact
Exigen Services confidential 9
10. Maven in action
Parent
pom
Frontend Backend
pom pom
Frontend Backend
Gwt EJB A EJB B My library
wrapper wrapper jar
war ear ejb ejb ear
Exigen Services confidential 10
15. Maven reactor
• Collects all the available modules to build
• Sorts the projects into the correct build order
• a project dependency on another module in the build
• different rules with plugins dependencies
• the order declared in the <modules> element (if no other rule
applies)
• Builds the selected projects in order
• Be aware of cycles and same modules on different
parents
Exigen Services confidential 16
16. Conclusion
• Inheritance and aggregation
• Flat/Tree structure
• Maven reactor
• Dependency&Plugin management
• Deploy to Nexus/Weblogic problem
Exigen Services confidential 17
17. What will help you
PROPERTIES, PROFILES,
EXECUTION BLOCKS
Exigen Services confidential 18
18. Maven properties
• Just as common Ant properties
• ${property_name}
• Case sensitive
• Upper case for environment variables
• Dot(.) notated path
Exigen Services confidential 19
19. Predefined properties
• Build in properties
• ${basedir} – directory with pom
• ${version} – artifact version
• Project properties
• ${project.build.directory}
• ${project.build.outputDirectory} (target/classes)
• ${project.name}
• ${project.version}
• Local user settings
• ${settings.localRepository}
• Environment properties
• ${env.M2_HOME}
Exigen Services confidential 20
20. Maven profiles
• Maven profile – special way for configuring
build
• Different environments – different results
• Renaming
• Different build cycles
• Special plugin configuration
• Just different targets
• For different users
Exigen Services confidential 22
21. Maven profiles
• Per project
• pom.xml
• Per user
• %USER_HOME%/.m2/settings.xml
• Per computer (Global)
• %M2_HOME%/conf/settings.xml
Exigen Services confidential 23
22. Maven profiles
• Activation
• By hand (-P profile1,profile2)
• <activeProfiles>
• <activation>
• By environment settings
• By properties
Exigen Services confidential 24
24. Mojo
• Plugin
• Executing action
• Mojo – magical charm in hoodoo
• Just a Goal
• Plugin consists of Mojos
• Some parameters
• MOJO aka POJO (Plain-old-Java-object)
Exigen Services confidential 27
25. Mojo
• When we should use mojos?
• Run from command line
• Different execution parameters for different
configurations
• Group of mojos from same plugin with
different configuration
Exigen Services confidential 28