Maven 3.0 at Øredev

10,984 views
10,840 views

Published on

Matthew McCullough's Maven 3.0 presentation to Øredev 2010 in Malmö, Sweden.

Published in: Education, Technology
0 Comments
19 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
10,984
On SlideShare
0
From Embeds
0
Number of Embeds
18
Actions
Shares
0
Downloads
0
Comments
0
Likes
19
Embeds 0
No embeds

No notes for slide

Maven 3.0 at Øredev

  1. 1. Maven 3.0 What’s new in by Matthew McCullough, Ambient Ideas, LLC
  2. 2. In the beginner’s mind there are many possibilities. In the expert’s mind there are few.
  3. 3. In the beginner’s mind there are many possibilities. In the expert’s mind there are few.
  4. 4. This Talk
  5. 5. Maven and You ❖Who will enjoy this talk? ❖Current Maven user ❖Familiar with POM syntax ❖Interested in preparing for Maven 3.0 ❖Comfortable with betas
  6. 6. Maven and Me ❖ Tenure ❖ Using it for 8 years since 0.7 ❖ Contributing to the codebase via patches ❖ Authoring archetypes ❖ 30 open source how-to projects
  7. 7. Maven and Me ❖ Tenure ❖ Using it for 8 years since 0.7 ❖ Contributing to the codebase via patches ❖ Authoring archetypes ❖ 30 open source how-to projects ❖ Mentoring ❖ 3 virtual Sonatype classes a month ❖ Several on-site classes around the globe per year ❖ 30+ global conference and user group talks to date ❖ 50+ enterprise Maven-consulting clients
  8. 8. Maven and Me ❖ Tenure ❖ Using it for 8 years since 0.7 ❖ Contributing to the codebase via patches ❖ Authoring archetypes ❖ 30 open source how-to projects ❖ Mentoring ❖ 3 virtual Sonatype classes a month ❖ Several on-site classes around the globe per year ❖ 30+ global conference and user group talks to date ❖ 50+ enterprise Maven-consulting clients ❖ Writing ❖ O’Reilly: Maven The Definitive Guide by Tim O’Brien ❖ Promotional materials, testimonial on the back cover ❖ DZone Maven RefCard ❖ 8th most-downloaded card of all time
  9. 9. The Roadmap
  10. 10. 3.0
  11. 11. Compatibility ❖Tested against 100s of Maven 2 projects ❖Legacy simulation layers ❖Using for 6 months almost exclusively ❖450+ integration tests
  12. 12. 603!
  13. 13. Speed ❖Performance tuned ❖Benchmarks ❖ Disk I/O ❖ Network I/O ❖ CPU ❖ Memory
  14. 14. Maven Speed Test
  15. 15. Quick ❖ Faster execution ❖ 10% faster in the demo ❖ Multi-threaded downloads ❖ Parallel plugin execution ❖ Java 5 optimized builds
  16. 16. Efficient ❖ Memory conservative ❖ 73% less in the demo ❖ Tuned data structures
  17. 17. ❖Largely re-written for quality, flexibility ❖30% smaller code base ❖Continuous integration running test suite Code
  18. 18. Extensibility ❖Layers of abstraction ❖Plugin classloader partitioning ❖Plexus to Guice IOC rewrite ❖Fully embeddable ❖Basis for derived tools
  19. 19. How can you keep up with Maven 3?
  20. 20. http://maven.apache.org/docs/3.0/release-notes.html
  21. 21. http://delicious.com/matthew.mccullough/maven
  22. 22. POMs & Maven 3.0
  23. 23. POM XML Syntax ❖ No POM syntax changes for Maven 3.0 <project> <modelVersion>4.0.0</modelVersion> <groupId>com.ambientideas</groupId> <artifactId>sample-barestbones</artifactId> <version>1.0-SNAPSHOT</version> </project>
  24. 24. POM XML Validations ❖ Heavily validated against common mistakes ❖ Forward-test with Maven 3.0 ❖Switch back to 2.x for production ❖ 3.0 POMs run better on 2.x
  25. 25. POM XML Validations ❖Warns when plugin versions are not specified
  26. 26. “Plugin version omitted” warning
  27. 27. POM XML Validations ❖ Blocks duplicate dependencies ❖Examined in same POM only ❖Conflict resolution used otherwise <dependency> <artifactId>junit</modelVersion> <groupId>junit</groupId> <version>3.8.1</version> </dependency> ... <dependency> <artifactId>junit</modelVersion> <groupId>junit</groupId> <version>3.8.2</version> </dependency>
  28. 28. “Duplicate dependency” error
  29. 29. Help URLs ❖ Wiki page URLs now shown for all error messages
  30. 30. Help URLs ❖ Wiki page URLs now shown for all error messages
  31. 31. Parent POM References ❖ Parent POMs now prefer to resolve from repositories ❖Better consistency on multi-module builds ❖ Version-less parent references may be allowed (not ready yet) ❖Will require <relativePath> tag ❖MNG-624
  32. 32. <project> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.ambientideas</groupId> <artifactId>sample-multimodulejava-parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> </project>
  33. 33. <project> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.ambientideas</groupId> <artifactId>sample-multimodulejava-parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> </project>
  34. 34. <project> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.ambientideas</groupId> <artifactId>sample-multimodulejava-parent</artifactId> <relativePath>../</relativePath> </parent> </project>
  35. 35. Profiles Consolidated •Profiles.xml external file support removed •Folded into pom.xml •Already a best-practice •Necessary for Polyglot Maven
  36. 36. Parallel Builds
  37. 37. Parallel Build Approach •Examines reactor build plan •Threads up to what’s possible •Governed by your provided limits
  38. 38. https://cwiki.apache.org/MAVEN/parallel-builds-in-maven-3.html
  39. 39. Parallel Build Syntax •Four threads mvn -T 4 install
  40. 40. Parallel Build Syntax •Two threads per core mvn -T 2C install
  41. 41. Serial Building
  42. 42. Parallel Building
  43. 43. Artifact Behavior Changes
  44. 44. Maven 1.0 Deprecated • Maven 1.0 repository support removed <layout>legacy</layout>
  45. 45. SNAPSHOT Datestamps •Deprecated <uniqueVersion> false </uniqueVersion> •SNAPSHOTs now always deployed with date-stamps
  46. 46. Artifact Resolution Caching •Caches lookups whether found or missing •Stored in: ~/.m2/repo/.../<artifact>.lastUpdated •Sample contents: #Last modified on: Thu Dec 31 10:42:13 MST 2009 #Thu Dec 31 10:42:13 MST 2009 http://localhost:8081/nexus/content/groups/public=12333938 •Overridden by: mvn <phase> -U
  47. 47. Plugin Behavior Changes
  48. 48. Core Changes: Plugins ❖Plugin version auto-selection favors RELEASEs over SNAPSHOTs ❖Affects command-line invocation of plugins
  49. 49. #Maven 2.x #Will run the newest SNAPSHOT, if one is cached locally mvn archetype:generate #...actually running mvn org.apache.maven.plugins:maven-archetype-plugin:1.0-SNAPSHOT:generate #Maven 3.x #Will always run the newest RELEASE in Maven 3.x mvn archetype:generate #...actually running mvn org.apache.maven.plugins:maven-archetype-plugin:2.0:generate Command Line
  50. 50. Core Changes: Plugins ❖Plugins versions cannot be specified as RELEASE or LATEST ❖Affects pom.xml configuration and command line fully-qualified invocation
  51. 51. ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-toolchains-plugin</artifactId> <version>LATEST</version> </plugin> ... pom.xml
  52. 52. ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-toolchains-plugin</artifactId> <version>LATEST</version> </plugin> ... pom.xml
  53. 53. Core Changes: Plugins ❖Plugins only resolved from <pluginRepository> locations
  54. 54. http://cwiki.apache.org/MAVEN/maven-3x-compatibility-notes.html
  55. 55. Site Plugin ❖Near-complete rewrite ❖Separation of <reporting> from core Maven codebase ❖Preparation for Maven 3.1 pom.xml syntax changes
  56. 56. Not a technical rant on Maven vs. Ant
  57. 57. mvnshell
  58. 58. http://shell.sonatype.org/
  59. 59. http://shell.sonatype.org/
  60. 60. What is mvnshell? ❖High performance console ❖Maven 3.x add-on
  61. 61. The shell and its commands
  62. 62. Color highlighting
  63. 63. Speed of Builds
  64. 64. Performance of Shell ❖220% faster in the demo ❖No JVM warm-up time ❖Strategies for caching
  65. 65. Subcommands, archetypes
  66. 66. polyglot
  67. 67. http://polyglot.sonatype.org/
  68. 68. http://polyglot.sonatype.org/
  69. 69. What is polyglot Maven? ❖Maven 3 superset ❖A full distribution of Maven ❖Enabled by Maven 3 embedding ❖Multi-language mvn command
  70. 70. What is polyglot Maven? ❖POM file converter ❖translate tool ❖Any-to-Any language translation
  71. 71. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http:// www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http:// maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ambientideas</groupId> <artifactId>sample-dependency</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>Sample Project - One Dependency</name> <url>http://github.com/matthewmccullough/maven-training/</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project> pom.xml
  72. 72. Translating a POM from XML toYAML
  73. 73. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http:// www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http:// maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ambientideas</groupId> <artifactId>sample-dependency</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>Sample Project - One Dependency</name> <url>http://github.com/matthewmccullough/maven-training/</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project> pom.xml
  74. 74. modelVersion: 4.0.0 artifactId: sample-dependency groupId: com.ambientideas name: Sample Project - One Dependency packaging: jar url: http://github.com/matthewmccullough/maven-training/ version: 1.0-SNAPSHOT dependencies: - {artifactId: junit, groupId: junit, optional: false, scope: test, type: jar, version: 3.8.1} pom.yaml
  75. 75. (defproject main "com.ambientideas:sample-dependency:1.0-SNAPSHOT" :model-version "4.0.0" :add-default-plugins false :name "Sample Project - One Dependency" :packaging "jar" :url "http://github.com/matthewmccullough/maven-training/" :test-dependencies [["junit:junit:3.8.1"]]) pom.clj
  76. 76. project { m => m.artifactId = "sample-dependency" m.dependency { d => d.artifactId = "junit" d.groupId = "junit" d.optional = false d.scope = "test" d._type = "jar" d.version = "3.8.1" } m.groupId = "com.ambientideas" m.modelVersion = "4.0.0" m.name = "Sample Project - One Dependency" m.packaging = "jar" m.url = "http://github.com/matthewmccullough/maven-training/" m.version = "1.0-SNAPSHOT" } pom.scala
  77. 77. project { modelVersion '4.0.0' groupId 'com.ambientideas' artifactId 'sample-dependency' version '1.0-SNAPSHOT' name 'Sample Project - One Dependency' url 'http://github.com/matthewmccullough/maven-training/' dependencies { dependency { groupId 'junit' artifactId 'junit' version '3.8.1' scope 'test' } } } pom.groovy
  78. 78. Translating a POM and building from it
  79. 79. Polyglot DSLs ❖A true DSL framework ❖Maven lifecycle hooks ❖Can modify execution plan ❖Supplement the lifecycle
  80. 80. Polyglot Macros ❖Maven-specific macros ❖Allows for more concise POMs ❖Groovy polyglot showcasing this ❖Freeform scripting in Groovy
  81. 81. project { modelVersion '4.0.0' $artifact('com.ambientideas', 'sample-dependency’, '1.0-SNAPSHOT') name 'Sample Project - One Dependency' url 'http://github.com/matthewmccullough/maven-training/' dependencies { dependency('junit', 'junit’, '3.8.1', ‘test') } } pom.groovy with macros
  82. 82. Where did we start from again?
  83. 83. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http:// www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http:// maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ambientideas</groupId> <artifactId>sample-dependency</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>Sample Project - One Dependency</name> <url>http://github.com/matthewmccullough/maven-training/</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project> pom.xml
  84. 84. M2Eclipse
  85. 85. Upgrading M2Eclipse ❖Latest version, 0.10 ❖Code quality improvements ❖Performance increases ❖Packaging changes ❖Two distinct update sites ❖ Core: http://m2eclipse.sonatype.org/sites/m2e ❖ Extensions: http://m2eclipse.sonatype.org/sites/m2e-extras
  86. 86. Eclipse Versions Supported ❖3.4 ❖3.5 ❖3.6
  87. 87. Dependencies ❖ Visualizes conflicts ❖ Graph and text form ❖ Dependency resolution tree ❖ Answers “where is X being brought in from?”
  88. 88. Dependency conflicts
  89. 89. Dependencies ❖ Easy exclusions ❖ Uses Eclipse refactoring engine
  90. 90. Exclusions
  91. 91. Class Search ❖ Search the entire central repository for ❖ Artifact ❖ Package ❖ Classname ❖ Lucene database ❖ Incremental updates
  92. 92. Class Search
  93. 93. Resources
  94. 94. Free Books http://books.sonatype.com
  95. 95. Examples ❖Ambient sample projects ❖http://github.com/matthewmccullough/maven-training ❖Sonatype sample projects ❖http://www.sonatype.com/products/maven/ documentation/book-defguide
  96. 96. Maven 3.1
  97. 97. Maven 3.1
  98. 98. Maven 3.1 POM Changes ❖ Backwards compatibility by modelVersion ❖ Final identifier TBD for 3.1 POM syntax ❖ Allows 3.1 to read 3.0, 2.0 POMs <project> <modelVersion>4.0.0</modelVersion> <groupId>com.ambientideas</groupId> <artifactId>sample-barestbones</artifactId> <version>1.0-SNAPSHOT</version> </project>
  99. 99. Maven 3.1 POM Changes ❖pom.xml syntax changes ❖Site plugin takes over <reporting>
  100. 100. Maven 3.1 POM Changes ❖“Mixins” for direct dependencies ❖Sometimes desired over POM inheritance
  101. 101. Maven 3.1 POM Changes ❖Plugin security manager ❖settings.xml as default implementation
  102. 102. Summary
  103. 103. Summary •Validations •Performance •Compatibility •Toolchain •Shell •Polyglot •M2Eclipse
  104. 104. Maven 3.0 What’s new in Email Twitter Blog Matthew McCullough matthewm@ambientideas.com @matthewmccull http://ambientideas.com/blog
  105. 105. Maven 3.0 What’s new in Email Twitter Blog Matthew McCullough matthewm@ambientideas.com @matthewmccull http://ambientideas.com/blog
  106. 106. References
  107. 107. ❖Maven 3 Core ❖ Homepage ❖ http://maven.apache.org/ ❖ Source Code ❖ http://svn.apache.org/viewvc/maven/maven-3/trunk ❖ Wiki ❖ http://cwiki.apache.org/MAVEN/maven-3x.html ❖ Bug Tracking ❖ http://jira.codehaus.org/browse/MNG ❖ Compatibility ❖ http://cwiki.apache.org/MAVEN/maven-3x-compatibility-notes.html ❖ Blog Posts ❖ http://www.sonatype.com/people/2009/11/maven-3x-paving-the-desire-lines- part-two/ ❖ Bookmarks ❖ http://delicious.com/matthewmccullough/maven
  108. 108. ❖Maven 3 Site Plugin ❖ Source Code ❖ https://svn.apache.org/repos/asf/maven/plugins/branches/ maven-site-plugin-3.x/ ❖ Wiki ❖ http://cwiki.apache.org/MAVEN/maven-3x-and-site-plugin.html
  109. 109. ❖Maven Shell ❖ Source Code ❖ http://github.com/sonatype/mvnsh/ ❖ Wiki ❖ https://docs.sonatype.org/display/MVNSH ❖ Homepage ❖ http://shell.sonatype.org/
  110. 110. ❖Polyglot Maven ❖ Homepage ❖ http://polyglot.sonatype.org/ ❖ Source Code ❖ http://github.com/sonatype/polyglot-maven ❖ Wiki ❖ https://docs.sonatype.org/display/PMAVEN/ ❖ Groovy Macros ❖ https://docs.sonatype.org/display/PMAVEN/Groovy
  111. 111. ❖M2Eclipse ❖ Homepage ❖ http://m2eclipse.sonatype.org/ ❖ Update Sites ❖ http://m2eclipse.sonatype.org/sites/m2e ❖ http://m2eclipse.sonatype.org/sites/m2e-extras

×