SlideShare una empresa de Scribd logo
1 de 15
Descargar para leer sin conexión
Apache Maven (3.0+)
Basic introduction
Dec.22.2013
Boy.Wang
Jar Hell & Plugin Hell
cosmos-saje
cosmos-lib saje
cosmos-core
xerces fscript fractal-adl dream-annot dream-core
antlr fractal-util julia-mixins perseus-cache
task-deployment julia-asm aval
fractal-rmi
easymock
developing project
intermediate depex
final depex
Main Purpose
1. Single project producing a single type.
2. Standard life-cycles and naming conventions.
3. Version and dependency management.
4. Repositories: several remote and one local, it means no
more externals or lib and no more jars in developer's
directories.
groupId artifactId version
Maven Working Flow
Maven
(core)
~/.m2/
repository
pom.xml
download
parse connect
plugins
libs artifacts
artifacts
use
The core of Maven consists of a very basic shell that knows only how to parse the command line, manage a
classpath, parse a POM file and download Maven plugins as needed.
Core Concepts
1. What is pom.xml?
2. What is Maven plugin and goal?
e.g. mvn archetype:generate -DgroupId=org.simple -DartifactId=simple
3. What is Maven lifecycle and phase?
e.g. mvn install
4. What is Maven coordinate?
5. What is Maven repositories and dependency?
6. What is Maven artifact?
mvn [options] [goal(s)] [phase(s)]
1. A Maven project is simply a folder that contains a pom.xml.
2. Every pom.xml implicitly inherits from Super POM.
http://maven.apache.org/ref/3.0.5/maven-model-builder/super-pom.html
pom.xml (Project Object Model)
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.demo</groupId>
<artifactId>myapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>myapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
SAMPLE
Maven Plugin and Goal
1. A plugin is a collection of one or more goals.
a. Plugin can be written in Java, Ant or Ruby.
b. e.g. Jar plugin contains goals for creating JAR files.
c. e.g. Compiler plugin contains goals for compiling
source code and unit test.
2. A goal is a specific task that can be executed.
% mvn archetype:generate -DgroupId=xxx.yyy -DartifactId=simple
plugin's identifier goal's parameters
goal's identifier
Maven Lifecycle and Phase
1. Phase may have zero or more goals bound to it.
2. Lifecycle is the definition of an ordered list of phases which is
executed sequentially.
% mvn resources:resources 
compiler:compile 
resources:testResources 
compiler:testCompile 
surefire:test 
jar:jar 
install:install 
% mvn install
phase's identifier Is the same with...
Lifecycle is just like a lazy package that is made of Phases. It helps you to execute multiple Goals sequentially.
% mvn compile
generate-sources
compile
test-compile
test
package
install
deploy
Phase Plugin:Goal
ear:generate...
compiler:compile
compiler:testCompile
surefire:test
jar:jar
install:install
deploy:deploy
lifecycle:
generate-source -> compile
lifecycle:
generate-source -> compile -> ... -> deploy
% mvn deploy
Maven Coordinate
Maven coordinates define a set of identifiers which can be
used to uniquely identify a project.
<project ...>
...
...
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
<groupId>org.eclipse.cdt</groupId>
<artifactId>cdt-parent</artifactId>
<packaging>jar</packaging>
<version>8.3.0-SNAPSHOT</version>
This packaging element affects the goals required by phases.
Maven Repositories and Depex
1. When you run Maven for the first time, you will notice that Maven
downloads a number of files from a remote Maven repository. In
Maven, artifacts and plugins are retrieved from a remote
repository when they are needed.
2. Maven uses the local repository to share dependencies across
local projects.
Maven publishes a JAR file and a slightly modified version of the project’s
pom.xml file in the local repository. Storing a POM file in the repository gives
other projects information about this project, most importantly what
dependencies it has.
% mvn install
Maven Artifact
An Maven artifact is a file that is produced by a build
execution and represents an application binary. e.g.
1. A project's library: JAR, WAR, EAR, ZIP, ....
2. Maven plugin: A JAR application to execute build
executions.
3. Maven archetype: A JAR application to create a Maven
project template.
4. Project metafile: pom.xml.
Summary
1. A goal is a "unit of work". It is a basic execution unit and
its behavior can be configured.
2. A phase is made up of goals and a lifecycle is made up of
phases.
3. Higher level of reusability between builds.
4. Maven is a build system not just a build tool.
Appendix
Reference
1. Free Books
a. http://www.sonatype.com/resources/books/maven-by-example
b. http://www.sonatype.com/resources/books/maven-the-complete-reference
2. Maven Lifecycle Reference
a. http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference
b. http://books.sonatype.com/mvnref-book/reference/lifecycle-sect-common-goals.html
3. Maven C/C++ Plugin
a. http://duns.github.io/maven-nar-plugin/

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
 
Learning Maven by Example
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
 
Liferay maven sdk
Liferay maven sdkLiferay maven sdk
Liferay maven sdk
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
Maven
MavenMaven
Maven
 
Apache Maven In 10 Slides
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An 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
 
Maven basics
Maven basicsMaven basics
Maven basics
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Using Maven 2
Using Maven 2Using Maven 2
Using Maven 2
 

Similar a Note - Apache Maven Intro

Introduction To Maven2
Introduction To Maven2Introduction To Maven2
Introduction To Maven2Shuji Watanabe
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialRaghavan Mohan
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 featuresAngel Ruiz
 
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
 
Maven basics (Android & IntelliJ)
Maven basics (Android & IntelliJ)Maven basics (Android & IntelliJ)
Maven basics (Android & IntelliJ)Hussain Mansoor
 
Wonderful World of Maven
Wonderful World of MavenWonderful World of Maven
Wonderful World of MavenJustin J. Moses
 
An Introduction to Maven and Flex
An Introduction to Maven and FlexAn Introduction to Maven and Flex
An Introduction to Maven and FlexJustin J. Moses
 
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
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with FlexPriyank
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with FlexPriyank
 
Apache Maven supports all Java (JokerConf 2018)
Apache Maven supports all Java (JokerConf 2018)Apache Maven supports all Java (JokerConf 2018)
Apache Maven supports all Java (JokerConf 2018)Robert Scholte
 

Similar a Note - Apache Maven Intro (20)

Introduction To Maven2
Introduction To Maven2Introduction To Maven2
Introduction To Maven2
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 features
 
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
 
Mavenppt
MavenpptMavenppt
Mavenppt
 
Maven
MavenMaven
Maven
 
Maven basics (Android & IntelliJ)
Maven basics (Android & IntelliJ)Maven basics (Android & IntelliJ)
Maven basics (Android & IntelliJ)
 
Apache Maven for AT/QC
Apache Maven for AT/QCApache Maven for AT/QC
Apache Maven for AT/QC
 
Wonderful World of Maven
Wonderful World of MavenWonderful World of Maven
Wonderful World of Maven
 
Exploring Maven SVN GIT
Exploring Maven SVN GITExploring Maven SVN GIT
Exploring Maven SVN GIT
 
A-Z_Maven.pdf
A-Z_Maven.pdfA-Z_Maven.pdf
A-Z_Maven.pdf
 
An Introduction to Maven and Flex
An Introduction to Maven and FlexAn Introduction to Maven and Flex
An Introduction to Maven and Flex
 
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 in Mule
Maven in MuleMaven in Mule
Maven in Mule
 
Maven
MavenMaven
Maven
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
 
Apache Maven supports all Java (JokerConf 2018)
Apache Maven supports all Java (JokerConf 2018)Apache Maven supports all Java (JokerConf 2018)
Apache Maven supports all Java (JokerConf 2018)
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 

Último

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 

