Maven 2 features


Published on

This presentation tries to show the main features in Maven 2

Published in: Technology, Business
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Maven 2 features

    1. 1. A Pragmatic View Presentation by Angel Ruiz Calvo
    2. 2. Index <ul><li>What is Maven 2? </li></ul><ul><li>What does it provide? </li></ul><ul><li>Comparison with Ant. </li></ul><ul><li>Examples. </li></ul><ul><li>Installation. </li></ul><ul><li>Conclusions. </li></ul><ul><li>References. </li></ul><ul><li>Questions. </li></ul>
    3. 3. What is Maven 2?
    4. 4. <ul><li>Formal definition: </li></ul><ul><ul><li>“ Maven is a project management tool which encompasses a project object model, a set of standards, a project lifecycle, a dependency management system, and logic for executing plug-in goals at defined phases in a lifecycle. When you use Maven, you describe your project using a well-defined project object model, Maven can then apply cross-cutting logic from a set of shared (or custom) plug-ins”. </li></ul></ul><ul><li>My definition: </li></ul><ul><ul><li>It is a project management tool that helps us in all the stages of the SDLC applying the principle of “Convention over Configuration” that simplifies many common issues involved in the development of any project. </li></ul></ul>What is Maven 2?
    5. 5. What does it provide?
    6. 6. What does it provide? <ul><li>Convention over configuration: </li></ul><ul><ul><li>Systems, libraries, and frameworks should assume reasonable defaults without requiring unnecessary configuration to &quot; just work &quot;. </li></ul></ul><ul><li>Under this premise it provides: </li></ul><ul><ul><li>Conceptual model of a project: P.O.M. </li></ul></ul><ul><ul><li>Plug-in based extensibility. </li></ul></ul><ul><ul><li>Standard project structure </li></ul></ul><ul><ul><li>Standard project identification. </li></ul></ul><ul><ul><li>Dependency Management </li></ul></ul><ul><ul><li>Repository Management </li></ul></ul><ul><ul><li>Project initialization: Archetypes. </li></ul></ul><ul><ul><li>IDE Portability and Integration. </li></ul></ul><ul><ul><li>Project configuration (JDK compilation level, SCM, Bug tracking, mailing lists, developers …). </li></ul></ul><ul><ul><li>Simplify and unify the process for documentation distribution and maintenance. </li></ul></ul>
    7. 7. What does it provide? <ul><li>Conceptual model of a project: P.O.M. </li></ul><ul><ul><li>P.O.M. = Project Object Model. </li></ul></ul><ul><ul><li>Maven projects are describes using a single file called pom.xml </li></ul></ul><ul><ul><li>This conceptual model is described using an XMLSchema. </li></ul></ul><ul><ul><li>Within this P.O.M. file you can define the following project information: </li></ul></ul><ul><ul><ul><li>General project info: name, artifact, … </li></ul></ul></ul><ul><ul><ul><li>Customized configuration for each SDLC step: packaging, jdk, … </li></ul></ul></ul><ul><ul><ul><li>Dependencies. </li></ul></ul></ul><ul><ul><ul><li>External tools: </li></ul></ul></ul><ul><ul><ul><ul><li>Mailing lists. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>S.C,M. tool. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Bug tracking </li></ul></ul></ul></ul><ul><ul><ul><li>Repository configuration: usually delegated on settings.xml file </li></ul></ul></ul><ul><ul><ul><li>… </li></ul></ul></ul>
    8. 8. What does it provide? <ul><li>Conceptual model of a project: P.O.M. </li></ul>
    9. 9. What does it provide? <ul><li>Plug-in based extensibility </li></ul><ul><ul><li>Maven has been designed to delegate most responsibility to a set of Maven Plugins which can affect the Maven Lifecycle and offer access to goals. </li></ul></ul><ul><ul><li>mvn war:war </li></ul></ul>Plug-in name Goal
    10. 10. What does it provide? <ul><li>Plug-in based extensibility </li></ul><ul><ul><li>The Maven Lifecycle. </li></ul></ul>
    11. 11. What does it provide? <ul><li>Plug-in based extensibility </li></ul><ul><ul><li>The real value. </li></ul></ul>Plug-ins Core <ul><li>Clean </li></ul><ul><li>Compiler </li></ul><ul><li>Deploy </li></ul><ul><li>Install </li></ul><ul><li>Resources </li></ul><ul><li>Site </li></ul><ul><li>Surefire </li></ul><ul><li>Verifier </li></ul><ul><li>… </li></ul>Tools <ul><li>Ant </li></ul><ul><li>Antlr </li></ul><ul><li>Antrun </li></ul><ul><li>Archetype </li></ul><ul><li>Assembly </li></ul><ul><li>Help </li></ul><ul><li>Release </li></ul><ul><li>SCM </li></ul><ul><li>XDoclet </li></ul><ul><li>… </li></ul><ul><li>Changelog </li></ul><ul><li>Changes </li></ul><ul><li>Checkstyle </li></ul><ul><li>Clover </li></ul><ul><li>Javadocs </li></ul><ul><li>PMD </li></ul><ul><li>Surefire-reports </li></ul><ul><li>… </li></ul>Reporting <ul><li>Cargo </li></ul><ul><li>Jaxme </li></ul><ul><li>Jetty </li></ul><ul><li>Tomcat </li></ul><ul><li>… </li></ul><ul><li>Ear </li></ul><ul><li>Ejb </li></ul><ul><li>Jar </li></ul><ul><li>Rar </li></ul><ul><li>War </li></ul><ul><li>… </li></ul><ul><li>Eclipse </li></ul><ul><li>IDEA </li></ul><ul><li>… </li></ul>Others Packaging Integration
    12. 12. What does it provide? <ul><li>Standard project structure : </li></ul><ul><li>Flexible. </li></ul><ul><li>Clean </li></ul><ul><li>Standard. </li></ul><ul><li>Easy to understand. </li></ul>
    13. 13. What does it provide? <ul><li>Standard project identification </li></ul><ul><ul><li>Artifact = maven project coordinates </li></ul></ul><ul><ul><li>Essential for dependency management. </li></ul></ul><project> <modelVersion>4.0.0</modelVersion> <groupId> </groupId> <artifactId> sra.commons </artifactId> <version> 0.0.1-SNAPSHOT </version> </project> groupId artifactId version
    14. 14. What does it provide? <ul><li>Standard project identification </li></ul><ul><ul><li>Versioning nomenclature system: </li></ul></ul>X Y Z This identifier is used when the project is currently under active development . artifactId version Package (JAR / WAR / EAR) sra-commons - 0.0.1 - SNAPSHOT .jar <ul><li>Bugfixes </li></ul><ul><li>Minor: fixes and adds </li></ul><ul><li>Mayor: no backward compatibility </li></ul>
    15. 15. What does it provide? <ul><li>Standard project identification </li></ul><ul><ul><li>How can we look for artifacts: http:// / </li></ul></ul>
    16. 16. What does it provide? <ul><li>Dependency Management </li></ul><ul><ul><li>Based on maven project coordinates. </li></ul></ul><ul><ul><li>It also implies a new and important parameter called Dependency Scope </li></ul></ul><project> … <dependencies> <dependency> <groupId> </groupId> <artifactId> sra.commons </artifactId> <version> 0.0.1-SNAPSHOT </version> <scope> compile </scope> </dependency> … </dependencies> </project> <ul><li>compile (default) </li></ul><ul><li>provided </li></ul><ul><li>runtime </li></ul><ul><li>test </li></ul><ul><li>system </li></ul>
    17. 17. What does it provide? <ul><li>Dependency Management </li></ul><ul><ul><li>There are some other concepts regarding dependency management: </li></ul></ul><ul><ul><ul><li>Transitive dependencies: </li></ul></ul></ul><ul><ul><ul><li>Optional dependencies: </li></ul></ul></ul><ul><li>Conflict resolution and dependency exclusion: </li></ul><ul><li>Dependency version range: </li></ul><ul><li>Multi-module projects: </li></ul>Dependency A Dependency B Dependency C
    18. 18. What does it provide? <ul><li>Repository Management </li></ul><ul><ul><li>With this feature you won’t have to maintain all the libs you are using in your SCM tool and you will reference them from a single common point. </li></ul></ul><ul><ul><li>By default Maven uses a local repository that is fed from the Maven Central repository or any other public Maven repository on the Internet, you may have configured in your settings.xml file. </li></ul></ul><ul><ul><li>By default this local repository is at ${user_home}/.m2/repository , but it is configurable. </li></ul></ul><ul><ul><li>In order to avoid multiple internet access to download the same file and also to get faster download speed we will use a Repository Manager that acts like a proxy between our office and the public Maven repositories. </li></ul></ul><ul><ul><li>It also provides a good platform to have all the company releases available and well identified. </li></ul></ul>
    19. 19. What does it provide? <ul><li>Repository Management </li></ul><ul><ul><li>The chosen repository management tool is called NEXUS from Sonatype: http://actdec01:8081/nexus </li></ul></ul>
    20. 20. What does it provide? <ul><li>Project initialization: Archetypes </li></ul><ul><ul><li>An archetype is a template for a Maven project which is used by the Maven Archetype plug-in to create new projects. </li></ul></ul><ul><ul><li>Archetypes can also be useful within an organization that wants to encourage standards across a series of similar and related projects. </li></ul></ul><ul><ul><li>mvn archetype:create -DgroupId=org.apache.maven.archetypes </li></ul></ul><ul><ul><li>-DartifactId=maven-archetype-webapp </li></ul></ul>
    21. 21. What does it provide? <ul><li>IDE Portability and Integration </li></ul><ul><ul><li>Tools like Eclipse, NetBeans, and IntelliJ now have a common place to find information about a project. Before the advent of Maven, every IDE had a different way to store what was essentially a custom Project Object Model (POM). Maven has standardized this description, and while each IDE continues to maintain custom project files, they can be easily generated from the model. </li></ul></ul><ul><ul><li>Integration can be performed in both ways: </li></ul></ul><ul><ul><ul><li>Maven plugin: </li></ul></ul></ul><ul><ul><ul><li>IDE plugin: </li></ul></ul></ul><ul><ul><li>mvn eclipse:eclipse </li></ul></ul>Built-in plug-in Built-in plug-in
    22. 22. What does it provide? <ul><li>Simplify and unify the process for documentation distribution and maintenance </li></ul><ul><ul><li>Maven site plug-in + reports </li></ul></ul>
    23. 23. Comparison with Ant
    24. 24. Comparison with Ant <ul><li>Two complementary tools </li></ul><ul><ul><li>Maven is definitely better for all the tasks related to the project building process. </li></ul></ul><ul><ul><li>Ant is better for all the rest programmatic tasks. </li></ul></ul>Maven has conventions, it already knew where your source code was because you followed the convention. It put the bytecode in target/classes, and it produced a JAR file in target. Ant doesn't have formal conventions like a common project directory structure, you have to tell Ant exactly where to find the source and where to put the output. Informal conventions have emerged over time, but they haven't been codified into the product. Maven has a lifecycle, which you invoked when you executed mvn install. This command told Maven to execute the a series of sequence steps until it reached the lifecycle. As a side-effect of this journey through the lifecycle, Maven executed a number of default plugin goals which did things like compile and create a JAR. Ant doesn't have a lifecycle, you had to define goals and goal dependencies. You had to attach a sequence of tasks to each goal manually Maven is declarative . All you had to do was create a pom.xml file and put your source in the default directory. Maven took care of the rest. Ant is procedural , you have to tell Ant exactly hat to do and when to do it. You had to tell it to compile, then copy, then compress …
    25. 25. Comparison with Ant <ul><li>Comparison thorough and example to build a jar file </li></ul><ul><ul><li>mvn package </li></ul></ul>
    26. 26. Examples
    27. 27. Installation
    28. 28. Installation <ul><li>Steps to install Maven </li></ul><ul><ul><li>Download the latest version of Maven (currently is 2.0.9). </li></ul></ul><ul><ul><li>Unzip the file. </li></ul></ul><ul><ul><li>Put the bin folder into the system path variable. </li></ul></ul><ul><ul><li>Execute the following command to check that the mvn command is available: </li></ul></ul><ul><ul><li>Download the latest settings.xml file from the SRA wiki and place it at ${user_home}/.m2 </li></ul></ul><ul><ul><li>The repository will be at C:.m2 epository </li></ul></ul><ul><ul><li>You also can find this instructions at the SRA Wiki. </li></ul></ul><ul><ul><li>mvn -version </li></ul></ul>
    29. 29. Conclusions
    30. 30. Conclusions <ul><li>Do not spend too much time defining procedures that are already modeled in Maven. </li></ul><ul><li>Maven is the result of many experienced professionals. </li></ul><ul><li>Maven is unquestionably linked to the following concepts: </li></ul>methodology standarization productivity agility usability quality control
    31. 31. References
    32. 32. References <ul><li>Maven portal </li></ul><ul><li>Maven: The definitive guide </li></ul><ul><li>Better builds with Maven </li></ul><ul><li>m2Eclipse plug-in </li></ul>
    33. 33. Questions