2. Maven... What is it?
Dependency Management
Plugin-ins
POM
Lifecycles
Inheritance
3. Maven... What is it?
"build tool"
• Generates deployable artifacts from the source code.
• Preprocessing, compilation, packaging, testing and
distribution.
"project management tool"
• GeneratesWeb Site (Project Documentation)
• Run Reports
4. Convention over Configuration
Systems should "just work“.
o Pre-defined directory structures
• Source
•Tests
• Documentation
o Based on goals
• compile, test, package, install, deploy, site…
o Just learn the conventions!
o Archetype plugin for easy project creation
• mvn archetype:generate
6. POM (Project Object Model)
o Fundamental unit of work in Maven
o Maven projects, dependencies, builds, artifacts: all of these are objects to be modeled
and described.These objects are described by an XML file called a Project Object Model
(POM).
Reference: pom.xml
7. POM – Important Attributes
project It is the root element of pom.xml file.
modelVersion It is the sub element of project. It specifies the modelVersion. It
should be set to 4.0.0.
groupId * It is the sub element of project. It specifies the id for the project
group.
artifactId * It is the sub element of project. It specifies the id for the artifact
(project). An artifact is something that is either produced or used
by a project. Examples of artifacts produced by Maven for a
project include: JARs, source and binary distributions, and WARs.
Version * It is the sub element of project. It specifies the version of the
artifact under given group.
* MavenCoordinates
8. Dependency Management
Mechanism for centralizing dependency information.
Managing dependencies become difficult task once we've to deal with multi-
module projects (consists of hundreds of modules/sub-projects). Maven provides
a high degree of control to manage such scenarios.
9. Dependency Management(Contd.)
o MavenCo-Ordinates – groupid, artifactid, version.
o type – packaging type.
• jar
• pom
• test-jar
• ejb-client etc.
o scope - compile (default), provided, runtime, test, system
o systemPath - use only if the dependency scope is “system”.
o optional - Marks optional a dependency when this project itself is a dependency.
11. Maven - Plug-ins
Maven is actually a plugin execution framework where every task is actually done by plugins.
Types:
Build Plugin -They execute during the build and should be configured in the <build/> element of
pom.xml.
Ex: maven-dependency-plugin
Reporting Plugin -They execute during the site generation and they should be configured in the
<reporting/> element of the pom.xml
Ex: maven-site-plugin
13. Maven - Plug-ins(Contd.)
Beyond the standard coordinate of groupId:artifactId:version, there are elements which configure the
plugin or this builds interaction with it.
inherited - true or false, whether or not this plugin configuration should apply to POMs which inherit from
this one. Default value is true.
configuration - package specific configuration
executions - configure the execution of a plugin's goals.
14. Lifecycles
Lifecycle is an organized sequence of phases that exist to give order to a set of
goals.
1) Clean
1) pre-clean
2) clean
3) post-clean
2) Default (sometimes called build)
1) validate
2) compile
3) test
4) package
5) verify
6) install
7) deploy
3) Site
1) pre-site
2) site
3) post-site
4) site-deploy
15. Inheritance
o Provides inheritance via the parent element.
o All Maven POMs inherit values from a parent POM. If a POM does not specify a direct
parent using the <parent> element, that POM will inherit values from the Super POM.
o The packaging type required to be pom for parent and aggregation (multi-module)
projects.
16. Inheritance (Contd.)
The elements in the parent POM that are inherited by its children are:
dependencies
developers and contributors
plugin lists
reports lists
plugin executions with matching ids
plugin configuration
17. Super POM
o All Maven project POMs extend the Super POM, which defines a set of defaults shared
by all projects.This Super POM is a part of the Maven installation.
o An analogy to how the Super POM is the parent for all Maven POM files, would be how
java.lang.Object is the top of the class hierarchy for all Java classes.