Último (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

Note - Apache Maven Intro

  • 1. Apache Maven (3.0+) Basic introduction Dec.22.2013 Boy.Wang
  • 2. Jar Hell & Plugin Hell cosmos-saje cosmos-lib saje cosmos-core xerces fscript fractal-adl dream-annot dream-core antlr fractal-util julia-mixins perseus-cache task-deployment julia-asm aval fractal-rmi easymock developing project intermediate depex final depex
  • 3. Main Purpose 1. Single project producing a single type. 2. Standard life-cycles and naming conventions. 3. Version and dependency management. 4. Repositories: several remote and one local, it means no more externals or lib and no more jars in developer's directories. groupId artifactId version
  • 4. Maven Working Flow Maven (core) ~/.m2/ repository pom.xml download parse connect plugins libs artifacts artifacts use The core of Maven consists of a very basic shell that knows only how to parse the command line, manage a classpath, parse a POM file and download Maven plugins as needed.
  • 5. Core Concepts 1. What is pom.xml? 2. What is Maven plugin and goal? e.g. mvn archetype:generate -DgroupId=org.simple -DartifactId=simple 3. What is Maven lifecycle and phase? e.g. mvn install 4. What is Maven coordinate? 5. What is Maven repositories and dependency? 6. What is Maven artifact? mvn [options] [goal(s)] [phase(s)]
  • 6. 1. A Maven project is simply a folder that contains a pom.xml. 2. Every pom.xml implicitly inherits from Super POM. http://maven.apache.org/ref/3.0.5/maven-model-builder/super-pom.html pom.xml (Project Object Model) <project> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.demo</groupId> <artifactId>myapp</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>myapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project> SAMPLE
  • 7. Maven Plugin and Goal 1. A plugin is a collection of one or more goals. a. Plugin can be written in Java, Ant or Ruby. b. e.g. Jar plugin contains goals for creating JAR files. c. e.g. Compiler plugin contains goals for compiling source code and unit test. 2. A goal is a specific task that can be executed. % mvn archetype:generate -DgroupId=xxx.yyy -DartifactId=simple plugin's identifier goal's parameters goal's identifier
  • 8. Maven Lifecycle and Phase 1. Phase may have zero or more goals bound to it. 2. Lifecycle is the definition of an ordered list of phases which is executed sequentially. % mvn resources:resources compiler:compile resources:testResources compiler:testCompile surefire:test jar:jar install:install % mvn install phase's identifier Is the same with...
  • 9. Lifecycle is just like a lazy package that is made of Phases. It helps you to execute multiple Goals sequentially. % mvn compile generate-sources compile test-compile test package install deploy Phase Plugin:Goal ear:generate... compiler:compile compiler:testCompile surefire:test jar:jar install:install deploy:deploy lifecycle: generate-source -> compile lifecycle: generate-source -> compile -> ... -> deploy % mvn deploy
  • 10. Maven Coordinate Maven coordinates define a set of identifiers which can be used to uniquely identify a project. <project ...> ... ... <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project> <groupId>org.eclipse.cdt</groupId> <artifactId>cdt-parent</artifactId> <packaging>jar</packaging> <version>8.3.0-SNAPSHOT</version> This packaging element affects the goals required by phases.
  • 11. Maven Repositories and Depex 1. When you run Maven for the first time, you will notice that Maven downloads a number of files from a remote Maven repository. In Maven, artifacts and plugins are retrieved from a remote repository when they are needed. 2. Maven uses the local repository to share dependencies across local projects. Maven publishes a JAR file and a slightly modified version of the project’s pom.xml file in the local repository. Storing a POM file in the repository gives other projects information about this project, most importantly what dependencies it has. % mvn install
  • 12. Maven Artifact An Maven artifact is a file that is produced by a build execution and represents an application binary. e.g. 1. A project's library: JAR, WAR, EAR, ZIP, .... 2. Maven plugin: A JAR application to execute build executions. 3. Maven archetype: A JAR application to create a Maven project template. 4. Project metafile: pom.xml.
  • 13. Summary 1. A goal is a "unit of work". It is a basic execution unit and its behavior can be configured. 2. A phase is made up of goals and a lifecycle is made up of phases. 3. Higher level of reusability between builds. 4. Maven is a build system not just a build tool.
  • 15. Reference 1. Free Books a. http://www.sonatype.com/resources/books/maven-by-example b. http://www.sonatype.com/resources/books/maven-the-complete-reference 2. Maven Lifecycle Reference a. http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference b. http://books.sonatype.com/mvnref-book/reference/lifecycle-sect-common-goals.html 3. Maven C/C++ Plugin a. http://duns.github.io/maven-nar-plugin/