Intro To Maven
Intro To Maven
Content
1. What is Maven?
2. Key Features
3. How does it work?
4. Maven Directory Structure
5. POM file
6. Settings file
7. Life Cycle
8. Bibliography
1. What is Maven?
easier build
process
best practices
development
quality project
guidelines information
MAVE
N
model-based
builds uniform build
system
dependencies
manager
3. How does it work?
• build controlled via POM (Project Object Model) files
Build Life Cycles
• Phases
• Goals
read pom.xml
Maven Maven Local
Dependencies
(JAR) Repository
Build Plugins
Build Profiles
POM File
4. Maven Directory Structure
• predefined standard
• no need to specify any directory on the project level
5. POM File
<groupId>com.rdaniel</groupId>
<artifactId>unit-test-tutorial</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
• project
• modelVersion
• Maven Coordinates – 3 tags
• groupId – the group from which the project is a part of
• artifactId – the name of the project
• version – project's version
• they would result in a JAR file built in and placed in the local Maven
repository
Dependencies
• most projects depend on other projects in order to build successfully
• 2 types:
• direct dependencies
• transitive dependencies
• example
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Properties
• avoid hardcoding values (like dependencies versions)
• provide flexibility to the build tool – passed at runtime
• examples:
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<junit.version>4.13.2</junit.version>
<pom.property1>env.MAVEN_HOME</pom.property1>
</properties>
Repositories
• holds build artifacts and dependencies
• two types:
• local – on the machine where Maven runs
• remote – external repositories providing artifacts for downloading
• configuring tags:
• releases, snapshots
• enabled
• updatePolicy
• checksumPolicy
• layout
Builds
• configure: plugins, directory to store the package, resource filtering
• two types:
• project build – base configurations per POM
• profile build – build configurations inside a profile
Builds - Resources
• used for: code generation, properties files, images, other files
• configured in the build part
• configuration tags:
• resources
• targetPath
• filtering
• directory
• includes
• excludes
• testResources
Builds - Plugins
deploy
8. Bibliography
• https://en.wikipedia.org/wiki/Apache_Maven
• https://maven.apache.org/
• Maven presentation – Marian Ungureanu, NTT Data Romania
• Maven Tutorial (jenkov.com)