SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Planning and Managing Software Projects 2011-12



Maven

Emanuele Della Valle, Lecturer: Daniele Dell’Aglio
http://emanueledellavalle.org
What is Maven?
   Maven is a project management tool
         Build automation tool
         Deployment tool
         Documentation generator
         Report generator
         ...
   Even if the focus in on Java projects, other
    programming languages are supported (C#, Ruby,
    etc.)




Planning and Managing Software Projects – Emanuele Della Valle
Convention
   Maven exploits the «Convention over configuration»
    approach
         Assumption about the location of source code, test,
          resources
         Assumption about the location of the output
         Etc.
   In general the conventions can be customized by users
   Example: folder layout
                  src/main/java
                  src/main/resources
                  src/test/java
                  src/test/resources



(http://maven.apache.org/guides/introduction/introduction-to-the-standard-
directory-layout.html)
Planning and Managing Software Projects – Emanuele Della Valle
Project Object Model
    The key element is the Project Object Model (POM)
    It is a xml file (pom.xml) located in the root of the
     project folder
    It contains the description of the project and all the
     information required by Maven
    POM contains:
            Project coordinates
            Dependencies
            Plugins
            Repositories
    A POM can be easily generated through
                                      mvn archetype:generate


 Planning and Managing Software Projects – Emanuele Della Valle
Project coordinates
       It is the “passport” of the artifact
       The required information are:
             Model version: the version of the POM
             Group id: unique identificator of the group/organization
              that creates the artifact
             Artifact id: unique identificator of the artifact
             Version: the version of the artifact. If the artifact is a
              non-stable/under development component, -SNAPSHOT
              should be added after the version number
      Another important information is the packaging
             It influences the build lifecycles
             Core packaging: jar (default), pom, maven-plugin, ejb,
              war, ear, rar, par



    Planning and Managing Software Projects – Emanuele Della Valle
Project coordinates
<project>
   <modelVersion>4.0.0</modelVersion>
   <groupId>pmsp.maven</groupId>
   <artifactId>firstexample</artifactId>
   <version>0.1</version>
   <packaging>jar</packaging>
</project>




 Planning and Managing Software Projects – Emanuele Della Valle
Dependencies
   POM contains the description of the artifacts
    required by the project
   Each dependency contains
         The required artifact (identified by its coordinates)
         The scope: controls the inclusion in the application
          and the availability in the classpath
                compile (default): required for compilation, in the
                 classpath and packaged
                provided: required for compilation, in the classpath but not
                 packaged (e.g. servlet.jar)
                runtime: required for the execution but not for the
                 compilation (e.g. JDBC, SLF4J bridges)
                test: required only for testing, not packaged (e.g. JUnit)
                system: like provided but with an explicit folder location


Planning and Managing Software Projects – Emanuele Della Valle
Dependencies
   In general the dependency is transitive
         It depends on the scope!
          http://maven.apache.org/guides/introduction/introductio
          n-to-dependency-mechanism.html#Dependency_Scope
   If the project requires artifact A, and artifact A requires
    artifact B, then also artifact B will be included in the
    project
   Users can disable the transitivity through the exclusion
    command




Planning and Managing Software Projects – Emanuele Della Valle
Dependencies
…
<dependencies>
         <dependency>
              <groupId>junit</groupId>
              <artifactId>junit</artifactId>
              <version>4.10</version>
              <scope>test</scope>
         </dependency>
        …
    </dependencies>
…



Planning and Managing Software Projects – Emanuele Della Valle
Plugins and Goals
     The Maven core doesn't contain the logic to compile,
      test, package the software
     Those features are provided through plugins
       •    Examples: archetype, jar, compiler, surefire
     As dependencies, projects should declare what are the
      required plugins
...
<plugins>
   <plugin>
         <artifactId>maven-surefire-plugin</artifactId>
         <version>2.10</version>
   </plugin>
</plugins>
...

Planning and Managing Software Projects – Emanuele Della Valle
Goals
    Each plugin offers a set of goals
          A goal is an executable task
                                           plugin
                                                                  goal 1

                                                                  goal 2

                                                                  goal 3


 A goal can be invoked in the following way:
                                               mvn plugin:goal
 Example:
                                     mvn archetype:generate



 Planning and Managing Software Projects – Emanuele Della Valle
