An Introduction to Maven

6,279 views

Published on

Published in: Technology
0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,279
On SlideShare
0
From Embeds
0
Number of Embeds
14
Actions
Shares
0
Downloads
0
Comments
0
Likes
9
Embeds 0
No embeds

No notes for slide

An Introduction to Maven

  1. 1. An Introduction to Apache Author: Vadim Lotar (QC Backend) 2011
  2. 2. Agenda Automation Build Tool A bit of history Why Maven? An Introduction to Maven Drawbacks of Maven Best practices Maven in software development suite Examples Q&A
  3. 3. Automation Build Tool Since the early days of modern engineering, automation of build processes has been the key to:  Productivity improvements  Quality insurance  Eliminate dependencies on key personnel  Save time and money Why would software development be any different?
  4. 4. Automation Build Tool How do you really enable automation of build?  Build has to be reproducible  Build has to produce the final production artifact  Build has to be as easy to maintain as possible and well documented
  5. 5. Agenda Automation Build Tool A bit of history Why Maven? An Introduction to Maven Drawbacks of Maven Best practices Maven in software development suite Examples Q&A
  6. 6. A bit of history A simple script (.sh, .bat) is already a possible solution More advanced command-line tools have been available for a long time make created in 1977 at Bells Labs by Stuart Feldman. Still very much used nowadays Apache Ant created by James Duncan Davidson
  7. 7. A bit of historyTwo main categories in current tools: Scripting tools  Ant  Rake (Ruby based)  Gradle (Groovy based)  … many others Artifact oriented tools  Maven  Debian Package Creation
  8. 8. A bit of history Maven 1.x is now almost 12 years old project, mostly motionless since 2007 (I cannot find anybody still using it or committing to it) Maven 2.x was the de facto standard for Java and Java EE build  Most open source projects were switched to Maven for their build system  It’s now seven years old Maven 3.x is used in > 90% of Java (EE) startup applications.  It’s now two years old  Last release – ver. 3.0.3
  9. 9. Agenda Automation Build Tool A bit of history Why Maven? An Introduction to Maven Drawbacks of Maven Best practices Maven in software development suite Examples Q&A
  10. 10. Why Maven? If you are not already using it:  Now is the best moment to start being aware  Maven is mature  Maven is getting better and better  Maven can be used online and offline If you are already using it:  Hang on! The best is yet to come!  Focus on necessary things and don’t get frustrated by petty details
  11. 11. Agenda Automation Build Tool A bit of history Why Maven? An Introduction to Maven Drawbacks of Maven Best practices Maven in software development suite Examples Q&A
  12. 12. An Introduction to MavenMaven is a tool with multiple facets: a BUILD tool a DEPENDENCY MANAGEMENT tool a DOCUMENTATION tool
  13. 13. An Introduction to Maven Project Object Model pom.xml Maven’s working … Generated artifacts (jar, war, ear…), Documentation, statistics (test results, quality metrics, javadoc, web site)…
  14. 14. An Introduction to Maven A project can easily be cut into modules thanks to Maven By simply declaring project metadata and optionally configuring a few plug-ins, you can:  Build your project (compile, generate sources…)  Launch tests and gather results (Junit, TestNG, Selenium…etc)  Package (Jar, War, Ejb, War…etc)  Document and generate reports
  15. 15. An Introduction to MavenProject Object Model (POM) Basic project information  groupId, artifactId, version…  Inheritance, or Aggregation through sub-modules (will explain the difference later on) Build section  Project layout (sources and resources folders… etc)  Build plugins configuration Reporting section  Reports configuration Some other advanced environment settings
  16. 16. An Introduction to Maven
  17. 17. An Introduction to Maven A plug-in is made of a MOJO (Maven POJO) which is simply a java class with Maven- specific metadata. A plug-in can define goals and reports Goals can be called directly:  mvn plugin:goal Goals can be bound to one or multiple phases Reports are used during site generation  mvn site
  18. 18. An Introduction to Maven
  19. 19. An Introduction to Maven
  20. 20. An Introduction to Maven When you invoke a phase, Maven will go through all the phases until the one specified, executing the bound goals:  mvn package
  21. 21. An Introduction to Maven There are many more phases than in previous examples in the default lifecycle By default, all the basic necessary plug-ins for the build phase are already bound to phases It is easy to have information about plugins:  mvn help:describe So….. what’s left to do, and what’s all the fuss about the complexity of Maven?
  22. 22. An Introduction to MavenDependencies: A blessing and a curse Blessing:  Transitive dependencies  easier to find/discover/use java libraries Curse:  Transitive dependencies can rapidly trigger a dependency hell!  Harder to stabilize builds
  23. 23. An Introduction to Maven What really made Maven different from other builds systems in the first place? REPOSITORIES!!! Before Maven, it was really hard to find java libraries, and harder to ensure a coherent use of these libraries Nowadays, it’s still very hard to find some jars with a decent/coherent versioning, let alone to find their sources or javadocs
  24. 24. An Introduction to Maven Local repository:  Local cache for artifacts  Contain temporary build artifacts  It’s possible to erase it regularly  Very useful for offline builds By default in user home’s .m2/repository folder Can be moved to another place through Maven runtime’ settings.xml file $MAVEN_HOME/conf/settings.xml
  25. 25. An Introduction to Maven Corporate repository/proxy  Access via file:// and http://  The first necessary step towards a corporate use of maven The local and remote repositories are structured the same Even better: install a repository management tool  Can proxy external repositories  Can filter unwanted artifacts
  26. 26. An Introduction to Maven Public repositories  Good for dependencies’ harvesting  A lot of mis-configured dependencies  A lot of alpha/beta Maven plugins and libraries Be cautious when adding public repositories to a build process!  Should be proxied in corporate
  27. 27. An Introduction to MavenOther key features of Maven: POM Inheritance/Aggregation Archetypes Launching Tests … many more…
  28. 28. An Introduction to Maven POM – Project Object Model Super POM Inheritance Aggregation Inheritance vs Aggregation
  29. 29. An Introduction to MavenProject Archetypes You can build template projects and make them available as artifacts in the repositories  mvn archetype:create-from-project Allows to share best practices without neither inheritance nor aggregation  mvn archetype:generate Many Archetypes already configured in the default catalog You can easily build a custom or corporate catalog mvn archetype:generate –DarchetypeCatalog=http://www.corporate.com/archetypes.xml
  30. 30. An Introduction to MavenArchetype ArtifactIds Descriptionmaven-archetype-archetype An archetype which contains a sample archetype.maven-archetype-j2ee-simple An archetype which contains a simplifed sample J2EE application.maven-archetype-mojo An archetype which contains a sample a sample Maven plugin.maven-archetype-plugin An archetype which contains a sample Maven plugin.maven-archetype-plugin-site An archetype which contains a sample Maven plugin site.maven-archetype-portlet An archetype which contains a sample JSR-268 Portlet.maven-archetype-quickstart An archetype which contains a sample Maven project.maven-archetype-simple An archetype which contains a simple Maven project.maven-archetype-site An archetype which contains a sample Maven site which demonstrates some of the supported document types like APT, XDoc, and FML and demonstrates how to i18n your site.maven-archetype-site-simple An archetype which contains a sample Maven site.maven-archetype-webapp An archetype which contains a sample Maven Webapp project.
  31. 31. An Introduction to MavenLaunching Tests Maven allows to launch various types of tests:  Unit tests: Junit 3.x or 4.x, TestNG, …  UI Tests: Selenium, Canoo Webtest  Functional tests: Fitnesse, Greenpepper  WebServices tests: SOAPUi  And many more…
  32. 32. Agenda Automation Build Tool A bit of history Why Maven? An Introduction to Maven Drawbacks of Maven Best practices Maven in software development suite Examples Q&A
  33. 33. Drawbacks of Maven Library repositories are not always safe. Maven Conventions Hard to find some things about maven and plugins A huge output log Sequential build (Lyfecycle) Learning Maven is long in comparison of Ant.
  34. 34. Agenda Automation Build Tool A bit of history Why Maven? An Introduction to Maven Drawbacks of Maven Best practices Maven in software development suite Examples Q&A
  35. 35. Best practices Embrace the standardization brought by Maven, don’t fight it Use POM Inheritance and <dependencyManagement> (with import scope), <pluginManagement> Use a Repository Manager:  Sonatype Nexus: http://nexus.sonatype.org  Jfrog Artifactory: http://artifactory.jfrog.org  …
  36. 36. Best practices Keep your build as simple as possible Launch your builds regularly and possibly in a neutral zone Use the “dependency” and “versions” plugins Generate test statistics data and other metrics data in order to exploit them in Software quality tools:  Sonar: http://sonar.codehaus.org  Squale: http://www.squale.org  …
  37. 37. Agenda Automation Build Tool A bit of history Why Maven? An Introduction to Maven Drawbacks of Maven Best practices Maven in software development suite Examples Q&A
  38. 38. Maven in a Software developmentsuite Maven is now very well integrated in IDEs  NetBeans 6.5+ now has very good support for Maven  Eclipse 3.x has very good support also.  IntelliJ IDEA seems to have excellent support also (though this is why you pay for it isn’t it?) Maven works very well with Quality monitoring tools Continuous integration
  39. 39. References and ThanksDocumentation and information: Site http://maven.apache.org Plugins  http://maven.apache.org/plugins  http://mojo.codehaus.org/  http://code.google.com/  And many others… Project Wiki http://docs.codehaus.org/display/MAVEN/ Users’ Wiki http://docs.codehaus.org/display/MAVENUSER
  40. 40. References and ThanksBooks Free electronic editions: Definitive Guide: http://www.sonatype.com/books Better Builds with Maven: http://www.maestrodev.com/better-build-maven Upcoming book by Arnaud Héritier and Nicolas De Loof http://www.pearson.fr/livre/?GCOI=27440100730370Thanks Many thanks to Pierre-Antoine Grégoire for its presentation on YaJUG Thanks to Jason van Zyl for its Maven 3 presentation http://www.sonatype.com/people/author/jason

×