An Introduction to Maven Part 1

MD Sayem Ahmed
MD Sayem AhmedSenior Software Engineer em Immobilien Scout GmbH
An Introduction to
     Maven
What is Maven
●   A build tool.


●   A Project Management Tool.


●   An abstract container for running Build Tasks.


●   A tool providing guidelines for best practice development.
What is Maven(Contd.)
●   It is a tool to manage applications that graduate beyond simple and
    need to start finding consistent ways to manage and build large
    collections of independent modules and libraries which make use of
    tens of hundreds of third-party components.


●   According to the official definition -
            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
             plugin 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) plugins.
Convention over Configuration
●   Maven incorporates this concept by providing sensible default
    behavior for projects.


●   It goes further than just simple directory locations. Maven's core
    plugins apply a common set of conventions for compiling source
    code, packaging distributions, generating websites, and many other
    processes.


●   However, most of the defaults provided by Maven can be customized.
Conceptual Model of a Project
●   Maven maintains a model of project. It does not just compile source
    code into bytecode, it develops a description of a software project and
    assigns a unique set of co-ordinates to a project.


●   It helps to mange project's license, the developers and contributors to
    the project, other dependent sub-projects etc.
Installing Maven
●   Verify that you've installed Java in your system.


●   Download Maven.


●   Set up Maven (remember to set up JAVA_HOME and
    MAVEN_HOME, and add maven home directory to PATH).


●   Test your installation (mvn –version in Windows).


●   Google it if any problem occurs/ask in our group channel.
Creating a Simple Project
●   We will use the Maven Archetype plugin to generate a simple skeleton
    project.


●   Open up your command prompt/shell, go to a particular location
    where you want the project to be stored, and execute the following
    command and keep hitting ENTER for now to accept the default
    options. The whole command should be typed in one line -
            mvn archetype:generate -DgroupId=org.wikiengine.intro
             -DartifactId=intro -Dpackage=org.wikiengine.intro
             -Dversion=1.0-SNAPSHOT


●   Please be patient. It will require considerable amount of time to
    complete. You will also need internet connection.
Creating a Simple Project(Contd.)
●   An Archetype is defined as -
            An original model or type after which other similar things are
              patterned; a prototype.


●   A number of archetypes are available in Maven for anything from a
    simple Swing Application to a complex web application, and the
    archetype:generate offers a huge list of archetypes to choose from,
    which you just did when you kept hitting ENTER. Here, archetype is
    the plugin prefix, and generate is called a GOAL.
Generated Project Skeleton
●   Open up the intro folder. The directory structure should look
    something like this -
         ●   intro
                     ●   src
                               –   main
                                          ●   java
                                                     ●   ….
                                                              ●   App.java
                               –   test
                                          ●   java
                                                     ●   …
                                                              ●   AppTest.java
                     ●   pom.xml
Generated Project Skeleton(Contd.)
●   The Maven Archetype plugin creates a directory called intro that
    matches the artifactId. This is known as the project's Base Directory.


●   Every Maven project has what is known as a Project Object Model,
    or, POM, for short, in a file named pom.xml. This file describes the
    project, configure plugins, and declare dependencies.


●   Project's source code and resources are placed under src/main. This
    folder may contain some simple java classes and some properties file,
    or it may be the document root of a web application, or it may contain
    configuration files for an application server (remember Glassfish,
    anyone?). In a java project, Java classes are placed in src/main/java
    and classpath resources are placed in src/main/resources.
Generated Project Skeleton(Contd.)
●   Project's test cases are located in src/test. Under this directory, Java
    classes such as JUnit tests are placed in src/test/java, and classpath
    resources for tests are located in src/test/resources.


●   For the time being, the Maven Archetype plugin has generated a
    single Java class org.wikiengine.intro.App, which is a pretty simple
    Hello World program.
Building and Running the Project
●   Once again, open up your command prompt/shell and traverse into the
    project's Base Directory, which is intro in our case. Then execute the
    following command -
            mvn install

●   Be patient, it will take considerable amount of time in this case too.
    Also you will need to be connected to the internet.


●   After your build is successful, run the program to test it -
            java -cp target/intro-1.0-SNAPSHOT.jar
              org.wikiengine.intro.App
The POM File
●   Take a look at the generated pom.xml file. This is the most basic POM
    we will ever deal with for a Maven project, usually a POM is
    considerably more complex.


