Mastering Maven 2.0 In 1 Hour V1.3

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    5 Favorites

    Mastering Maven 2.0 In 1 Hour V1.3 - Presentation Transcript

    1. Mastering Maven ncrease your Mo Jo-tivity I by Matthew McCullough of Ambient Ideas, LLC
    2. Matthew
    3. http://refcardz.dzone.com/refcardz/apache-maven-2
    4. Maven use ing up on the sw
    5. Convention v e r o Configuration
    6. Default Goal
    7. Default Goal ‣ Often not set. ‣ Saves typing. ‣ Communicates author’s intended goal. ‣ Only one goal or phase allowed.
    8. mvn install
    9. <project> <groupId>com.ambientideas</groupId> <artifactId>sample-defaultgoal</artifactId> [...] <build> <defaultGoal>install</defaultGoal> </build> [...] </project>
    10. mvn install
    11. mvn install
    12. mvn
    13. Super Pom
    14. Super Pom ‣ Pseudo-invisible.
    15. Super Pom ‣ Pseudo-invisible. ‣ All projects inherit it.
    16. Super Pom ‣ Pseudo-invisible. ‣ All projects inherit it. ‣ Specifies file location defaults.
    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. <!-- 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. Super Pom ‣ Familiarize yourself with it. ‣ View it in SVN.
    20. Saving time with Archetypes
    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. $ mvn archetype:generate
    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. $ mvn archetype:create-from-project
    25. Archetype via Archetype ‣ “Template for templates”
    26. Archetype via Archetype ‣ “Template for templates” ‣ Can be selected from the archetype list.
    27. Archetype via Archetype ‣ “Template for templates” ‣ Can be selected from the archetype list. mvn archetype:generate
    28. $ mvn archetype:generate -DarchetypeGroupId=\"org.apache.maven.archetypes\" -DarchetypeArtifactId=maven-archetype-archetype -DarchetypeVersion=1.0 -DgroupId=com.ambientideas -DartifactId=mysamplearchetype
    29. Dependency Management
    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. How does Maven resolve versions?
    32. Nearest
    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. 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. Then highest version?
    36. Then highest version?
    37. Then sequential first at same distance
    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. 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. 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. 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. 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. 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. 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. Resolving Tree A:A:1.0 B:B:1.0 C:C:1.0 JU:JU:3.8.2 B:B:2.0
    46. Resolved Tree A:A:1.0 B:B:1.0 C:C:1.0 JU:JU:3.8.2
    47. We’ve resolved the version tree.
    48. How about the dependency graph?
    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. Resolved Graph A:A:1.0 B:B:1.0 C:C:1.0 JU:JU:3.8.2
    51. A dice roll for complex graphs?
    52. Declare desired versions
    53. Advertise authorized versions
    54. <*Management> ‣ <dependencyManagement> ‣ Inheritance for dependency versions.
    55. <*Management> ‣ <dependencyManagement> ‣ Inheritance for dependency versions. ‣ <pluginManagement> ‣ Inheritance for plugin versions and config.
    56. <dependencyManagement> and <pluginManagement> are essentially identical
    57. Minimizing declarations with <*Management>
    58. In the base pom.xml...
    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. <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. <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. <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. In the child pom.xml...
    64. <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> </plugin> </plugins>
    65. Dependency Lists ‣ List view ‣ mvn dependency:resolve ‣ Tree view ‣ mvn dependency:tree ‣ Plugin list view ‣ mvn dependency:resolve-plugins
    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. Dependency Analysis ‣ Analyze to help prune unneeded. ‣ mvn dependency:analyze
    68. Dependency Analysis ‣ See if overrides are colliding. ‣ mvn dependency:analyze-dep-mgt
    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. DeBugging
    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. $ 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. 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. Debug Unit Tests ‣ Waits on socket for debugger to connect. mvn test -Dmaven.surefire.debug
    75. Groovy Support
    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. 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. command line Help !
    79. Maven Help Plugin mvn help:describe -Dplugin=<anygoal> ‣ Lists and describes plugin goals.
    80. Maven Help Plugin mvn help:system ‣ Outputs environment variables and system properties.
    81. Maven Help Plugin mvn help:active-profiles ‣ See what profiles are being triggered by environment, files, params.
    82. Maven Help Plugin mvn help:effective-pom ‣ Outputs the resultant pom. ‣ Includes inherited sections.
    83. M2Eclipse
    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. mvn eclipse:eclipse File > Import > Existing ➊ Projects into Workspace Set up Eclipse Classpath Variable M2_REPO
    86. mvn eclipse:eclipse File > Import > Existing ➊ Projects into Workspace Set up Eclipse Classpath Variable M2_REPO
    87. mvn eclipse:eclipse te d File > Import > Existing a ➊ tdClasspath Projects into Workspace u O Set up Eclipse Variable M2_REPO
    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. 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. 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. 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. 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. Dependency Graph
    94. Exclusions
    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. Source Code Control Integration
    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. Maven SCM Support ‣ Dozens of SCM systems supported. ‣ CVS ‣ Subversion ‣ Git
    99. http://docs.codehaus.org/display/SCM/SCM+Matrix
    100. Maven SCM Support mvn release:prepare ‣ Increments all pom.xml version tags.
    101. Reactor Plugin
    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. Reactor Plugin In Use ‣ Resume multi-module build starting with this module. $ mvn reactor:resume -Dfrom=mymodule
    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. 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. Reactor Plugin In Use ‣ Build all modules that scm says had changed. ‣ Essentially, build “dirty”. $ mvn reactor:make-scm-changes
    107. Running Apps
    108. Exec Plugin ‣ Run any Java main class or external tool.
    109. Exec Plugin ‣ Run any Java main class or external tool. ‣ Builds classpath from pom dependencies.
    110. Exec Plugin ‣ Run any Java main class or external tool. ‣ Builds classpath from pom dependencies. ‣ Primarily for testing.
    111. $ mvn exec:java -Dexec.mainClass=\"com.foo.Main\"
    112. $ mvn exec:java -Dexec.mainClass=\"com.foo.Main\" or
    113. $ mvn exec:java -Dexec.mainClass=\"com.foo.Main\" or $ mvn exec:exec -Dexec.executable=\"winzip.exe\" -Dexec.args=\"myfile.txt\"
    114. Ant Integration
    115. Ant Build Generation Why? ‣ Dead simple. ‣ Great for backport/legacy situations.
    116. $ cd mymavenproj
    117. $ cd mymavenproj $ mvn ant:ant
    118. $ cd mymavenproj it! , th at’s $ mvn ant:ant Yes $ ls build.xml maven-build.xml maven-build.properties
    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. <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=\"${myspecialfolder}\"> <fileset dir=\"${myfiles}\"/> </copy> </tasks> </configuration> </execution> </executions> </plugin> </plugins>
    121. Sitesand Reports
    122. Site Generation ‣ Professional project web site
    123. Site Generation ‣ Professional project web site ‣ Templatizable
    124. Site Generation ‣ Professional project web site ‣ Templatizable ‣ Contributors
    125. Site Generation ‣ Professional project web site ‣ Templatizable ‣ Contributors ‣ Licenses
    126. Site Generation ‣ Professional project web site ‣ Templatizable ‣ Contributors ‣ Licenses ‣ Hyperlinked source ref
    127. Site Generation ‣ Professional project web site ‣ Templatizable ‣ Contributors ‣ Licenses ‣ Hyperlinked source ref ‣ Defect tracking
    128. Site Generation ‣ Professional project web site ‣ Templatizable ‣ Contributors ‣ Licenses ‣ Hyperlinked source ref ‣ Defect tracking ‣ Dependencies
    129. Site Generation ‣ Professional project web site ‣ Templatizable ‣ Contributors ‣ Licenses ‣ Hyperlinked source ref ‣ Defect tracking ‣ Dependencies ‣ Plugins
    130. Project Info
    131. Report Generation ‣ Unit test reports ‣ Test coverage reports ‣ Checkstyle and PMD ‣ Javadocs ‣ Tag list (TODO)
    132. Report
    133. What’s New?
    134. Maven 2.0.10 ‣ Stability. ‣ Unit and integration tests. ‣ End of the line for 2.0.X.
    135. Maven 2.1 ‣ Parallel downloads (Don Brown) ‣ Encrypted passwords ‣ Drop in replacement
    136. What’s Next?
    137. Maven 3.0 ‣ Encrypted passwords (from 2.1) ‣ Mercury engine ‣ Parallel downloads (determinate) ‣ New resolver ‣ Tyco OSGi bundle builder
    138. Build Nirvana
    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. 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. 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. 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. 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. 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. Image Credits ‣ http://flickr.com/photos/chanchan222/2883910690/ ‣ http://flickr.com/photos/themarmot/3173506262/ ‣ http://commons.wikimedia.org/wiki/File:Napoleon4.jpg

    + Matthew McCulloughMatthew McCullough, 6 months ago

    custom

    1037 views, 5 favs, 0 embeds more stats

    Presentation of Mastering Maven to the SDJUG team i more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1037
      • 1037 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 5
    • Downloads 70
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories