maven
TRANSCRIPT
Project management and Comprehension tool
Maven... What is it?
Dependency ManagementPlugin-ins
POM
Lifecycles Inheritance
Maven... What is it?
"build tool" • Generates deployable artifacts from the source
code.• Preprocessing, compilation, packaging, testing and
distribution.
"project management tool"
• Generates Web Site (Project Documentation)
• Run Reports
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
Standard Directory Layout
POM (Project Object Model)o Fundamental unit of work in Maveno 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
POM – Important Attributesproject 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.
* Maven Coordinates
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.
Dependency Management(Contd.) o Maven Co-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.
Dependency Management(Contd.)
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
Maven - Plug-ins(Contd.)
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.
LifecyclesLifecycle is an organized sequence of phases that exist to give order to a set of goals.1) Clean
1) pre-clean2) clean3) post-clean
2) Default (sometimes called build) 1) validate2) compile3) test4) package5) verify6) install7) deploy
3) Site1) pre-site2) site3) post-site4) site-deploy
Inheritanceo 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.
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
Super POMo 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.
Lots covered…questions?
https://maven.apache.org/pom.html#What_is_the_POM
https://
maven.apache.org/guides/mini/guide-configuring-plugins.html
https://www.tutorialspoint.com//maven/index.htm
https://dzone.com/articles/5-maven-tips
https://maven.apache.org/settings.html