●   The first few elements – groupId, artifactId, packaging, version – are
    what is known as the Maven co-ordinates which uniquely identify a
    project.


●   name and url are descriptive elements of the POM providing a human
    readable name and associating the project with a web site.


●   The dependencies element defines a single, test-scoped dependency
    on a unit testing framework called JUnit.
The POM File(Contd.)
●   Maven will always execute against an effective POM. This effective
    POM is constructed from the current project's pom.xml, all parent
    POMs, a super-POM defined within Maven, user-defined settings, and
    active profiles. All projects ultimately extend super-POM, which
    defines a set of sensible default configuration settings.


●   To see the effective POM, run the following command in the project
    base directory -
           mvn help:effective-pom

●   You should see a much larger POM which exposes the default settings
    of Maven. This can come in handy while debugging.
What Have We Done So Far
●   A project is generated which consisted of a POM and some code
    assembled in the Maven standard directory layout. We generated this
    project by executing a plugin goal.


●   We then executed Maven with a lifecycle phase as an argument,
    which prompted Maven to execute a series of Maven plugin goals.


●   Lastly, we have installed a Maven artifact into our local repository.
Goals
●   Goals are unit of work in Maven. A goal is a specific task that
    contributes to the building and managing of a project. Goals may be
    executed as a standalone goal or along with other goals as part of a
    larger build.


●   Examples of goals include the compile goal in the Compiler plugin,
    which compiles all of the source code for a project, or the test goal of
    the Surefire plugin, which can execute unit tests.


●   When referring to a plugin goal, we often use the shorthand notation:
    pluginId:goalId (remember our archetype:generate portion of the
    command before?).
Goals(Contd.)
●   They define parameters that contain sensible default values. In our
    example, the goal stopped for some input from us because there were
    no sensible defaults for this case. If we had run the archetype:create
    goal, Maven would have assumed that we wanted to generate a new
    project using the default maven-archetype-quickstart archetype. This
    is also an example of the convention over configuration principle.


●   Each goal has access to the information defined in the project's POM.
    They always execute in the context of a POM.
Plugins
●   A Maven plugin is a collection of one or more goals. Example plugins
    are Compiler, Surefire, Jar etc.


●   The Maven Core basically does nothing when it comes to project
    build. It basically knows how to parse the command line, manage a
    classpath, parse a POM file, and download Maven plugins. All other
    important tasks are taken care of by the various plugins.


●   This ensures universal re-usability of common build logics.
Maven Lifecycle
●   The second command that we've executed contained a Lifecycle Phase
    as an argument.


●   Maven is based around the central concept of a Build Lifecycle. It is a
    list of named phases that can be used to give order to Goal Execution,
    wherein a phase represents a stage in the lifecycle. Goals are chosen
    and bound by the packaging type of the project being acted upon.


●   There are three built-in lifecycles – default, clean and site. The first
    one handles project deployment, the second one handles project
    cleaning, while the last one handles the creation of the project's site
    documentation. Each of these is defined by a different list of build
    phases. To see the total list, go here.
Maven Lifecycle(Contd.)
●   The default lifecycle contains quite a lot of build phases. They are
    executed sequentially to complete the default lifecycle.


●   To fully execute a whole lifecycle, you only need to invoke the last
    build phase to be executed. This is because if you call a build phase, it
    will execute not only that build phase, but also every build phase prior
    to the called build phase. So, for the default lifecycle, executing
            mvn deploy
    will cause the whole default lifecycle phases to be executed.


●   A build phase is basically made up of various goals as plugin goals
    can be attached to it.
Maven Lifecycle(Contd.)
●   As Maven moves through the phases in a lifecycle, it will execute the
    goals attached to each particular phase. Each phase may have zero or
    more goals attached to it. If it has no goals bound to it, it will not
    execute.


●   A goal which is not bound to any build phase could be executed
    outside of the build lifecycle by direct invocation (remember
    archetype:generate, anyone? ) .


●   The lifecycle is what allows a developer to jump from one Maven
    project to another without having to know very much about the details
    of each particular project's build.
Next Meeting Topics
●   Understanding Maven Coordinates, Repositories, Dependencies.


●   Customizing Maven, managing dependencies


●   Generating complex web application, adding Java EE dependencies.


●   Managing multi-module projects.
References/Acknowledgments
●   Maven by Example by Sonatype.


●   Official Maven Documentation.


●   Our handsome guy Sharif Shahnewaz's awesome slide.
1 de 23

Recomendados

Apache MavenApache Maven
Apache MavenRahul Tanwani
2.1K visualizações35 slides
An introduction to MavenAn introduction to Maven
An introduction to MavenJoao Pereira
7.8K visualizações78 slides
MavenMaven
MavenМарія Русин
1.9K visualizações49 slides
An Introduction to MavenAn Introduction to Maven
An Introduction to MavenVadym Lotar
13.9K visualizações40 slides
Maven OverviewMaven Overview
Maven OverviewFastConnect
8.5K visualizações29 slides
Introduction to MavenIntroduction to Maven
Introduction to MavenOnkar Deshpande
3.4K visualizações67 slides

Mais conteúdo relacionado

Mais procurados

Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - ExplainedSmita Prasad
1.1K visualizações46 slides
Java Builds with Maven and AntJava Builds with Maven and Ant
Java Builds with Maven and AntDavid Noble
2.4K visualizações56 slides
Maven pptMaven ppt
Maven pptnatashasweety7
4.6K visualizações21 slides
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overviewReturn on Intelligence
1.8K visualizações37 slides
Demystifying MavenDemystifying Maven
Demystifying MavenMike Desjardins
4.9K visualizações88 slides

Mais procurados(20)

Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
Smita Prasad1.1K visualizações
Java Builds with Maven and AntJava Builds with Maven and Ant
Java Builds with Maven and Ant
David Noble2.4K visualizações
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
Holasz Kati1.4K visualizações
Maven pptMaven ppt
Maven ppt
natashasweety74.6K visualizações
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
Return on Intelligence1.8K visualizações
Demystifying MavenDemystifying Maven
Demystifying Maven
Mike Desjardins4.9K visualizações
Introduction to Apache MavenIntroduction to Apache Maven
Introduction to Apache Maven
Rajind Ruparathna2.2K visualizações
Maven IntroductionMaven Introduction
Maven Introduction
Sandeep Chawla21.1K visualizações
Maven tutorialMaven tutorial
Maven tutorial
James Cellini2.1K visualizações
Introduction to mavenIntroduction to maven
Introduction to maven
Manos Georgopoulos1.2K visualizações
Maven basicsMaven basics
Maven basics
Vijay Krishnan Ramaswamy253 visualizações
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
Mike Ensor2.7K visualizações
Maven Maven
Maven
Khan625905 visualizações
Using Maven 2Using Maven 2
Using Maven 2
andyhot2.8K visualizações
MavenMaven
Maven
feng lee1.8K visualizações
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
Robert Burrell Donkin5.7K visualizações
MavenMaven
Maven
Chris Roeder2.3K visualizações
Introduction to MavenIntroduction to Maven
Introduction to Maven
Mindfire Solutions955 visualizações
Build Automation using Maven Build Automation using Maven
Build Automation using Maven
Ankit Gubrani3.7K visualizações
Development Tools - MavenDevelopment Tools - Maven
Development Tools - Maven
Bert Koorengevel477 visualizações

Similar a An Introduction to Maven Part 1

Jenkins advance topicJenkins advance topic
Jenkins advance topicGourav Varma
182 visualizações29 slides
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdfAnkurSingh656748
9 visualizações45 slides
What is mavenWhat is maven
What is mavensureshraj43
95 visualizações11 slides
tools cli javatools cli java
tools cli javaTiNguyn863920
4 visualizações62 slides

Similar a An Introduction to Maven Part 1(20)

Jenkins advance topicJenkins advance topic
Jenkins advance topic
Gourav Varma182 visualizações
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
AnkurSingh6567489 visualizações
What is mavenWhat is maven
What is maven
sureshraj4395 visualizações
tools cli javatools cli java
tools cli java
TiNguyn8639204 visualizações
MavenMaven
Maven
Jyothi Malapati514 visualizações
MavenMaven
Maven
Jyothi Malapati1.7K visualizações
Apache ANT vs Apache MavenApache ANT vs Apache Maven
Apache ANT vs Apache Maven
Mudit Gupta1.3K visualizações
Alpes Jug (29th March, 2010) - Apache MavenAlpes Jug (29th March, 2010) - Apache Maven
Alpes Jug (29th March, 2010) - Apache Maven
Arnaud Héritier1.5K visualizações
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management tool
Renato Primavera1.6K visualizações
MavenMaven
Maven
darshanvartak269 visualizações
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using Maven
Scheidt & Bachmann2.9K visualizações
Java build toolsJava build tools
Java build tools
Sujit Kumar79 visualizações
MavenMaven
Maven
Harshit Choudhary71 visualizações
Maven in mulesoftMaven in mulesoft
Maven in mulesoft
venkata20k141 visualizações
Apache mavenApache maven
Apache maven
Shreyas Lokkur416 visualizações
Fundamental of apache mavenFundamental of apache maven
Fundamental of apache maven
Rajesh Kumar1.3K visualizações
(Re)-Introduction to Maven(Re)-Introduction to Maven
(Re)-Introduction to Maven
Eric Wyles127 visualizações
Jenkins advance topicJenkins advance topic
Jenkins advance topic
Kalkey70 visualizações

