SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
Introduction to Apache
Rajind Ruparathna
AdroitLogic
Outline
● What is Maven?
● Download and Installation
● Configuring Maven
● First Maven Project
● What is a POM?
● Using External Dependencies
● Project Lifecycle Management
● Using External Repositories
● Using Plugins
2
What is Maven?
Maven is essentially a project management tool and as such provides a way to
help with managing:
● Builds
● Documentation
● Reporting
● Dependencies
● SCM
● Releases
● Distribution
3
Download and Installation https://maven.apache.org/download.cgi
4
Configuring Maven
Maven configuration occurs at 3 levels:
● Installation - this is configuration added once for a Maven installation
● User - this is configuration specific to a particular user
● Project - most static configuration occurs in pom.xml
You can specify your user configuration in
${user.home}/.m2/settings.xml.
● Configuring your Local Repository
● Configuring a Proxy
● Security and Deployment Settings
5
Configuring your Local Repository
The location of your local repository can be changed in your user configuration.
The default value is ${user.home}/.m2/repository/.
Note: The local repository must be an absolute path.
6
Configuring Security and Deployment Settings
7
First Maven Project
To create our first Maven project we are going to use Maven's archetype
mechanism.
An archetype is defined as an original pattern or model from which all other things
of the same kind are made.
mvn -B archetype:generate 
-DarchetypeGroupId=org.apache.maven.archetypes 
-DgroupId=com.mycompany.app 
-DartifactId=my-app
8
First Maven Project contd.
9
What is a POM? - Project Object Model
● It is an XML file that contains information about the project and configuration
details used by Maven to build the project.
10
What is a POM? contd.
XML
Artifact Descriptor
Hierarchy
Dependencies
11
Using External Dependencies
● Transitive Dependencies
○ Excluded/Optional Dependencies
● Dependency Scope
● Dependency Management
12
Transitive Dependencies
There are two types of Maven
dependencies:
● Direct: These are dependencies defined
in your pom.xml file under the
<dependencies/> section.
● Transitive: These are dependencies
that are dependencies of your direct
dependencies.
13
Dependency Scope
Dependency scope is used to limit the transitivity of a dependency, and also to
affect the classpath used for various build tasks.
compile
This is the default scope, used if none is specified. Compile dependencies are
available in all classpaths of a project. Furthermore, those dependencies are
propagated to dependent projects.
provided
This is much like compile, but indicates you expect the JDK or a container to
provide the dependency at runtime. This scope is only available on the compilation
and test classpath, and is not transitive. 14
Dependency Scope contd.
runtime
This scope indicates that the dependency is not required for compilation, but is for
execution. It is in the runtime and test classpaths, but not the compile classpath.
test
This scope indicates that the dependency is not required for normal use of the
application, and is only available for the test compilation and execution phases.
This scope is not transitive.
system
This scope is similar to provided except that you have to provide the JAR which
contains it explicitly. The artifact is always available and is not looked up in a
repository. 15
Dependency Exclusions
Since maven resolves dependencies
transitively, it is possible for
unwanted dependencies to be
included in your project's classpath.
Therefore explicit dependency
exclusion can be used.
Excluded artifacts will not be added
to your project's classpath.
16
Project Lifecycle Management
Compiling application sources - mvn compile
Compile test sources and run unit tests - mvn test
Creating a JAR and installing it in my local repository - mvn package
-mvn install
Removing the target directory -mvn clean
17
Using External Repositories
A repository in Maven is used to hold
build artifacts and dependencies of
varying types.
There are strictly only two types of
repositories: local and remote
Offline: mvn -o package
Force Update: mvn install -U
18
Using Plugins
Whenever you want to customise the
build for a Maven project, this is done
by adding or reconfiguring plugins.
For this example, we will configure the
Java compiler to allow specific java
version ({java.version}) sources.
19
References
https://maven.apache.org/guides/getting-started/index.html
20

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Spring boot
Spring bootSpring boot
Spring boot
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Introduction to gradle
Introduction to gradleIntroduction to gradle
Introduction to gradle
 
Build Automation using Maven
Build Automation using Maven Build Automation using Maven
Build Automation using Maven
 
Jenkins CI
Jenkins CIJenkins CI
Jenkins CI
 
Tomcat Server
Tomcat ServerTomcat Server
Tomcat Server
 
(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines
 
Docker by Example - Basics
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics
 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
 
Maven Overview
Maven OverviewMaven Overview
Maven Overview
 
Jenkins tutorial for beginners
Jenkins tutorial for beginnersJenkins tutorial for beginners
Jenkins tutorial for beginners
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Webpack slides
Webpack slidesWebpack slides
Webpack slides
 
An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)
 

Ähnlich wie Introduction to Apache Maven

An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1MD Sayem Ahmed
 
Opendaylight SDN Controller
Opendaylight SDN ControllerOpendaylight SDN Controller
Opendaylight SDN ControllerSumit Arora
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topicGourav Varma
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using MavenScheidt & Bachmann
 
Maven in mulesoft
Maven in mulesoftMaven in mulesoft
Maven in mulesoftvenkata20k
 
