Your SlideShare is downloading. ×
0
Mastering
          Maven
  ncrease your Mo Jo-tivity
I


                    by Matthew McCullough of Ambient Ideas, LLC
Matthew
http://refcardz.dzone.com/refcardz/apache-maven-2
Maven use ing
     up
on the   sw
Convention
    v e r
   o Configuration
Default
   Goal
Default Goal

‣   Often not set.
‣   Saves typing.
‣   Communicates author’s intended goal.
‣   Only one goal or phase all...
mvn install
<project>
  <groupId>com.ambientideas</groupId>
  <artifactId>sample-defaultgoal</artifactId>
  [...]

  <build>
    <defa...
mvn install
mvn install
mvn
Super
   Pom
Super Pom
‣ Pseudo-invisible.
Super Pom
‣ Pseudo-invisible.
‣ All projects inherit it.
Super Pom
‣ Pseudo-invisible.
‣ All projects inherit it.
‣ Specifies file location defaults.
Super Pom
‣   Pseudo-invisible.
‣   All projects inherit it.
‣   Specifies file location defaults.
‣   Locks version of comm...
<!-- START SNIPPET: superpom -->
<project>
  <modelVersion>4.0.0</modelVersion>
  <name>Maven Default Project</name>

  <b...
Super Pom


‣ Familiarize yourself with it.
‣ View it in SVN.
Saving time with
Archetypes
Project via Archetype
‣ Project templates on steroids.
  ‣   Seed unit tests.
  ‣   Standardize directory structure.
  ‣  ...
$ mvn archetype:generate
Archetype via Project

‣ Uses existing project as seed.
‣ Turns it into a maven archetype.
‣ Can publish to a repo for oth...
$ mvn archetype:create-from-project
Archetype via Archetype

‣ “Template for templates”
Archetype via Archetype

‣ “Template for templates”
‣ Can be selected from the archetype list.
Archetype via Archetype

‣ “Template for templates”
‣ Can be selected from the archetype list.
mvn archetype:generate
$ mvn archetype:generate
  -DarchetypeGroupId=quot;org.apache.maven.archetypesquot;
  -DarchetypeArtifactId=maven-archetyp...
Dependency
  Management
Dirty Tree
                                     A:A:1.0




                           B:B:1.0               C:C:1.0




 ...
How does Maven resolve versions?
Nearest
Dirty Tree
                                     A:A:1.0




                           B:B:1.0               C:C:1.0




 ...
Dirty Tree
                                     A:A:1.0




                           B:B:1.0               C:C:1.0




 ...
Then highest version?
Then highest version?
Then sequential first at same distance
Dirty Tree
                                     A:A:1.0




                           B:B:1.0               C:C:1.0




 ...
Dirty Tree
                                     A:A:1.0




                           B:B:1.0               C:C:1.0




 ...
First sequential at same level ➲




                                   [INFO]   [dependency:tree]
                       ...
First sequential at same level ➲



                                                                    4.0 is resolved
  ...
First sequential at same level ➲



                                                                    4.0 is resolved
  ...
Resolving Tree
                                         A:A:1.0




                               B:B:1.0               C...
Resolving Tree
                                         A:A:1.0




                               B:B:1.0               C...
Resolving Tree
                                         A:A:1.0




                               B:B:1.0               C...
Resolved Tree
                                        A:A:1.0




                              B:B:1.0             C:C:1....
We’ve resolved the version tree.
How about the dependency graph?
Dirty Graph
                                      A:A:1.0




                            B:B:1.0               C:C:1.0


...
Resolved Graph
                            A:A:1.0




                 B:B:1.0                 C:C:1.0




              ...
A dice roll
for complex graphs?
Declare desired versions
Advertise authorized versions
<*Management>

‣ <dependencyManagement>
 ‣ Inheritance for dependency versions.
<*Management>

‣ <dependencyManagement>
 ‣ Inheritance for dependency versions.
‣ <pluginManagement>
 ‣ Inheritance for pl...
