Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k...
Transcript of Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k...
![Page 1: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/1.jpg)
Maven
Introduction to Concepts: POM, Dependencies, Plugins, Phases
This document: http://arnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf
![Page 2: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/2.jpg)
What is Maven ?31
M !!
![Page 3: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/3.jpg)
https://maven.apache.org/
![Page 4: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/4.jpg)
A software project management and comprehension tool.
Based on a project object model (POM), .. project's build, reporting and documentation..
![Page 5: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/5.jpg)
https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
![Page 6: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/6.jpg)
https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
![Page 7: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/7.jpg)
Wikipedia
![Page 8: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/8.jpg)
Maven is a Build Automation Tool
pom.xml<dependencies>
<plugins>
<packaging> <phase>
![Page 9: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/9.jpg)
1st, it describes how software is built,
2nd, it describesits dependencies.
… use conventions for build
![Page 10: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/10.jpg)
Maven HistoryM
akef
ile
Ant
Mav
en 1
Mav
en 2
Mav
en 3
Mav
en 5
?
1977 2000 2002
Maven 1 = Ant + Jelly= xml build tasks + scripts (<if>, <var> ..)+ rules / lifecycle…
Ant= portable Makein xml for Javac, Jar, ..
2010 2017 ?2005
Maven 2= Java Mojopom.xml
Maven 3= better & compatible
optional .mvnw => pom inyaml, groovy, ..( not widespread )
?? Split pom vs build
Yaml / groovy
Gra
dle
2007
![Page 11: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/11.jpg)
Authors, Company, Community
Jason Van Zyl
Worked on TurbineAuthor of- Velocity- Maven
founder of Sonatype
Sonatype Company( core Contributor + Product = Nexus )
Apache Fondation= Open Source Community
PMC Chair / Member / Contributor / Plugin-Developpers / Users
![Page 12: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/12.jpg)
Maven Adoption
68% uses mavenIt JUST Work !!
4.5 Millions published artifacts (=jars)
![Page 13: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/13.jpg)
Yet Another Build Tool
Makefile, Imake, Cmake,Ant, Maven, Gradle,
MsBuild, Sbt, Gulp, Grunt, ...
![Page 14: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/14.jpg)
Declarative vs Imperative
Describe WHAT … not HOW
![Page 15: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/15.jpg)
Imperative
Do 1/ This, Then 2/ That,
Then 3/ Also That…
And N/ You have finished you want to restart ?
![Page 16: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/16.jpg)
ImplicitConvention over Configuration
Given standards
When You follow them
Then it just works
![Page 17: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/17.jpg)
ImplicitConvention over Configuration
a Java Program is src/*.java filescompiled in classes/*.class
using javac + classpath
assembled in jar file
tested with Junit testbla bla bla
![Page 18: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/18.jpg)
Implicit + Declarative= Surprising Magic ...
![Page 19: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/19.jpg)
Maven Core Concepts 1 :(declarative) Project Object Model
![Page 20: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/20.jpg)
Mandatory GAV Declaration
Unique ID : GAV = Group / Artifact / Version
Group = like dns domain name, reverse com.<<company>>, org.<<...>>, <<country>>.<<...>>. ...
Artifact = name of the final jar naming convention: some-library-name
Version = major.minor.fix (-SNAPSHOT)?
![Page 21: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/21.jpg)
Optional Project Information
![Page 22: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/22.jpg)
Example Project Information
![Page 23: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/23.jpg)
Typical Maven Generated Site
Menu when you see this logo
Logo comes from maven (maven-site-plugin )
Then you recognise pom infos
![Page 24: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/24.jpg)
Basic Declarations
![Page 25: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/25.jpg)
Maven Core Concepts 2 :Dependencies
![Page 26: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/26.jpg)
Dependency Declaration
Describe WHAT Not HOW
First execution: Download Next execution:
reuse local repository file
![Page 27: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/27.jpg)
http://maven.search.orgWHERE ?
![Page 28: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/28.jpg)
Transitive Dependencies
Transitive Relation Definition:A → B and B → C .. then A → C
![Page 29: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/29.jpg)
Transitive Dependencies Conflicts
A
B
C
D version1
D version2 != 1
![Page 30: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/30.jpg)
Dependencies Omitted for Conflict
Given Java ClassLoader load once each classWhen you have conflict
Then 1 jar on 2 would be useless, Maven omit oldest jar version
![Page 31: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/31.jpg)
Can Override default configurationOverride to use specific version
Override to exclude dependency
![Page 32: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/32.jpg)
DependencyManagementavoid duplicate version, use parent
![Page 33: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/33.jpg)
Dependency Scopes
Compile
Test
Runtime
src/main/java/**.java
src/test/java/**.java
target/classes/**.class
target/test-classes/**.class
target/*.jar
Provided *.jar
provided *.jar
system *.jar
compile *.jar
![Page 34: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/34.jpg)
Dependency Summary
Would be more concise than xml: “junit:junit:4.12:test”
Use dependencyManagementversions in parent only
don't be too verbosetransitive dependencies => implicit
don't be too implicituse exact versions, not *
![Page 35: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/35.jpg)
ExampleGetting Started with Mvn & Eclipse
![Page 36: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/36.jpg)
Maven Tools Usages
In Command Line In IDE EclipseBuit-in support
In CI Server Jenkins..Built-in support
![Page 37: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/37.jpg)
Maven Tools Usages
In Command Line In IDE EclipseBuit-in support
In CI Server Jenkins..Built-in support
![Page 38: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/38.jpg)
Installation= Unzip + export PATH
1: Unzip
2: export JAVA_HOME & PATH
![Page 39: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/39.jpg)
Mvn command line
mvn install
![Page 40: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/40.jpg)
Typical Commands
mvn install -f ../pom.xml -o -DskipTests -Pprofile...
mvn clean install
mvn springboot:run
Simpl
e ph
ases
With
opt
ions
Plugi
n G
oals
![Page 41: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/41.jpg)
Start Edit a Pom.xml manually ?
XML = Langage for Computers… not for Humans
You only need this identity card : GAV = group / artifact / version
![Page 42: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/42.jpg)
mvn archetype:generate New Project... > Type: Maven Project
New Maven Project
Import existing project … > Type : maven
mvn install
mvn installChoose archetype...
Copy & Paste
mvn install
![Page 43: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/43.jpg)
EclipseImport Existing Maven Project
![Page 44: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/44.jpg)
First Maven Project in Eclipse
![Page 45: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/45.jpg)
Pom.xml
![Page 46: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/46.jpg)
Standard Source Project Layout
![Page 47: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/47.jpg)
Mvn compile (or install)
![Page 48: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/48.jpg)
src → target directories
src/main/java → target/classes
compile-test
src
target
compile
src/test/java → target/test-classes
jartarget/classes → target/*.jar
target/*.jar → ~/.m2/repository/... groupId/artifactid/version/*.jar
install
deploy.m2/repository/.. .jar → http://nexus-repo/... groupId/artifactid/version/*.jar
![Page 49: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/49.jpg)
Mvn cleansrc vs target + .gitignore
![Page 50: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/50.jpg)
Typical .gitignorefor target/, .project, .classpath, ...
![Page 51: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/51.jpg)
Project Layout Explainedby Dichotomy Questions
Dir / FileStored In SCM or Generated (or ignored) ?
src/**+ pom.xml + .gitignore
target/**
.git/**
.classpath
.project
.settings
![Page 52: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/52.jpg)
Project Layout Explained (bis)
src/**
target/**
Main or test ?
src/main/**
src/test/**Dir / File
![Page 53: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/53.jpg)
Project Layout Explained (ter)
src
target
src/main
src/testDir / File
Lang? resources
java
docwebapp
python
![Page 54: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/54.jpg)
Maven Core Concepts 3 :Plugins – Goals
![Page 55: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/55.jpg)
https://maven.apache.org/plugins/Scroll for 100 more
![Page 56: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/56.jpg)
.m2/repository/org/apache/maven
First launch mvn … will download ~150Mo ...
Plugins ...
![Page 57: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/57.jpg)
Maven .m2/repository/ …/pluginsstandard plugins in local repository
![Page 58: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/58.jpg)
Use build/plugins
Declare plugin Dependencies … with GAV ( as “build dependencies” but in section plugins)=> Plugin will register itself in build lifecyclesee next for configuring..
Use plugin
Use Another
![Page 59: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/59.jpg)
Plugin <configuration>
Overridepluginconfiguration
<source> = “-source” for javac compiler …list of options => cf next
![Page 60: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/60.jpg)
Eclipse Auto-Completionfor Plugin Configuration
![Page 61: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/61.jpg)
Maven Plugin Doc Sitehttps://maven.apache.org/plugins
See Plugin Goals & Usage
In 2016default value to change
for jdk8 !!
![Page 62: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/62.jpg)
Configuration Override Properties
Project properties
![Page 63: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/63.jpg)
Properties Override Hierarchy (bis)
Project properties
User ~/.m2/settings.xml
Command Line arguments
override
override
![Page 64: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/64.jpg)
plugins/executions
1 execution
Can add others...
When processing lifecycle phase
Then call plugin goal
With this parameter
![Page 65: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/65.jpg)
Plugin Execution Override
Executionconfiguration
Project properties
pluginconfiguration
override
override
![Page 66: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/66.jpg)
Command LineExplicit Plugin Goal Execution
Call build lifecycle 1..* phase(s) => sequence of plugin goals
Call explicit 1..* plugin goal(s)
![Page 67: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/67.jpg)
Example of Plugin Goals
![Page 68: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/68.jpg)
Plugin Internal “Mojo” Classes
as simple as a “main()”executed within a project build context
![Page 69: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/69.jpg)
Run Mojo Hello World ...
![Page 70: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/70.jpg)
Mojo Context Injection @Parameter
Inject the FAMOUS pom
Inject from <configuration><sources>..
default properties for values
![Page 71: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/71.jpg)
Maven Core Concepts 4 :Build Lifecycle - Phases
![Page 72: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/72.jpg)
Maven Phases
![Page 73: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/73.jpg)
Register Goals Execution in Phases
Explicit Goal Execution per <phase>
Implicit Goal Execution per Phase
![Page 74: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/74.jpg)
Project Type→LifeCycle→Phases →Plugins Mojo
META-INF/plexus/components.xml
repository/org/apache/maven/plugins/
Maven-jar-plugin-3.0.2.jar
![Page 75: Maven - GitHub Pagesarnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf · Maven History M a k e f i l e A n t M a v e n 1 M a v e n 2 M a v e n 3 M a v e n 5 ? 1977 2000 2002](https://reader030.fdocuments.in/reader030/viewer/2022040608/5ec578a3306dd8516847d904/html5/thumbnails/75.jpg)
Conclusion
Questions [email protected]
Only a “Short” Introduction to Concepts...
other docs:http://arnaud-nauwynck.github.io/
http://arnaud.nauwynck.free.fr/
This document: http://arnaud-nauwynck.github.io/docs/Maven-Intro-Concepts.pdf