#10 Calicut Mulesoft Meetup - Maven And Mule.pptx
#10 Calicut Mulesoft Meetup - Maven And Mule.pptx#10 Calicut Mulesoft Meetup - Maven And Mule.pptx
#10 Calicut Mulesoft Meetup - Maven And Mule.pptxAnoopRamachandran13
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 featuresAngel Ruiz
 
SE2018_Lec-22_-Continuous-Integration-Tools
SE2018_Lec-22_-Continuous-Integration-ToolsSE2018_Lec-22_-Continuous-Integration-Tools
SE2018_Lec-22_-Continuous-Integration-ToolsAmr E. Mohamed
 
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 worldDmitry Bakaleinik
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulMert Çalışkan
 
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 toolRenato Primavera
 

Ähnlich wie Introduction to Apache Maven (20)

A-Z_Maven.pdf
A-Z_Maven.pdfA-Z_Maven.pdf
A-Z_Maven.pdf
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
 
Maven
MavenMaven
Maven
 
Opendaylight SDN Controller
Opendaylight SDN ControllerOpendaylight SDN Controller
Opendaylight SDN Controller
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topic
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using Maven
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Introduction to maven
Introduction to mavenIntroduction to maven
Introduction to maven
 
Mavennotes.pdf
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
 
Maven in mulesoft
Maven in mulesoftMaven in mulesoft
Maven in mulesoft
 
#10 Calicut Mulesoft Meetup - Maven And Mule.pptx
#10 Calicut Mulesoft Meetup - Maven And Mule.pptx#10 Calicut Mulesoft Meetup - Maven And Mule.pptx
#10 Calicut Mulesoft Meetup - Maven And Mule.pptx
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 features
 
SE2018_Lec-22_-Continuous-Integration-Tools
SE2018_Lec-22_-Continuous-Integration-ToolsSE2018_Lec-22_-Continuous-Integration-Tools
SE2018_Lec-22_-Continuous-Integration-Tools
 
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
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
Maven overview
Maven overviewMaven overview
Maven overview
 
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
 
What is maven
What is mavenWhat is maven
What is maven
 

Kürzlich hochgeladen

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 

Kürzlich hochgeladen (20)

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 

Introduction to Apache Maven

  • 1. Introduction to Apache Rajind Ruparathna AdroitLogic
  • 2. Outline ● What is Maven? ● Download and Installation ● Configuring Maven ● First Maven Project ● What is a POM? ● Using External Dependencies ● Project Lifecycle Management ● Using External Repositories ● Using Plugins 2
  • 3. What is Maven? Maven is essentially a project management tool and as such provides a way to help with managing: ● Builds ● Documentation ● Reporting ● Dependencies ● SCM ● Releases ● Distribution 3
  • 4. Download and Installation https://maven.apache.org/download.cgi 4
  • 5. Configuring Maven Maven configuration occurs at 3 levels: ● Installation - this is configuration added once for a Maven installation ● User - this is configuration specific to a particular user ● Project - most static configuration occurs in pom.xml You can specify your user configuration in ${user.home}/.m2/settings.xml. ● Configuring your Local Repository ● Configuring a Proxy ● Security and Deployment Settings 5
  • 6. Configuring your Local Repository The location of your local repository can be changed in your user configuration. The default value is ${user.home}/.m2/repository/. Note: The local repository must be an absolute path. 6
  • 7. Configuring Security and Deployment Settings 7
  • 8. First Maven Project To create our first Maven project we are going to use Maven's archetype mechanism. An archetype is defined as an original pattern or model from which all other things of the same kind are made. mvn -B archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app 8
  • 10. What is a POM? - Project Object Model ● It is an XML file that contains information about the project and configuration details used by Maven to build the project. 10
  • 11. What is a POM? contd. XML Artifact Descriptor Hierarchy Dependencies 11
  • 12. Using External Dependencies ● Transitive Dependencies ○ Excluded/Optional Dependencies ● Dependency Scope ● Dependency Management 12
  • 13. Transitive Dependencies There are two types of Maven dependencies: ● Direct: These are dependencies defined in your pom.xml file under the <dependencies/> section. ● Transitive: These are dependencies that are dependencies of your direct dependencies. 13
  • 14. Dependency Scope Dependency scope is used to limit the transitivity of a dependency, and also to affect the classpath used for various build tasks. compile This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects. provided This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. This scope is only available on the compilation and test classpath, and is not transitive. 14
  • 15. Dependency Scope contd. runtime This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath. test This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases. This scope is not transitive. system This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository. 15
  • 16. Dependency Exclusions Since maven resolves dependencies transitively, it is possible for unwanted dependencies to be included in your project's classpath. Therefore explicit dependency exclusion can be used. Excluded artifacts will not be added to your project's classpath. 16
  • 17. Project Lifecycle Management Compiling application sources - mvn compile Compile test sources and run unit tests - mvn test Creating a JAR and installing it in my local repository - mvn package -mvn install Removing the target directory -mvn clean 17
  • 18. Using External Repositories A repository in Maven is used to hold build artifacts and dependencies of varying types. There are strictly only two types of repositories: local and remote Offline: mvn -o package Force Update: mvn install -U 18
  • 19. Using Plugins Whenever you want to customise the build for a Maven project, this is done by adding or reconfiguring plugins. For this example, we will configure the Java compiler to allow specific java version ({java.version}) sources. 19