Phases and lifecycles
    A phase is a step in the build lifecycle, which is an
     ordered sequence of phases. [Apache Maven manual]
    Lifecycles can be used to execute mutliple operations
           A lifecycle models a sequence of operations
    Each step of a lifecycle is a phase
    When a lifecycle is executed, plugin goals are bound to
     the phases
            The goal bindings depends by the packaging!
    Built-in lifecycle
            default
            clean
            site

(http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html)
 Planning and Managing Software Projects – Emanuele Della Valle
Lifecycles: default (simplified)
                                                                  validate


                                                                  compile


                                                                    test


                                                              package


                                                         integration-test


                                                                   verify


                                                                   install


                                                                  deploy

 Planning and Managing Software Projects – Emanuele Della Valle
Lifecycles: default (simplified) - packaging jar

            validate
            compile                                • compiler:compile

                  test                             • surefire:test

           package                                 • jar:jar

 integration-test
               verify
               install                             • install:install

             deploy                                • deploy:deploy
 Planning and Managing Software Projects – Emanuele Della Valle
Lifecycles: default (simplified) - packaging pom

            validate
            compile
                  test
           package                                 • site:attach-descriptor

 integration-test
               verify
               install                             • install:install

             deploy                                • deploy:deploy
 Planning and Managing Software Projects – Emanuele Della Valle
Repositories
    Repositories are the places where dependencies and
     plugins are located
           They are declared into the POM
    When Maven runs, it connects to the repositories in
     order to retrieve the dependencies and the plugins
    There is a special repository that is built by Maven on
     the local machine
            It is located in these locations:
              –    Unix: ~/.m2/repository
              –    Win: C:%USER%.m2
      •     Its purpose is twofold:
              –   It is a cache
              –   Artifacts can be installed there (install:install) and be
                  available for the other artifacts



 Planning and Managing Software Projects – Emanuele Della Valle
Repositories
<repositories>
    <repository>
        <id>central</id>
        <name>Maven Repository Switchboard</name>
        <layout>default</layout>
        <url>http://repo1.maven.org/maven2</url>
        <snapshots>
             <enabled>false</enabled>
        </snapshots>
    </repository>
    ...
</repositories>
<pluginRepositories>
    <pluginRepository>
        ...
    </pluginRepository>
</pluginRepositories>

 Planning and Managing Software Projects – Emanuele Della Valle
References
 Maven http://maven.apache.org/guides/
 Apache Maven 2 (Dzone RefCard)
  http://refcardz.dzone.com/refcardz/apache-maven-2
 Maven: the complete reference (Sonatype)
  http://www.sonatype.com/books/mvnref-
  book/reference/
 Maven – The definitive Guide (O’Reilly)
  http://www.amazon.com/Maven-Definitive-Guide-
  Sonatype-Company/dp/0596517335




Planning and Managing Software Projects – Emanuele Della Valle

Weitere ähnliche Inhalte

Was ist angesagt?

Continuous Deployment Pipeline with maven
Continuous Deployment Pipeline with mavenContinuous Deployment Pipeline with maven
Continuous Deployment Pipeline with maven
Alan Parkinson
 
02 - Build and Deployment Management
02 - Build and Deployment Management02 - Build and Deployment Management
02 - Build and Deployment Management
Sergii Shmarkatiuk
 

Was ist angesagt? (20)

Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Java Builds with Maven and Ant
Java Builds with Maven and AntJava Builds with Maven and Ant
Java Builds with Maven and Ant
 
Drupal & Continous Integration - SF State Study Case
Drupal & Continous Integration - SF State Study CaseDrupal & Continous Integration - SF State Study Case
Drupal & Continous Integration - SF State Study Case
 
Build Automation using Maven
Build Automation using Maven Build Automation using Maven
Build Automation using Maven
 
Continuous delivery-with-maven
Continuous delivery-with-mavenContinuous delivery-with-maven
Continuous delivery-with-maven
 
Maven basics
Maven basicsMaven basics
Maven basics
 
Maven Overview
Maven OverviewMaven Overview
Maven Overview
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
 
Maven plugins, properties en profiles: Advanced concepts in Maven
Maven plugins, properties en profiles: Advanced concepts in MavenMaven plugins, properties en profiles: Advanced concepts in Maven
Maven plugins, properties en profiles: Advanced concepts in Maven
 
Automated Deployment with Maven - going the whole nine yards
Automated Deployment with Maven - going the whole nine yardsAutomated Deployment with Maven - going the whole nine yards
Automated Deployment with Maven - going the whole nine yards
 
Maven
MavenMaven
Maven
 
Continuous Deployment Pipeline with maven
Continuous Deployment Pipeline with mavenContinuous Deployment Pipeline with maven
Continuous Deployment Pipeline with maven
 
