This document provides an overview of several key concepts for using Maven including:
- Default goals that can be set at the project level to save typing common commands like "mvn install".
- The super POM that all Maven projects inherit from to specify common configuration defaults.
- Archetypes that allow creating standard project templates with predefined directory structures and files.
- Dependency and plugin management sections that allow declaring common dependency and plugin versions to minimize repetitive declarations.
26. Super Pom
‣ Pseudo-invisible.
‣ All projects inherit it.
‣ Specifies file location defaults.
‣ Locks version of common plugins.
‣ post mvn 2.0.8.
‣ Increases build stability.
51. Dirty Tree
A:A:1.0
B:B:1.0 C:C:1.0
JU:JU:3.8.1 B:B:2.0 JU:JU:3.8.2
JU:JU:3.8.2
52. Dirty Tree
A:A:1.0
B:B:1.0 C:C:1.0
JU:JU:3.8.1 B:B:2.0 JU:JU:3.8.2
JU:JU:3.8.2
53. First sequential at same level ➲
[INFO] [dependency:tree]
[INFO] root.project:ear:ear:1.0
[INFO] +- root.project:ejbs:ejb:1.0:compile
[INFO] | - junit:junit:jar:4.0:compile
[INFO] +- root.project.servlets:servlet:war:1.0:compile
[INFO] +- root.project:primary-source:jar:1.0:compile
[INFO] - root.project.projects:logging:jar:1.0:compile
54. First sequential at same level ➲
4.0 is resolved
[INFO] [dependency:tree]
[INFO] root.project:ear:ear:1.0
[INFO] +- root.project:ejbs:ejb:1.0:compile
[INFO] | - junit:junit:jar:4.0:compile
[INFO] +- root.project.servlets:servlet:war:1.0:compile
[INFO] +- root.project:primary-source:jar:1.0:compile
[INFO] - root.project.projects:logging:jar:1.0:compile
55. First sequential at same level ➲
4.0 is resolved
[INFO] [dependency:tree]
[INFO] root.project:ear:ear:1.0
[INFO] +- root.project:ejbs:ejb:1.0:compile
[INFO] | - junit:junit:jar:4.0:compile
[INFO] +- root.project.servlets:servlet:war:1.0:compile
[INFO] +- root.project:primary-source:jar:1.0:compile
[INFO] - root.project.projects:logging:jar:1.0:compile
Even though I have 4.4 declared as
a dependency of primary-source
56. Resolving Tree
A:A:1.0
B:B:1.0 C:C:1.0
JU:JU:3.8.2 B:B:2.0 JU:JU:3.8.1
JU:JU:3.8.2
57. Resolving Tree
A:A:1.0
B:B:1.0 C:C:1.0
JU:JU:3.8.2 B:B:2.0 JU:JU:3.8.1
58. Resolving Tree
A:A:1.0
B:B:1.0 C:C:1.0
JU:JU:3.8.2 B:B:2.0
87. Debug Maven
‣ Waits on socket for debugger to connect.
‣ mvnDebug <anygoal>
‣ Useful for debugging plugins.
‣ Can be used for unit test debugging.
‣ mvnDebug test -DforkMode=none
88. Debug Unit Tests
‣ Waits on socket for debugger to connect.
mvn test -Dmaven.surefire.debug
98. m2eclipse Plugin
‣ Advanced Eclipse GUI for Maven
‣ Update site:
http://m2eclipse.sonatype.org/update-dev/
‣ Eclipse 3.2-3.4 compatibility
‣ 3.5 support arrived May 09
‣ Features include:
‣ Exclusion/Inclusion via clicks
‣ Searching for artifacts
‣ Dependency diagrams
‣ Click-to-run Maven goals
+
99. mvn eclipse:eclipse
File > Import > Existing
➊ Projects into Workspace
Set up Eclipse Classpath
Variable M2_REPO
100. mvn eclipse:eclipse
File > Import > Existing
➊ Projects into Workspace
Set up Eclipse Classpath
Variable M2_REPO
101. mvn eclipse:eclipse
te d
File > Import > Existing
a
➊ tdClasspath
Projects into Workspace
u
O
Set up Eclipse
Variable M2_REPO
102. mvn eclipse:eclipse
te d
File > Import > Existing
a
➊ tdClasspath
Projects into Workspace
u
O
Set up Eclipse
Variable M2_REPO
mvn eclipse:m2eclipse
➋ File > Import > Existing
Projects into Workspace
103. mvn eclipse:eclipse
te d
File > Import > Existing
a
➊ tdClasspath
Projects into Workspace
u
O
Set up Eclipse
Variable M2_REPO
mvn eclipse:m2eclipse
➋ File > Import > Existing
Projects into Workspace
104. mvn eclipse:eclipse
te d
File > Import > Existing
a
➊ tdClasspath
Projects into Workspace
u
O
Set up Eclipse
Variable M2_REPO
sa ry
es
mvn eclipse:m2eclipse
➋ File > Importc> Existing
nn e Workspace
U
Projects into
105. mvn eclipse:eclipse
te d
File > Import > Existing
a
➊ tdClasspath
Projects into Workspace
u
O
Set up Eclipse
Variable M2_REPO
sa ry
es
mvn eclipse:m2eclipse
➋ File > Importc> Existing
nn e Workspace
U
Projects into
➌ File > Import > Maven
Projects
106. mvn eclipse:eclipse
te d
File > Import > Existing
a
➊ tdClasspath
Projects into Workspace
u
O
Set up Eclipse
Variable M2_REPO
sa ry
es
mvn eclipse:m2eclipse
➋ File > Importc> Existing
nn e Workspace
U
Projects into
➌ File > Import > Maven
Projects
120. Reactor Plugin
Purposes
‣ Spawns a new nested Maven build.
‣ Restart where a long-running build failed.
‣ Selective build based on dependency.
‣ Selective build based on scm-noticed changes.
121. Reactor Plugin
In Use
‣ Resume multi-module build starting with this
module.
$ mvn reactor:resume -Dfrom=mymodule
122. Reactor Plugin
In Use
‣ Build all modules that are dependents of mine.
‣ Essentially, selective children.
‣ I just made a change.
‣ Want to ensure I didn’t break anything below me.
$ mvn reactor:make-dependents -Dmake.folders=mid1
or
$ mvn reactor:make-dependents -Dmake.projects=com.ambientideas:mid1
123. Reactor Plugin
In Use
‣ Build all modules that this module depends on
‣ Essentially, selective parents.
‣ Teammate informed me.
‣ Wants to make sure I test his changes.
$ mvn reactor:make -Dmake.folders=mid1
or
$ mvn reactor:make -Dmake.projects=com.ambientideas:mid1
124. Reactor Plugin
In Use
‣ Build all modules that scm says had changed.
‣ Essentially, build “dirty”.
$ mvn reactor:make-scm-changes
137. $ cd mymavenproj
it!
, th at’s
$ mvn ant:ant Yes
$ ls
build.xml
maven-build.xml
maven-build.properties
138. AntRun Plugin
‣ Run any Ant task.
‣ Leverage legacy in-house plugins.
‣ Great way to copy arbitrary files.
‣ Useful for echoing status or properties.
159. Twitter
@matthewmccull Matthew
Blog
http://www.ambientideas.com/blog
sidebar has all my social media links
Email
matthewm@ambientideas.com
GitHub
http://github.com/matthewmccullough