Maven is a build automation tool used primarily for Java projects that utilizes a project object model (POM) to manage dependencies and build processes. It was created in 2001 to standardize builds of Apache projects. Some key features include dependency management, a standard project layout, configurable build lifecycles and phases, and plugins for tasks like compiling, testing, packaging, and reporting. Maven aims to provide a uniform build system and is not intended to replace build tools like Ant.
2. Apache Maven history
• Started by Jason Van Zyl in 2001
o Standardising the build of Apache Turbine
• Version history
o 1.0 in Jul-2004, after loads of betas
o 2.0 in Oct-2005, completely redesigned
o 3.0 in Oct-2010, fully compatible
o 3.5.0 is the latest, released Apr-2017
• Previsouly somewhat controlled by Sonatype
• Strong and stable!
5. Maven plugins
• Written in Java (MOJO), or ...
• Entry-points are called goals
• Examples:
o Core
maven-compiler-plugin
maven-resources-plugin - including filtering
maven-surefire-plugin - executes tests
o Reporting
maven-javadoc-plugin
maven-findbugs-plugin
o Code Generation
antlr3-maven-plugin
o maven-alfresco-plugin !!
o .......
9. Maven conventions
• tree layout
o pom.xml
o src
main
• java
• resources
test
• java
• resources
o target
• tests are executed as part of the build
Follow the Maven way!
10. Maven dependency
A dependency (internal or external) is made of:
• mandatory : GAV
o groupId (org.alfresco)
o artifactId (alfresco-datamodel)
o version
release: 4.1.0
snapshot: 4.1.0-SNAPSHOT
• optionally:
o scope (compile, test, provided, ...)
o classifier (jdk6, sources, javadocs, ...)
Dependencies are transitive!
• mvn dependency:tree dependency:list
12. Maven dependency management
mvnmvn install
Team Repo
Maven Central
http://repo.maven.apache.org/maven2/
local Maven repo
~/.m2/repository
13. Invoking Maven
• call a phase
o mvn clean install
o mvn test
• call a goal
o mvn surefire:test
o mvn javadoc:javadoc
• Useful switches
o -o : offline
o -U : force check for snapshot updates
o -X : verbose, to check plugin configuration
• Adding command-line params for plugins
o -DskipTests
o -Dtest=MyClassTest
14. Multimodule builds
• call sub-projects in parent folder
<packaging>pom</packaging>
<modules>
<module>core</module>
<module>web-client</module>
</modules>
• pom inheritance in sub-projects
<parent>
<groupId>...
<artifactId>...
<version>...
</parent>
• Computing the actual pom
mvn help:effective-pom
15. Maven profiles
• conditional parts in the pom.xml
o plug/unplug a submodule
o run a different set of tests
o test various platforms
o ...
• Triggering a profile
o command line: -Pprofile1,!profile3
o presence/absence of a property
o automatic: JDK, OS, platform, existence of a file, …
16. IDE integration
• "Old school": Maven generating IDE project
o mvn eclipse:eclipse [-DdownloadSources=true]
o mvn idea:idea
o mvn netbeans:netbeans
• Recommended: IDE directly reading pom.xml
o m2e plugin, included in "Eclipse IDE for Java Devs"
19. Want some more?
• Maven books from Sonatype
https://www.sonatype.com/ebooks
• pom.xml reference
• Maven Plugins reference
o Apache
o Codehaus
Editor's Notes
"convention over configuration" guarantees success!
First thing that maven downloads is itself! plugins, etc. ("Maven downloads the internet")
Adding a Maven repo for the team to
proxy central
share internal artifacts between team members
share releases with outsiders (until we're on central...)