<dependencyManagement> and <pluginManagement>
   are essentially identical
Minimizing declarations
        with
   <*Management>
In the base pom.xml...
<pluginManagement>
 <plugins>
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-antrun-p...
<pluginManagement>
 <plugins>
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-antrun-p...
<pluginManagement>
 <plugins>
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-antrun-p...
<pluginManagement>
 <plugins>
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-antrun-p...
In the child pom.xml...
<plugins>
  <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
  </plugin>
</plugins>
Dependency Lists
‣ List view
  ‣ mvn dependency:resolve
‣ Tree view
  ‣ mvn dependency:tree
‣ Plugin list view
  ‣ mvn dep...
$ mvn dependency:tree
[INFO] com.ambientideas:sample13-wicket:war:1.0-SNAPSHOT
[INFO] +- org.apache.wicket:wicket:jar:1.3....
Dependency Analysis


‣ Analyze to help prune unneeded.
 ‣ mvn dependency:analyze
Dependency Analysis


‣ See if overrides are colliding.
  ‣ mvn dependency:analyze-dep-mgt
$ mvn dependency:analyze

[WARNING] Unused declared dependencies found:
[WARNING] org.slf4j:slf4j-log4j12:jar:1.4.2:compil...
DeBugging
Maven Debug Flags

‣ Output full error stacktraces.
  ‣ mvn <anygoal> -e
‣ Output debug level operational info.
  ‣ mvn <a...
$ mvn <anygoal> -X