02 - Build and Deployment Management
02 - Build and Deployment Management02 - Build and Deployment Management
02 - Build and Deployment Management
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
Maven for Dummies
Maven for DummiesMaven for Dummies
Maven for Dummies
 
Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
 
Continuous Delivery Overview
Continuous Delivery OverviewContinuous Delivery Overview
Continuous Delivery Overview
 

Andere mochten auch (6)

Wapz
WapzWapz
Wapz
 
IMaRS - Incremental Materialization for RDF Streams (SR4LD2013)
IMaRS - Incremental Materialization for RDF Streams (SR4LD2013)IMaRS - Incremental Materialization for RDF Streams (SR4LD2013)
IMaRS - Incremental Materialization for RDF Streams (SR4LD2013)
 
Kapittel 15
Kapittel 15Kapittel 15
Kapittel 15
 
Learning for a New Leadership:The Collaborative Redesign of Lidera Programme
Learning for a New Leadership:The Collaborative Redesign of Lidera ProgrammeLearning for a New Leadership:The Collaborative Redesign of Lidera Programme
Learning for a New Leadership:The Collaborative Redesign of Lidera Programme
 
Kapittel 15
Kapittel 15Kapittel 15
Kapittel 15
 
RDF Stream Processing Models (RSP2014)
RDF Stream Processing Models (RSP2014)RDF Stream Processing Models (RSP2014)
RDF Stream Processing Models (RSP2014)
 

Ähnlich wie P&MSP2012 - Maven

Apache maven, a software project management tool
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management tool
Renato Primavera
 
Java build tools
Java build toolsJava build tools
Java build tools
Sujit Kumar
 
Maven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolMaven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension tool
elliando dias
 

Ähnlich wie P&MSP2012 - Maven (20)

Apache maven, a software project management tool
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management tool
 
Introduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS worldIntroduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS world
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Mavennotes.pdf
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topic
 
Learning Maven by Example
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
 
Maven
MavenMaven
Maven
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
 
Introduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOpsIntroduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOps
 
Maven in mulesoft
Maven in mulesoftMaven in mulesoft
Maven in mulesoft
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Java build tools
Java build toolsJava build tools
Java build tools
 
(Re)-Introduction to Maven
(Re)-Introduction to Maven(Re)-Introduction to Maven
(Re)-Introduction to Maven
 
Maven
MavenMaven
Maven
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
Maven
MavenMaven
Maven
 
Maven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolMaven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension tool
 

Mehr von Daniele Dell'Aglio

On correctness in RDF stream processor benchmarking
On correctness in RDF stream processor benchmarkingOn correctness in RDF stream processor benchmarking
On correctness in RDF stream processor benchmarking
Daniele Dell'Aglio
 
P&MSP2012 - Version Control Systems
P&MSP2012 - Version Control SystemsP&MSP2012 - Version Control Systems
P&MSP2012 - Version Control Systems
Daniele Dell'Aglio
 
P&MSP2012 - Logging Frameworks
P&MSP2012 - Logging FrameworksP&MSP2012 - Logging Frameworks
P&MSP2012 - Logging Frameworks
Daniele Dell'Aglio
 

Mehr von Daniele Dell'Aglio (20)

Distributed stream consistency checking
Distributed stream consistency checkingDistributed stream consistency checking
Distributed stream consistency checking
 
On web stream processing
On web stream processingOn web stream processing
On web stream processing
 
On a web of data streams
On a web of data streamsOn a web of data streams
On a web of data streams
 
Triplewave: a step towards RDF Stream Processing on the Web
Triplewave: a step towards RDF Stream Processing on the WebTriplewave: a step towards RDF Stream Processing on the Web
Triplewave: a step towards RDF Stream Processing on the Web
 
On unifying query languages for RDF streams
On unifying query languages for RDF streamsOn unifying query languages for RDF streams
On unifying query languages for RDF streams
 
RSEP-QL: A Query Model to Capture Event Pattern Matching in RDF Stream Proces...
RSEP-QL: A Query Model to Capture Event Pattern Matching in RDF Stream Proces...RSEP-QL: A Query Model to Capture Event Pattern Matching in RDF Stream Proces...
RSEP-QL: A Query Model to Capture Event Pattern Matching in RDF Stream Proces...
 
Summary of the Stream Reasoning workshop at ISWC 2016
Summary of the Stream Reasoning workshop at ISWC 2016Summary of the Stream Reasoning workshop at ISWC 2016
Summary of the Stream Reasoning workshop at ISWC 2016
 