Mais de MD Sayem Ahmed

Distributed systems - A PrimerDistributed systems - A Primer
Distributed systems - A PrimerMD Sayem Ahmed
477 visualizações105 slides
Factory Method PatternFactory Method Pattern
Factory Method PatternMD Sayem Ahmed
761 visualizações17 slides
A brief overview of java frameworksA brief overview of java frameworks
A brief overview of java frameworksMD Sayem Ahmed
14.4K visualizações42 slides
Restful web servicesRestful web services
Restful web servicesMD Sayem Ahmed
1.1K visualizações38 slides
An introduction to javascriptAn introduction to javascript
An introduction to javascriptMD Sayem Ahmed
1.5K visualizações47 slides
01. design pattern01. design pattern
01. design patternMD Sayem Ahmed
715 visualizações65 slides

Mais de MD Sayem Ahmed(6)

Distributed systems - A PrimerDistributed systems - A Primer
Distributed systems - A Primer
MD Sayem Ahmed477 visualizações
Factory Method PatternFactory Method Pattern
Factory Method Pattern
MD Sayem Ahmed761 visualizações
A brief overview of java frameworksA brief overview of java frameworks
A brief overview of java frameworks
MD Sayem Ahmed14.4K visualizações
Restful web servicesRestful web services
Restful web services
MD Sayem Ahmed1.1K visualizações
An introduction to javascriptAn introduction to javascript
An introduction to javascript
MD Sayem Ahmed1.5K visualizações
01. design pattern01. design pattern
01. design pattern
MD Sayem Ahmed715 visualizações

Último(20)

Use of Probiotics in Aquaculture.pptxUse of Probiotics in Aquaculture.pptx
Use of Probiotics in Aquaculture.pptx
AKSHAY MANDAL72 visualizações
STYP infopack.pdfSTYP infopack.pdf
STYP infopack.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego159 visualizações
Class 10 English  lesson plansClass 10 English  lesson plans
Class 10 English lesson plans
TARIQ KHAN189 visualizações
BYSC infopack.pdfBYSC infopack.pdf
BYSC infopack.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego160 visualizações
Universe revised.pdfUniverse revised.pdf
Universe revised.pdf
DrHafizKosar88 visualizações
Chemistry of sex hormones.pptxChemistry of sex hormones.pptx
Chemistry of sex hormones.pptx
RAJ K. MAURYA107 visualizações
7 NOVEL DRUG DELIVERY SYSTEM.pptx7 NOVEL DRUG DELIVERY SYSTEM.pptx
7 NOVEL DRUG DELIVERY SYSTEM.pptx
Sachin Nitave56 visualizações
Lecture: Open InnovationLecture: Open Innovation
Lecture: Open Innovation
Michal Hron94 visualizações
SIMPLE PRESENT TENSE_new.pptxSIMPLE PRESENT TENSE_new.pptx
SIMPLE PRESENT TENSE_new.pptx
nisrinamadani2159 visualizações
Class 10 English notes 23-24.pptxClass 10 English notes 23-24.pptx
Class 10 English notes 23-24.pptx
TARIQ KHAN74 visualizações
Narration lesson plan.docxNarration lesson plan.docx
Narration lesson plan.docx
TARIQ KHAN92 visualizações
Structure and Functions of Cell.pdfStructure and Functions of Cell.pdf
Structure and Functions of Cell.pdf
Nithya Murugan256 visualizações
Student Voice Student Voice
Student Voice
Pooky Knightsmith125 visualizações
Nico Baumbach IMR Media ComponentNico Baumbach IMR Media Component
Nico Baumbach IMR Media Component
InMediaRes1368 visualizações
Ch. 7 Political Participation and Elections.pptxCh. 7 Political Participation and Elections.pptx
Ch. 7 Political Participation and Elections.pptx
Rommel Regala56 visualizações
Women from Hackney’s History: Stoke Newington by Sue DoeWomen from Hackney’s History: Stoke Newington by Sue Doe
Women from Hackney’s History: Stoke Newington by Sue Doe
History of Stoke Newington117 visualizações
AI Tools for Business and StartupsAI Tools for Business and Startups
AI Tools for Business and Startups
Svetlin Nakov74 visualizações