[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-
dependency-plugin:2.0:analyze' -->
[DEBUG] (f...
Debug Maven

‣ Waits on socket for debugger to connect.
  ‣ mvnDebug <anygoal>
‣ Useful for debugging plugins.

‣ Can be u...
Debug Unit Tests

‣ Waits on socket for debugger to connect.

 mvn test -Dmaven.surefire.debug
Groovy
 Support
Groovy Support
‣ Groovy application code compilation.
  ‣ mvn archetype:generate
    ...gmaven-archetype-basic

‣ Groovy m...
Grails Support
 ‣ Grails now fully supports Maven...
   ‣ Archetype
   ‣ Grails goals: create-controller, run-app, etc.
mv...
command line
      Help !
Maven Help Plugin

mvn help:describe -Dplugin=<anygoal>

‣ Lists and describes plugin goals.
Maven Help Plugin

mvn help:system

‣ Outputs environment variables and
  system properties.
Maven Help Plugin

mvn help:active-profiles

‣ See what profiles are being
  triggered by environment, files,
  params.
Maven Help Plugin

mvn help:effective-pom

‣ Outputs the resultant pom.
‣ Includes inherited sections.
M2Eclipse
m2eclipse Plugin
‣ Advanced Eclipse GUI for Maven
  ‣ Update site:
    http://m2eclipse.sonatype.org/update-dev/
‣ Eclipse...
mvn eclipse:eclipse
    File > Import > Existing
➊   Projects into Workspace
    Set up Eclipse Classpath
    Variable M2_...
mvn eclipse:eclipse
    File > Import > Existing
➊   Projects into Workspace
    Set up Eclipse Classpath
    Variable M2_...
mvn eclipse:eclipse

                    te d
    File > Import > Existing
                  a
➊             tdClasspath
 ...
mvn eclipse:eclipse

                    te d
    File > Import > Existing
                  a
➊             tdClasspath
 ...
mvn eclipse:eclipse

                    te d
    File > Import > Existing
                  a
➊             tdClasspath
 ...
mvn eclipse:eclipse

                    te d
    File > Import > Existing
                  a
➊             tdClasspath
 ...
mvn eclipse:eclipse

                    te d
    File > Import > Existing
                  a
➊             tdClasspath
 ...
mvn eclipse:eclipse

                    te d
    File > Import > Existing
                  a
➊             tdClasspath
 ...
Dependency Graph
Exclusions
Eclipse command line Compiler
<plugin>
     <artifactId>maven‐compiler‐plugin</artifactId>
     <configuration>
         <...
Source Code Control
      Integration
Maven SCM Support
‣ Seamlessly integrates Maven
  processes with your SCM repo.
 ‣ mvn scm:diff
  ‣ Creates UNIX diff file
...
Maven SCM Support

‣ Dozens of SCM systems supported.
 ‣ CVS
 ‣ Subversion
 ‣ Git
http://docs.codehaus.org/display/SCM/SCM+Matrix
Maven SCM Support

mvn release:prepare

‣ Increments all pom.xml version tags.
Reactor
    Plugin
Reactor Plugin

Purposes
  ‣   Spawns a new nested Maven build.
  ‣   Restart where a long-running build failed.
  ‣   Sel...
Reactor Plugin
 In Use
  ‣ Resume multi-module build starting with this
    module.


$ mvn reactor:resume -Dfrom=mymodule
Reactor Plugin
  In Use
    ‣ Build all modules that are dependents of mine.
       ‣ Essentially, selective children.
   ...
Reactor Plugin

  In Use
   ‣ Build all modules that this module depends on
      ‣ Essentially, selective parents.
      ...
Reactor Plugin

In Use
‣ Build all modules that scm says had changed.
  ‣ Essentially, build “dirty”.



  $ mvn reactor:m...
Running
   Apps
Exec Plugin

‣ Run any Java main class or external tool.
Exec Plugin

‣ Run any Java main class or external tool.
‣ Builds classpath from pom dependencies.
Exec Plugin

‣ Run any Java main class or external tool.
‣ Builds classpath from pom dependencies.
‣ Primarily for testing.
$ mvn exec:java -Dexec.mainClass=quot;com.foo.Mainquot;
$ mvn exec:java -Dexec.mainClass=quot;com.foo.Mainquot;


 or
$ mvn exec:java -Dexec.mainClass=quot;com.foo.Mainquot;


 or
$ mvn exec:exec -Dexec.executable=quot;winzip.exequot;
   -D...
Ant
Integration
Ant Build Generation

Why?
‣ Dead simple.
‣ Great for backport/legacy situations.
$ cd mymavenproj
$ cd mymavenproj
$ mvn ant:ant
$ cd mymavenproj
                              it!
                    , th at’s
$ mvn ant:ant   Yes


$ ls
build.xml
mave...
AntRun Plugin

‣   Run any Ant task.
‣   Leverage legacy in-house plugins.
‣   Great way to copy arbitrary files.
‣   Usefu...
<plugins>
  <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
      <execution>
        <id>echod...
Sitesand
  Reports
Site Generation
‣ Professional project web site
Site Generation
‣ Professional project web site
‣ Templatizable
Site Generation
‣ Professional project web site
‣ Templatizable
‣ Contributors
Site Generation
‣   Professional project web site
‣   Templatizable
‣   Contributors
‣   Licenses
Site Generation
‣   Professional project web site
‣   Templatizable
‣   Contributors
‣   Licenses
‣   Hyperlinked source r...
Site Generation
‣   Professional project web site
‣   Templatizable
‣   Contributors
‣   Licenses
‣   Hyperlinked source r...
Site Generation
‣   Professional project web site
‣   Templatizable
‣   Contributors
‣   Licenses
‣   Hyperlinked source r...
Site Generation
‣   Professional project web site
‣   Templatizable
‣   Contributors
‣   Licenses
‣   Hyperlinked source r...
Project Info
Report Generation

‣   Unit test reports
‣   Test coverage reports
‣   Checkstyle and PMD
‣   Javadocs
‣   Tag list (TODO)
Report
What’s New?
Maven 2.0.10
‣ Stability.
‣ Unit and integration tests.
‣ End of the line for 2.0.X.
Maven 2.1
‣ Parallel downloads (Don Brown)
‣ Encrypted passwords
‣ Drop in replacement
What’s Next?
Maven 3.0
‣ Encrypted passwords (from 2.1)
‣ Mercury engine
  ‣ Parallel downloads (determinate)
  ‣ New resolver
‣ Tyco O...
Build Nirvana
Twitter
 @matthewmccull             Matthew
Blog
 http://www.ambientideas.com/blog
         sidebar has all my social medi...
Resources
Maven Homepage
http://maven.apache.org/

Maven Sonatype eBook
http://www.sonatype.com/book/

Matthew’s Maven Boo...
Resources
Maven Superpom
http://maven.apache.org/pom.html#The_Super_POM

Sonatype Central Repo
http://repository.sonatype....
Resources
GMaven Plugin
http://groovy.codehaus.org/GMaven

Grails Maven Integration
http://www.grails.org/Maven+Integratio...
Resources
Archetype Guide
http://maven.apache.org/guides/mini/guide-creating-archetypes.html

Sonatype eBook Archetype Cha...
Resources
Maven Dependency Plugin
http://maven.apache.org/plugins/maven-dependency-plugin/

Maven AntRun Plugin
http://mav...
Image Credits

‣ http://flickr.com/photos/chanchan222/2883910690/
‣ http://flickr.com/photos/themarmot/3173506262/
‣ http://...
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Upcoming SlideShare
Loading in...5
×

Mastering Maven 2.0 In 1 Hour V1.3

24,602

Published on

Presentation of Mastering Maven to the SDJUG team in San Diego, CA.

Published in: Technology

Transcript of "Mastering Maven 2.0 In 1 Hour V1.3"

  1. 1. Mastering Maven ncrease your Mo Jo-tivity I by Matthew McCullough of Ambient Ideas, LLC
  2. 2. Matthew
  3. 3. http://refcardz.dzone.com/refcardz/apache-maven-2
  4. 4. Maven use ing up on the sw
  5. 5. Convention v e r o Configuration
  6. 6. Default Goal
  7. 7. Default Goal ‣ Often not set. ‣ Saves typing. ‣ Communicates author’s intended goal. ‣ Only one goal or phase allowed.
  8. 8. mvn install
  9. 9. <project> <groupId>com.ambientideas</groupId> <artifactId>sample-defaultgoal</artifactId> [...] <build> <defaultGoal>install</defaultGoal> </build> [...] </project>
  10. 10. mvn install
  11. 11. mvn install
  12. 12. mvn
  13. 13. Super Pom
  14. 14. Super Pom ‣ Pseudo-invisible.
  15. 15. Super Pom ‣ Pseudo-invisible. ‣ All projects inherit it.
  16. 16. Super Pom ‣ Pseudo-invisible. ‣ All projects inherit it. ‣ Specifies file location defaults.
  17. 17. 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.
  18. 18. <!-- START SNIPPET: superpom --> <project> <modelVersion>4.0.0</modelVersion> <name>Maven Default Project</name> <build> <directory>target</directory> <outputDirectory>target/classes</outputDirectory> <finalName>${project.artifactId}-${project.version}</finalName> [...] <pluginManagement> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>2.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> </plugin> </plugins> </pluginManagement> </build> </project>
  19. 19. Super Pom ‣ Familiarize yourself with it. ‣ View it in SVN.
  20. 20. Saving time with Archetypes
  21. 21. Project via Archetype ‣ Project templates on steroids. ‣ Seed unit tests. ‣ Standardize directory structure. ‣ Corporate licenses, OSS licenses. ‣ Bundle corporate READMEs. ‣ Doesn’t mutate like a copy-n-paste template. ‣ Replaceables for classnames, company info.
  22. 22. $ mvn archetype:generate
  23. 23. Archetype via Project ‣ Uses existing project as seed. ‣ Turns it into a maven archetype. ‣ Can publish to a repo for others to use.
  24. 24. $ mvn archetype:create-from-project
  25. 25. Archetype via Archetype ‣ “Template for templates”
  26. 26. Archetype via Archetype ‣ “Template for templates” ‣ Can be selected from the archetype list.
  27. 27. Archetype via Archetype ‣ “Template for templates” ‣ Can be selected from the archetype list. mvn archetype:generate
  28. 28. $ mvn archetype:generate -DarchetypeGroupId=quot;org.apache.maven.archetypesquot; -DarchetypeArtifactId=maven-archetype-archetype -DarchetypeVersion=1.0 -DgroupId=com.ambientideas -DartifactId=mysamplearchetype
  29. 29. Dependency Management
  30. 30. 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
  31. 31. How does Maven resolve versions?
  32. 32. Nearest
  33. 33. 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
  34. 34. 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
  35. 35. Then highest version?
  36. 36. Then highest version?
  37. 37. Then sequential first at same distance
  38. 38. 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
  39. 39. 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
  40. 40. 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
  41. 41. 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
  42. 42. 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
  43. 43. 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
  44. 44. 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
  45. 45. Resolving Tree A:A:1.0 B:B:1.0 C:C:1.0 JU:JU:3.8.2 B:B:2.0
  46. 46. Resolved Tree A:A:1.0 B:B:1.0 C:C:1.0 JU:JU:3.8.2
  47. 47. We’ve resolved the version tree.
  48. 48. How about the dependency graph?
  49. 49. Dirty Graph 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
  50. 50. Resolved Graph A:A:1.0 B:B:1.0 C:C:1.0 JU:JU:3.8.2
  51. 51. A dice roll for complex graphs?
  52. 52. Declare desired versions
  53. 53. Advertise authorized versions
  54. 54. <*Management> ‣ <dependencyManagement> ‣ Inheritance for dependency versions.
  55. 55. <*Management> ‣ <dependencyManagement> ‣ Inheritance for dependency versions. ‣ <pluginManagement> ‣ Inheritance for plugin versions and config.
  56. 56. <dependencyManagement> and <pluginManagement> are essentially identical
  57. 57. Minimizing declarations with <*Management>
  58. 58. In the base pom.xml...
  59. 59. <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>echodir</id> <goals> <goal>run</goal> </goals> <phase>install</phase> <configuration> <tasks> <echo>Build Dir: ${project.build.directory}</echo> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </pluginManagement>
  60. 60. <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>echodir</id> <goals> <goal>run</goal> </goals> <phase>install</phase> <configuration> <tasks> <echo>Build Dir: ${project.build.directory}</echo> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </pluginManagement>
  61. 61. <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>echodir</id> <goals> <goal>run</goal> </goals> <phase>install</phase> <configuration> <tasks> <echo>Build Dir: ${project.build.directory}</echo> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </pluginManagement>
  62. 62. <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>echodir</id> <goals> <goal>run</goal> </goals> <phase>install</phase> <configuration> <tasks> <echo>Build Dir: ${project.build.directory}</echo> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </pluginManagement>
  63. 63. In the child pom.xml...
  64. 64. <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> </plugin> </plugins>
  65. 65. Dependency Lists ‣ List view ‣ mvn dependency:resolve ‣ Tree view ‣ mvn dependency:tree ‣ Plugin list view ‣ mvn dependency:resolve-plugins
  66. 66. $ mvn dependency:tree [INFO] com.ambientideas:sample13-wicket:war:1.0-SNAPSHOT [INFO] +- org.apache.wicket:wicket:jar:1.3.2:compile [INFO] | - org.slf4j:slf4j-api:jar:1.4.2:compile [INFO] +- org.apache.wicket:wicket-extensions:jar:1.3.2:compile [INFO] +- commons-collections:commons-collections:jar:3.1:compile [INFO] +- org.slf4j:slf4j-log4j12:jar:1.4.2:compile [INFO] +- log4j:log4j:jar:1.2.14:compile [INFO] +- junit:junit:jar:3.8.2:test [INFO] +- org.mortbay.jetty:jetty:jar:6.1.4:provided [INFO] | - org.mortbay.jetty:servlet-api-2.5:jar:6.1.4:provided [INFO] +- org.mortbay.jetty:jetty-util:jar:6.1.4:provided [INFO] - org.mortbay.jetty:jetty-management:jar:6.1.4:provided [INFO] +- mx4j:mx4j:jar:3.0.1:provided [INFO] - mx4j:mx4j-tools:jar:3.0.1:provided
  67. 67. Dependency Analysis ‣ Analyze to help prune unneeded. ‣ mvn dependency:analyze
  68. 68. Dependency Analysis ‣ See if overrides are colliding. ‣ mvn dependency:analyze-dep-mgt
  69. 69. $ mvn dependency:analyze [WARNING] Unused declared dependencies found: [WARNING] org.slf4j:slf4j-log4j12:jar:1.4.2:compile [WARNING] log4j:log4j:jar:1.2.14:compile [WARNING] org.mortbay.jetty:jetty-management:jar:6.1.4:provided [WARNING] org.apache.wicket:wicket-extensions:jar:1.3.2:compile [WARNING] commons-collections:commons-collections:jar:3.1:compile
  70. 70. DeBugging
  71. 71. Maven Debug Flags ‣ Output full error stacktraces. ‣ mvn <anygoal> -e ‣ Output debug level operational info. ‣ mvn <anygoal> -X ‣ Always use when submitting questions or bug reports.
  72. 72. $ mvn <anygoal> -X [DEBUG] Configuring mojo 'org.apache.maven.plugins:maven- dependency-plugin:2.0:analyze' --> [DEBUG] (f) baseDir = /Users/mccm06/Documents/Teach/ Courses/Mastering-Maven-1Hour/examples/maven-training.git/ sample13-wicket-withdependencies [DEBUG] (f) failOnWarning = false [DEBUG] (f) project = MavenProject: com.ambientideas:sample13-wicket-withunneededdependencies: 1.0-SNAPSHOT @ /Users/mccm06/Documents/Teach/Courses/ Mastering-Maven-1Hour/examples/maven-training.git/sample13- wicket-withunneededdependencies/pom.xml [DEBUG] (f) scriptableFlag = $$%%% [DEBUG] (f) scriptableOutput = false [DEBUG] (f) verbose = false
  73. 73. 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
  74. 74. Debug Unit Tests ‣ Waits on socket for debugger to connect. mvn test -Dmaven.surefire.debug
  75. 75. Groovy Support
  76. 76. Groovy Support ‣ Groovy application code compilation. ‣ mvn archetype:generate ...gmaven-archetype-basic ‣ Groovy maven plugin authoring. ‣ mvn archetype:generate ...gmaven-archetype-mojo ‣ Joint compiler in both cases. +
  77. 77. Grails Support ‣ Grails now fully supports Maven... ‣ Archetype ‣ Grails goals: create-controller, run-app, etc. mvn org.apache.maven.plugins:maven-archetype-plugin:2.0- alpha-4:generate -DarchetypeGroupId=org.grails -DarchetypeArtifactId=grails-maven-archetype -DarchetypeVersion=1.0-SNAPSHOT -DarchetypeRepository=http://snapshots.repository.codehaus.org -DgroupId=com.ambientideas -DartifactId=sample-grails +
  78. 78. command line Help !
  79. 79. Maven Help Plugin mvn help:describe -Dplugin=<anygoal> ‣ Lists and describes plugin goals.
  80. 80. Maven Help Plugin mvn help:system ‣ Outputs environment variables and system properties.
  81. 81. Maven Help Plugin mvn help:active-profiles ‣ See what profiles are being triggered by environment, files, params.
  82. 82. Maven Help Plugin mvn help:effective-pom ‣ Outputs the resultant pom. ‣ Includes inherited sections.
  83. 83. M2Eclipse
  84. 84. 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 +
  85. 85. mvn eclipse:eclipse File > Import > Existing ➊ Projects into Workspace Set up Eclipse Classpath Variable M2_REPO
  86. 86. mvn eclipse:eclipse File > Import > Existing ➊ Projects into Workspace Set up Eclipse Classpath Variable M2_REPO
  87. 87. mvn eclipse:eclipse te d File > Import > Existing a ➊ tdClasspath Projects into Workspace u O Set up Eclipse Variable M2_REPO
  88. 88. 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
  89. 89. 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
  90. 90. 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
  91. 91. 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
  92. 92. 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
  93. 93. Dependency Graph
  94. 94. Exclusions
  95. 95. Eclipse command line Compiler <plugin>      <artifactId>maven‐compiler‐plugin</artifactId>      <configuration>          <compilerId>eclipse</compilerId>          <source>1.5</source>          <target>1.6</target>      </configuration>      <dependencies>         <dependency>            <groupId>org.codehaus.plexus</groupId>            <artifactId>plexus‐compiler‐eclipse</artifactId>            <version>1.5.1</version>         </dependency>      </dependencies> </plugin>
  96. 96. Source Code Control Integration
  97. 97. Maven SCM Support ‣ Seamlessly integrates Maven processes with your SCM repo. ‣ mvn scm:diff ‣ Creates UNIX diff file ‣ mvn scm:tag ‣ mvn scm:status
  98. 98. Maven SCM Support ‣ Dozens of SCM systems supported. ‣ CVS ‣ Subversion ‣ Git
  99. 99. http://docs.codehaus.org/display/SCM/SCM+Matrix
  100. 100. Maven SCM Support mvn release:prepare ‣ Increments all pom.xml version tags.
  101. 101. Reactor Plugin
  102. 102. 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.
  103. 103. Reactor Plugin In Use ‣ Resume multi-module build starting with this module. $ mvn reactor:resume -Dfrom=mymodule
  104. 104. 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
  105. 105. 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
  106. 106. Reactor Plugin In Use ‣ Build all modules that scm says had changed. ‣ Essentially, build “dirty”. $ mvn reactor:make-scm-changes
  107. 107. Running Apps
  108. 108. Exec Plugin ‣ Run any Java main class or external tool.
  109. 109. Exec Plugin ‣ Run any Java main class or external tool. ‣ Builds classpath from pom dependencies.
  110. 110. Exec Plugin ‣ Run any Java main class or external tool. ‣ Builds classpath from pom dependencies. ‣ Primarily for testing.
  111. 111. $ mvn exec:java -Dexec.mainClass=quot;com.foo.Mainquot;
  112. 112. $ mvn exec:java -Dexec.mainClass=quot;com.foo.Mainquot; or
  113. 113. $ mvn exec:java -Dexec.mainClass=quot;com.foo.Mainquot; or $ mvn exec:exec -Dexec.executable=quot;winzip.exequot; -Dexec.args=quot;myfile.txtquot;
  114. 114. Ant Integration
  115. 115. Ant Build Generation Why? ‣ Dead simple. ‣ Great for backport/legacy situations.
  116. 116. $ cd mymavenproj
  117. 117. $ cd mymavenproj $ mvn ant:ant
  118. 118. $ cd mymavenproj it! , th at’s $ mvn ant:ant Yes $ ls build.xml maven-build.xml maven-build.properties
  119. 119. AntRun Plugin ‣ Run any Ant task. ‣ Leverage legacy in-house plugins. ‣ Great way to copy arbitrary files. ‣ Useful for echoing status or properties.
  120. 120. <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>echodir</id> <goals> <goal>run</goal> </goals> <phase>package</phase> <configuration> <tasks> <echo>BuildDir: ${project.build.directory}</echo> <copy todir=quot;${myspecialfolder}quot;> <fileset dir=quot;${myfiles}quot;/> </copy> </tasks> </configuration> </execution> </executions> </plugin> </plugins>
  121. 121. Sitesand Reports
  122. 122. Site Generation ‣ Professional project web site
  123. 123. Site Generation ‣ Professional project web site ‣ Templatizable
  124. 124. Site Generation ‣ Professional project web site ‣ Templatizable ‣ Contributors
  125. 125. Site Generation ‣ Professional project web site ‣ Templatizable ‣ Contributors ‣ Licenses
  126. 126. Site Generation ‣ Professional project web site ‣ Templatizable ‣ Contributors ‣ Licenses ‣ Hyperlinked source ref
  127. 127. Site Generation ‣ Professional project web site ‣ Templatizable ‣ Contributors ‣ Licenses ‣ Hyperlinked source ref ‣ Defect tracking
  128. 128. Site Generation ‣ Professional project web site ‣ Templatizable ‣ Contributors ‣ Licenses ‣ Hyperlinked source ref ‣ Defect tracking ‣ Dependencies
  129. 129. Site Generation ‣ Professional project web site ‣ Templatizable ‣ Contributors ‣ Licenses ‣ Hyperlinked source ref ‣ Defect tracking ‣ Dependencies ‣ Plugins
  130. 130. Project Info
  131. 131. Report Generation ‣ Unit test reports ‣ Test coverage reports ‣ Checkstyle and PMD ‣ Javadocs ‣ Tag list (TODO)
  132. 132. Report
  133. 133. What’s New?
  134. 134. Maven 2.0.10 ‣ Stability. ‣ Unit and integration tests. ‣ End of the line for 2.0.X.
  135. 135. Maven 2.1 ‣ Parallel downloads (Don Brown) ‣ Encrypted passwords ‣ Drop in replacement
  136. 136. What’s Next?
  137. 137. Maven 3.0 ‣ Encrypted passwords (from 2.1) ‣ Mercury engine ‣ Parallel downloads (determinate) ‣ New resolver ‣ Tyco OSGi bundle builder
  138. 138. Build Nirvana
  139. 139. 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
  140. 140. Resources Maven Homepage http://maven.apache.org/ Maven Sonatype eBook http://www.sonatype.com/book/ Matthew’s Maven Bookmarks http://delicious.com/matthew.mccullough/maven GMaven Plugin http://groovy.codehaus.org/GMaven
  141. 141. Resources Maven Superpom http://maven.apache.org/pom.html#The_Super_POM Sonatype Central Repo http://repository.sonatype.org/ Java.net Repo http://download.java.net/maven/2/ Archetype Mini-Guide http://maven.apache.org/guides/mini/guide-creating-archetypes.html
  142. 142. Resources GMaven Plugin http://groovy.codehaus.org/GMaven Grails Maven Integration http://www.grails.org/Maven+Integration m2eclipse Plugin Homepage http://m2eclipse.codehaus.org/ m2eclipse Eclipse Update Site http://m2eclipse.sonatype.org/update-dev/ m2eclipse Documentation http://docs.codehaus.org/display/MAVENUSER/Dealing+with+Eclipse-based+IDE
  143. 143. Resources Archetype Guide http://maven.apache.org/guides/mini/guide-creating-archetypes.html Sonatype eBook Archetype Chapter http://propellors.net/maven/book/archetypes.html http://www.sonatype.com/books/maven-book/reference/archetypes.html Archetype create-from-project Mojo http://maven.apache.org/plugins/maven-archetype-plugin/create-from-project- mojo.html JavaWorld Reporting Article http://www.javaworld.com/javaworld/jw-02-2006/jw-0227-maven.html
  144. 144. Resources Maven Dependency Plugin http://maven.apache.org/plugins/maven-dependency-plugin/ Maven AntRun Plugin http://maven.apache.org/plugins/maven-antrun-plugin/ Maven Exec Plugin http://mojo.codehaus.org/exec-maven-plugin/usage.html SuperPOM in SVN http://svn.apache.org/viewvc/maven/components/tags/maven-2.0.9/maven-project/ src/main/resources/org/apache/maven/project/pom-4.0.0.xml?view=markup
  145. 145. Image Credits ‣ http://flickr.com/photos/chanchan222/2883910690/ ‣ http://flickr.com/photos/themarmot/3173506262/ ‣ http://commons.wikimedia.org/wiki/File:Napoleon4.jpg
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×