On Unified Stream Reasoning
On Unified Stream ReasoningOn Unified Stream Reasoning
On Unified Stream Reasoning
 
On Unified Stream Reasoning - The RDF Stream Processing realm
On Unified Stream Reasoning - The RDF Stream Processing realmOn Unified Stream Reasoning - The RDF Stream Processing realm
On Unified Stream Reasoning - The RDF Stream Processing realm
 
Querying the Web of Data with XSPARQL 1.1
Querying the Web of Data with XSPARQL 1.1Querying the Web of Data with XSPARQL 1.1
Querying the Web of Data with XSPARQL 1.1
 
Augmented Participation to Live Events through Social Network Content Enrichm...
Augmented Participation to Live Events through Social Network Content Enrichm...Augmented Participation to Live Events through Social Network Content Enrichm...
Augmented Participation to Live Events through Social Network Content Enrichm...
 
An experience on empirical research about rdf stream
An experience on empirical research about rdf streamAn experience on empirical research about rdf stream
An experience on empirical research about rdf stream
 
A Survey of Temporal Extensions of Description Logics
A Survey of Temporal Extensions of Description LogicsA Survey of Temporal Extensions of Description Logics
A Survey of Temporal Extensions of Description Logics
 
RDF Stream Processing Models (SR4LD2013)
RDF Stream Processing Models (SR4LD2013)RDF Stream Processing Models (SR4LD2013)
RDF Stream Processing Models (SR4LD2013)
 
Ontology based top-k query answering over massive, heterogeneous, and dynamic...
Ontology based top-k query answering over massive, heterogeneous, and dynamic...Ontology based top-k query answering over massive, heterogeneous, and dynamic...
Ontology based top-k query answering over massive, heterogeneous, and dynamic...
 
On correctness in RDF stream processor benchmarking
On correctness in RDF stream processor benchmarkingOn correctness in RDF stream processor benchmarking
On correctness in RDF stream processor benchmarking
 
An Ontological Formulation and an OPM profile for Causality in Planning Appli...
An Ontological Formulation and an OPM profile for Causality in Planning Appli...An Ontological Formulation and an OPM profile for Causality in Planning Appli...
An Ontological Formulation and an OPM profile for Causality in Planning Appli...
 
P&MSP2012 - Version Control Systems
P&MSP2012 - Version Control SystemsP&MSP2012 - Version Control Systems
P&MSP2012 - Version Control Systems
 
P&MSP2012 - Unit Testing
P&MSP2012 - Unit TestingP&MSP2012 - Unit Testing
P&MSP2012 - Unit Testing
 
P&MSP2012 - Logging Frameworks
P&MSP2012 - Logging FrameworksP&MSP2012 - Logging Frameworks
P&MSP2012 - Logging Frameworks
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