An Introduction to Maven Part 1

  • 2. What is Maven ● A build tool. ● A Project Management Tool. ● An abstract container for running Build Tasks. ● A tool providing guidelines for best practice development.
  • 3. What is Maven(Contd.) ● It is a tool to manage applications that graduate beyond simple and need to start finding consistent ways to manage and build large collections of independent modules and libraries which make use of tens of hundreds of third-party components. ● According to the official definition - 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 plugin 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) plugins.
  • 4. Convention over Configuration ● Maven incorporates this concept by providing sensible default behavior for projects. ● It goes further than just simple directory locations. Maven's core plugins apply a common set of conventions for compiling source code, packaging distributions, generating websites, and many other processes. ● However, most of the defaults provided by Maven can be customized.
  • 5. Conceptual Model of a Project ● Maven maintains a model of project. It does not just compile source code into bytecode, it develops a description of a software project and assigns a unique set of co-ordinates to a project. ● It helps to mange project's license, the developers and contributors to the project, other dependent sub-projects etc.
  • 6. Installing Maven ● Verify that you've installed Java in your system. ● Download Maven. ● Set up Maven (remember to set up JAVA_HOME and MAVEN_HOME, and add maven home directory to PATH). ● Test your installation (mvn –version in Windows). ● Google it if any problem occurs/ask in our group channel.
  • 7. Creating a Simple Project ● We will use the Maven Archetype plugin to generate a simple skeleton project. ● Open up your command prompt/shell, go to a particular location where you want the project to be stored, and execute the following command and keep hitting ENTER for now to accept the default options. The whole command should be typed in one line - mvn archetype:generate -DgroupId=org.wikiengine.intro -DartifactId=intro -Dpackage=org.wikiengine.intro -Dversion=1.0-SNAPSHOT ● Please be patient. It will require considerable amount of time to complete. You will also need internet connection.
  • 8. Creating a Simple Project(Contd.) ● An Archetype is defined as - An original model or type after which other similar things are patterned; a prototype. ● A number of archetypes are available in Maven for anything from a simple Swing Application to a complex web application, and the archetype:generate offers a huge list of archetypes to choose from, which you just did when you kept hitting ENTER. Here, archetype is the plugin prefix, and generate is called a GOAL.
  • 9. Generated Project Skeleton ● Open up the intro folder. The directory structure should look something like this - ● intro ● src – main ● java ● …. ● App.java – test ● java ● … ● AppTest.java ● pom.xml
  • 10. Generated Project Skeleton(Contd.) ● The Maven Archetype plugin creates a directory called intro that matches the artifactId. This is known as the project's Base Directory. ● Every Maven project has what is known as a Project Object Model, or, POM, for short, in a file named pom.xml. This file describes the project, configure plugins, and declare dependencies. ● Project's source code and resources are placed under src/main. This folder may contain some simple java classes and some properties file, or it may be the document root of a web application, or it may contain configuration files for an application server (remember Glassfish, anyone?). In a java project, Java classes are placed in src/main/java and classpath resources are placed in src/main/resources.
  • 11. Generated Project Skeleton(Contd.) ● Project's test cases are located in src/test. Under this directory, Java classes such as JUnit tests are placed in src/test/java, and classpath resources for tests are located in src/test/resources. ● For the time being, the Maven Archetype plugin has generated a single Java class org.wikiengine.intro.App, which is a pretty simple Hello World program.
  • 12. Building and Running the Project ● Once again, open up your command prompt/shell and traverse into the project's Base Directory, which is intro in our case. Then execute the following command - mvn install ● Be patient, it will take considerable amount of time in this case too. Also you will need to be connected to the internet. ● After your build is successful, run the program to test it - java -cp target/intro-1.0-SNAPSHOT.jar org.wikiengine.intro.App
  • 13. The POM File ● Take a look at the generated pom.xml file. This is the most basic POM we will ever deal with for a Maven project, usually a POM is considerably more complex. ● The first few elements – groupId, artifactId, packaging, version – are what is known as the Maven co-ordinates which uniquely identify a project. ● name and url are descriptive elements of the POM providing a human readable name and associating the project with a web site. ● The dependencies element defines a single, test-scoped dependency on a unit testing framework called JUnit.
  • 14. The POM File(Contd.) ● Maven will always execute against an effective POM. This effective POM is constructed from the current project's pom.xml, all parent POMs, a super-POM defined within Maven, user-defined settings, and active profiles. All projects ultimately extend super-POM, which defines a set of sensible default configuration settings. ● To see the effective POM, run the following command in the project base directory - mvn help:effective-pom ● You should see a much larger POM which exposes the default settings of Maven. This can come in handy while debugging.
  • 15. What Have We Done So Far ● A project is generated which consisted of a POM and some code assembled in the Maven standard directory layout. We generated this project by executing a plugin goal. ● We then executed Maven with a lifecycle phase as an argument, which prompted Maven to execute a series of Maven plugin goals. ● Lastly, we have installed a Maven artifact into our local repository.
  • 16. Goals ● Goals are unit of work in Maven. A goal is a specific task that contributes to the building and managing of a project. Goals may be executed as a standalone goal or along with other goals as part of a larger build. ● Examples of goals include the compile goal in the Compiler plugin, which compiles all of the source code for a project, or the test goal of the Surefire plugin, which can execute unit tests. ● When referring to a plugin goal, we often use the shorthand notation: pluginId:goalId (remember our archetype:generate portion of the command before?).
  • 17. Goals(Contd.) ● They define parameters that contain sensible default values. In our example, the goal stopped for some input from us because there were no sensible defaults for this case. If we had run the archetype:create goal, Maven would have assumed that we wanted to generate a new project using the default maven-archetype-quickstart archetype. This is also an example of the convention over configuration principle. ● Each goal has access to the information defined in the project's POM. They always execute in the context of a POM.
  • 18. Plugins ● A Maven plugin is a collection of one or more goals. Example plugins are Compiler, Surefire, Jar etc. ● The Maven Core basically does nothing when it comes to project build. It basically knows how to parse the command line, manage a classpath, parse a POM file, and download Maven plugins. All other important tasks are taken care of by the various plugins. ● This ensures universal re-usability of common build logics.
  • 19. Maven Lifecycle ● The second command that we've executed contained a Lifecycle Phase as an argument. ● Maven is based around the central concept of a Build Lifecycle. It is a list of named phases that can be used to give order to Goal Execution, wherein a phase represents a stage in the lifecycle. Goals are chosen and bound by the packaging type of the project being acted upon. ● There are three built-in lifecycles – default, clean and site. The first one handles project deployment, the second one handles project cleaning, while the last one handles the creation of the project's site documentation. Each of these is defined by a different list of build phases. To see the total list, go here.
  • 20. Maven Lifecycle(Contd.) ● The default lifecycle contains quite a lot of build phases. They are executed sequentially to complete the default lifecycle. ● To fully execute a whole lifecycle, you only need to invoke the last build phase to be executed. This is because if you call a build phase, it will execute not only that build phase, but also every build phase prior to the called build phase. So, for the default lifecycle, executing mvn deploy will cause the whole default lifecycle phases to be executed. ● A build phase is basically made up of various goals as plugin goals can be attached to it.
  • 21. Maven Lifecycle(Contd.) ● As Maven moves through the phases in a lifecycle, it will execute the goals attached to each particular phase. Each phase may have zero or more goals attached to it. If it has no goals bound to it, it will not execute. ● A goal which is not bound to any build phase could be executed outside of the build lifecycle by direct invocation (remember archetype:generate, anyone? ) . ● The lifecycle is what allows a developer to jump from one Maven project to another without having to know very much about the details of each particular project's build.
  • 22. Next Meeting Topics ● Understanding Maven Coordinates, Repositories, Dependencies. ● Customizing Maven, managing dependencies ● Generating complex web application, adding Java EE dependencies. ● Managing multi-module projects.
  • 23. References/Acknowledgments ● Maven by Example by Sonatype. ● Official Maven Documentation. ● Our handsome guy Sharif Shahnewaz's awesome slide.