P&MSP2012 - Maven

  • 1. Planning and Managing Software Projects 2011-12 Maven Emanuele Della Valle, Lecturer: Daniele Dell’Aglio http://emanueledellavalle.org
  • 2. What is Maven?  Maven is a project management tool  Build automation tool  Deployment tool  Documentation generator  Report generator  ...  Even if the focus in on Java projects, other programming languages are supported (C#, Ruby, etc.) Planning and Managing Software Projects – Emanuele Della Valle
  • 3. Convention  Maven exploits the «Convention over configuration» approach  Assumption about the location of source code, test, resources  Assumption about the location of the output  Etc.  In general the conventions can be customized by users  Example: folder layout  src/main/java  src/main/resources  src/test/java  src/test/resources (http://maven.apache.org/guides/introduction/introduction-to-the-standard- directory-layout.html) Planning and Managing Software Projects – Emanuele Della Valle
  • 4. Project Object Model  The key element is the Project Object Model (POM)  It is a xml file (pom.xml) located in the root of the project folder  It contains the description of the project and all the information required by Maven  POM contains:  Project coordinates  Dependencies  Plugins  Repositories  A POM can be easily generated through mvn archetype:generate Planning and Managing Software Projects – Emanuele Della Valle
  • 5. Project coordinates  It is the “passport” of the artifact  The required information are:  Model version: the version of the POM  Group id: unique identificator of the group/organization that creates the artifact  Artifact id: unique identificator of the artifact  Version: the version of the artifact. If the artifact is a non-stable/under development component, -SNAPSHOT should be added after the version number  Another important information is the packaging  It influences the build lifecycles  Core packaging: jar (default), pom, maven-plugin, ejb, war, ear, rar, par Planning and Managing Software Projects – Emanuele Della Valle
  • 6. Project coordinates <project> <modelVersion>4.0.0</modelVersion> <groupId>pmsp.maven</groupId> <artifactId>firstexample</artifactId> <version>0.1</version> <packaging>jar</packaging> </project> Planning and Managing Software Projects – Emanuele Della Valle
  • 7. Dependencies  POM contains the description of the artifacts required by the project  Each dependency contains  The required artifact (identified by its coordinates)  The scope: controls the inclusion in the application and the availability in the classpath  compile (default): required for compilation, in the classpath and packaged  provided: required for compilation, in the classpath but not packaged (e.g. servlet.jar)  runtime: required for the execution but not for the compilation (e.g. JDBC, SLF4J bridges)  test: required only for testing, not packaged (e.g. JUnit)  system: like provided but with an explicit folder location Planning and Managing Software Projects – Emanuele Della Valle
  • 8. Dependencies  In general the dependency is transitive  It depends on the scope! http://maven.apache.org/guides/introduction/introductio n-to-dependency-mechanism.html#Dependency_Scope  If the project requires artifact A, and artifact A requires artifact B, then also artifact B will be included in the project  Users can disable the transitivity through the exclusion command Planning and Managing Software Projects – Emanuele Della Valle
  • 9. Dependencies … <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> … </dependencies> … Planning and Managing Software Projects – Emanuele Della Valle
  • 10. Plugins and Goals  The Maven core doesn't contain the logic to compile, test, package the software  Those features are provided through plugins • Examples: archetype, jar, compiler, surefire  As dependencies, projects should declare what are the required plugins ... <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.10</version> </plugin> </plugins> ... Planning and Managing Software Projects – Emanuele Della Valle
  • 11. Goals  Each plugin offers a set of goals  A goal is an executable task plugin goal 1 goal 2 goal 3  A goal can be invoked in the following way: mvn plugin:goal  Example: mvn archetype:generate Planning and Managing Software Projects – Emanuele Della Valle
  • 12. Phases and lifecycles  A phase is a step in the build lifecycle, which is an ordered sequence of phases. [Apache Maven manual]  Lifecycles can be used to execute mutliple operations  A lifecycle models a sequence of operations  Each step of a lifecycle is a phase  When a lifecycle is executed, plugin goals are bound to the phases  The goal bindings depends by the packaging!  Built-in lifecycle  default  clean  site (http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html) Planning and Managing Software Projects – Emanuele Della Valle
  • 13. Lifecycles: default (simplified) validate compile test package integration-test verify install deploy Planning and Managing Software Projects – Emanuele Della Valle
  • 14. Lifecycles: default (simplified) - packaging jar validate compile • compiler:compile test • surefire:test package • jar:jar integration-test verify install • install:install deploy • deploy:deploy Planning and Managing Software Projects – Emanuele Della Valle
  • 15. Lifecycles: default (simplified) - packaging pom validate compile test package • site:attach-descriptor integration-test verify install • install:install deploy • deploy:deploy Planning and Managing Software Projects – Emanuele Della Valle
  • 16. Repositories  Repositories are the places where dependencies and plugins are located  They are declared into the POM  When Maven runs, it connects to the repositories in order to retrieve the dependencies and the plugins  There is a special repository that is built by Maven on the local machine  It is located in these locations: – Unix: ~/.m2/repository – Win: C:%USER%.m2 • Its purpose is twofold: – It is a cache – Artifacts can be installed there (install:install) and be available for the other artifacts Planning and Managing Software Projects – Emanuele Della Valle
  • 17. Repositories <repositories> <repository> <id>central</id> <name>Maven Repository Switchboard</name> <layout>default</layout> <url>http://repo1.maven.org/maven2</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> ... </repositories> <pluginRepositories> <pluginRepository> ... </pluginRepository> </pluginRepositories> Planning and Managing Software Projects – Emanuele Della Valle
  • 18. References  Maven http://maven.apache.org/guides/  Apache Maven 2 (Dzone RefCard) http://refcardz.dzone.com/refcardz/apache-maven-2  Maven: the complete reference (Sonatype) http://www.sonatype.com/books/mvnref- book/reference/  Maven – The definitive Guide (O’Reilly) http://www.amazon.com/Maven-Definitive-Guide- Sonatype-Company/dp/0596517335 Planning and Managing Software Projects – Emanuele Della Valle