Maven

Shraddha
ShraddhaAndroid Developer em Shraddha
Introduction to
MAVEN
What is Maven?
Maven v/s ANT
Create a simple project in Maven
mvn archetype:generate -DgroupId=com.lumesse.talentcloud
-DartifactId=sample
-DarchetypeArtifactId=maven-archetype-quickstart
-DinteractiveMode=false
Super POM
http://maven.apache.org/pom.html#The_Super_POM
Using A Single Repository
Maven Build Lifecycle and Phases:
Built-in Build Lifecycles:
• Default, Clean and Site
• The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning,
while the site lifecycle handles the creation of your project's site documentation.
Standard Lifecycles:
• validate: validate the project is correct and all necessary information is available
• compile: compile the source code of the project
• test: test the compiled source code using a suitable unit testing framework. These tests should not
require the code be packaged or deployed
• package: take the compiled code and package it in its distributable format, such as a JAR.
• integration-test: process and deploy the package if necessary into an environment where
integration tests can be run
• verify: run any checks to verify the package is valid and meets quality criteria
• install: install the package into the local repository, for use as a dependency in other projects locally
• deploy: done in an integration or release environment, copies the final package to the remote
repository for sharing with other developers and projects.
2 Ways to assign tasks to build phases
• Packaging
• Plug-ins
Jar Packaging:
Configuring Plug-ins
• Build plugins will be executed during the build
and then, they should be configured in the
<build/> element.
• Reporting plugins will be executed during the
site generation and they should be configured
in the <reporting/> element.
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<configuration>
<models>
<model>src/main/mdo/maven.mdo</model>
</models>
<version>4.0.0</version>
</configuration>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
package sample.plugin;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
/**
* Says "Hi" to the user.
*
*/
@Mojo( name = "sayhi")
public class GreetingMojo extends AbstractMojo
{
public void execute() throws MojoExecutionException
{
getLog().info( "Hello, world." );
}
}
Simple MOJO Example
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>sample.plugin</groupId>
<artifactId>hello-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</project>
MOJO’s pom.xml
...
<build>
<plugins>
<plugin>
<groupId>sample.plugin</groupId>
<artifactId>hello-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</plugin>
</plugins>
</build>
...
Executing Your First Mojo
mvn sample.plugin:hello-maven-plugin:1.0-SNAPSHOT:sayhi
mvn hello:sayhi
/**
* The greeting to display.
*/
@Parameter( property = "sayhi.greeting", defaultValue = "Hello World!" )
private String greeting;
Defining Parameters Within a Mojo
Configuring Parameters in a Project
<plugin>
<groupId>sample.plugin</groupId>
<artifactId>hello-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<greeting>Welcome</greeting>
</configuration>
</plugin>
Using Executions Tag<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-myquery-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>execution1</id>
<phase>test</phase>
<configuration>
<url>http://www.foo.com/query</url>
<timeout>10</timeout>
<options>
<option>one</option>
<option>two</option>
<option>three</option>
</options>
</configuration>
<goals>
<goal>query</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
<executions>
<execution>
<id>execution1</id>
<phase>test</phase>
<configuration>
<url>http://www.foo.com/query</url>
<timeout>10</timeout>
<options>
<option>one</option>
<option>two</option>
<option>three</option>
</options>
</configuration>
<goals>
<goal>query</goal>
</goals>
</execution>
<execution>
<id>execution2</id>
<configuration>
<url>http://www.bar.com/query</url>
<timeout>15</timeout>
<options>
<option>four</option>
<option>five</option>
<option>six</option>
</options>
</configuration>
<goals>
<goal>query</goal>
</goals>
</execution>
</executions>
Maven Antrun Plug-in
<project>
[...]
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase> <!-- a lifecycle phase --> </phase>
<configuration>
<target>
<!--
Place any Ant task here. You can add anything
you can add between <target> and </target> in a
build.xml.
-->
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
Dependency Scopes
• Compile
• Provided
• Runtime
• Test
• System
• Import
Dependency Scopes – System
<project>
...
<dependencies>
<dependency>
<groupId>javax.sql</groupId>
<artifactId>jdbc-stdext</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>${java.home}/lib/rt.jar</systemPath>
</dependency>
</dependencies>
...
</project>
Best Practices
• Dependency Management
• Plug-in Management
Good to Know Facts
1) Surefire plugin:
Accepted class names are
**/*Test.java
**/Test*.java
**/*TestCase.java
And the default excludes are:
**/Abstract*Test.java
**/Abstract*TestCase.java
2) Putting a jar in local repository
mvn install:install-file
-Dfile=<path-to-file>
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dpackaging=<packaging> -DgeneratePom=true
Good to Know Facts
3) Skip tests in Maven:
-Dmaven.test.skip=true  skips test compilation and execution
-DskipTests=true  skips test execution only
4) Produce execution debug output or error messages in Maven
Use -X parameter or -e parameter
References
• http://maven.apache.org/index.html
• http://maven.apache.org/plugins/index.html
• http://maven.apache.org/developers/index.html
Creating your own Archetypes
• An archetype descriptor (archetype.xml in directory:
src/main/resources/META-INF/maven
• The prototype files that are copied by the archetype plugin (directory:
src/main/resources/archetype-resources/)
• The prototype pom (pom.xml in: src/main/resources/archetype-resources)
• A pom for the archetype (pom.xml in the archetype's root directory).
Aggregation
Thank You
1 de 24

Recomendados

Maven por
MavenMaven
MavenVineela Madarapu
979 visualizações19 slides
maven por
mavenmaven
mavenakd11
375 visualizações25 slides
An Introduction to Maven Part 1 por
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1MD Sayem Ahmed
899 visualizações23 slides
Introduction to Maven por
Introduction to MavenIntroduction to Maven
Introduction to MavenOnkar Deshpande
3.4K visualizações67 slides
Maven por
Maven Maven
Maven Khan625
905 visualizações9 slides
Maven Introduction por
Maven IntroductionMaven Introduction
Maven IntroductionSandeep Chawla
21.1K visualizações31 slides

Mais conteúdo relacionado

Mais procurados

Learning Maven by Example por
Learning Maven by ExampleLearning Maven by Example
Learning Maven by ExampleHsi-Kai Wang
1.6K visualizações42 slides
Apache Maven por
Apache MavenApache Maven
Apache MavenRahul Tanwani
2.1K visualizações35 slides
Maven Overview por
Maven OverviewMaven Overview
Maven OverviewFastConnect
8.5K visualizações29 slides
Maven tutorial por
Maven tutorialMaven tutorial
Maven tutorialDragos Balan
1.8K visualizações52 slides
Maven tutorial for beginners por
Maven tutorial for beginnersMaven tutorial for beginners
Maven tutorial for beginnersinTwentyEight Minutes
307 visualizações13 slides
Maven 2 Introduction por
Maven 2 IntroductionMaven 2 Introduction
Maven 2 IntroductionValentin Jacquemin
2.5K visualizações12 slides

Mais procurados(20)

Learning Maven by Example por Hsi-Kai Wang
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
Hsi-Kai Wang1.6K visualizações
Apache Maven por Rahul Tanwani
Apache MavenApache Maven
Apache Maven
Rahul Tanwani2.1K visualizações
Maven Overview por FastConnect
Maven OverviewMaven Overview
Maven Overview
FastConnect8.5K visualizações
Maven tutorial por Dragos Balan
Maven tutorialMaven tutorial
Maven tutorial
Dragos Balan1.8K visualizações
Maven tutorial for beginners por inTwentyEight Minutes
Maven tutorial for beginnersMaven tutorial for beginners
Maven tutorial for beginners
inTwentyEight Minutes307 visualizações
Maven 2 Introduction por Valentin Jacquemin
Maven 2 IntroductionMaven 2 Introduction
Maven 2 Introduction
Valentin Jacquemin2.5K visualizações
Apache Maven In 10 Slides por Robert Burrell Donkin
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
Robert Burrell Donkin5.7K visualizações
Maven Basics - Explained por Smita Prasad
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
Smita Prasad1.1K visualizações
Maven 3 Overview por Mike Ensor
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
Mike Ensor2.7K visualizações
Maven plugins, properties en profiles: Advanced concepts in Maven por Geert Pante
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
Geert Pante2.6K visualizações
Demystifying Maven por Mike Desjardins
Demystifying MavenDemystifying Maven
Demystifying Maven
Mike Desjardins4.9K visualizações
Maven tutorial por James Cellini
Maven tutorialMaven tutorial
Maven tutorial
James Cellini2.1K visualizações
Hands On with Maven por Sid Anand
Hands On with MavenHands On with Maven
Hands On with Maven
Sid Anand6.1K visualizações
Introduction to Apache Maven por Rajind Ruparathna
Introduction to Apache MavenIntroduction to Apache Maven
Introduction to Apache Maven
Rajind Ruparathna2.2K visualizações
Maven por Sunil Komarapu
MavenMaven
Maven
Sunil Komarapu215 visualizações
Introduction to maven por Manos Georgopoulos
Introduction to mavenIntroduction to maven
Introduction to maven
Manos Georgopoulos1.2K visualizações
Using Maven 2 por andyhot
Using Maven 2Using Maven 2
Using Maven 2
andyhot2.8K visualizações
Java Builds with Maven and Ant por David Noble
Java Builds with Maven and AntJava Builds with Maven and Ant
Java Builds with Maven and Ant
David Noble2.4K visualizações
An Introduction to Maven por Vadym Lotar
An Introduction to MavenAn Introduction to Maven
An Introduction to Maven
Vadym Lotar13.9K visualizações

Similar a Maven

Intelligent Projects with Maven - DevFest Istanbul por
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulMert Çalışkan
1.3K visualizações58 slides
BMO - Intelligent Projects with Maven por
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenMert Çalışkan
1.6K visualizações59 slides
Introduction to maven, its configuration, lifecycle and relationship to JS world por
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
691 visualizações91 slides
Apache maven, a software project management tool por
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management toolRenato Primavera
1.6K visualizações57 slides
Session 2 por
Session 2Session 2
Session 2gayathiry
167 visualizações21 slides
Session 2 por
Session 2Session 2
Session 2gayathiry
162 visualizações21 slides

Similar a Maven(20)

Intelligent Projects with Maven - DevFest Istanbul por Mert Çalışkan
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
Mert Çalışkan1.3K visualizações
BMO - Intelligent Projects with Maven por Mert Çalışkan
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
Mert Çalışkan1.6K visualizações
Introduction to maven, its configuration, lifecycle and relationship to JS world por Dmitry Bakaleinik
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
Dmitry Bakaleinik691 visualizações
Apache maven, a software project management tool por Renato Primavera
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
Session 2 por gayathiry
Session 2Session 2
Session 2
gayathiry167 visualizações
Session 2 por gayathiry
Session 2Session 2
Session 2
gayathiry162 visualizações
Maven basic concept por Ming-Sian Lin
Maven basic conceptMaven basic concept
Maven basic concept
Ming-Sian Lin843 visualizações
Developing Liferay Plugins with Maven por Mika Koivisto
Developing Liferay Plugins with MavenDeveloping Liferay Plugins with Maven
Developing Liferay Plugins with Maven
Mika Koivisto11.7K visualizações
Maven in mulesoft por venkata20k
Maven in mulesoftMaven in mulesoft
Maven in mulesoft
venkata20k141 visualizações
4 maven junit por Honnix Liang
4 maven junit4 maven junit
4 maven junit
Honnix Liang692 visualizações
(Re)-Introduction to Maven por Eric Wyles
(Re)-Introduction to Maven(Re)-Introduction to Maven
(Re)-Introduction to Maven
Eric Wyles127 visualizações
Maven 2.0 - Project management and comprehension tool por elliando dias
Maven 2.0 - Project management and comprehension toolMaven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension tool
elliando dias2K visualizações
Maven por Fabio Bonfante
MavenMaven
Maven
Fabio Bonfante829 visualizações
Maven advanced por Smita Prasad
Maven advancedMaven advanced
Maven advanced
Smita Prasad970 visualizações
Exploring Maven SVN GIT por People Strategists
Exploring Maven SVN GITExploring Maven SVN GIT
Exploring Maven SVN GIT
People Strategists1.5K visualizações
Liferay maven sdk por Mika Koivisto
Liferay maven sdkLiferay maven sdk
Liferay maven sdk
Mika Koivisto3.2K visualizações
Mavennotes.pdf por AnkurSingh656748
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
AnkurSingh6567489 visualizações
Ci jenkins maven svn por Ankur Goyal
Ci jenkins maven svnCi jenkins maven svn
Ci jenkins maven svn
Ankur Goyal2.2K visualizações
Embrace Maven por Guy Marom
Embrace MavenEmbrace Maven
Embrace Maven
Guy Marom213 visualizações
Maven por feng lee
MavenMaven
Maven
feng lee1.8K visualizações

Último

Cycleops - Automate deployments on top of bare metal.pptx por
Cycleops - Automate deployments on top of bare metal.pptxCycleops - Automate deployments on top of bare metal.pptx
Cycleops - Automate deployments on top of bare metal.pptxThanassis Parathyras
30 visualizações12 slides
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t... por
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...Deltares
9 visualizações26 slides
Advanced API Mocking Techniques por
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking TechniquesDimpy Adhikary
19 visualizações11 slides
Citi TechTalk Session 2: Kafka Deep Dive por
Citi TechTalk Session 2: Kafka Deep DiveCiti TechTalk Session 2: Kafka Deep Dive
Citi TechTalk Session 2: Kafka Deep Diveconfluent
17 visualizações60 slides
WebAssembly por
WebAssemblyWebAssembly
WebAssemblyJens Siebert
33 visualizações18 slides
SAP FOR TYRE INDUSTRY.pdf por
SAP FOR TYRE INDUSTRY.pdfSAP FOR TYRE INDUSTRY.pdf
SAP FOR TYRE INDUSTRY.pdfVirendra Rai, PMP
23 visualizações3 slides

Último(20)

Cycleops - Automate deployments on top of bare metal.pptx por Thanassis Parathyras
Cycleops - Automate deployments on top of bare metal.pptxCycleops - Automate deployments on top of bare metal.pptx
Cycleops - Automate deployments on top of bare metal.pptx
Thanassis Parathyras30 visualizações
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t... por Deltares
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
Deltares9 visualizações
Advanced API Mocking Techniques por Dimpy Adhikary
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking Techniques
Dimpy Adhikary19 visualizações
Citi TechTalk Session 2: Kafka Deep Dive por confluent
Citi TechTalk Session 2: Kafka Deep DiveCiti TechTalk Session 2: Kafka Deep Dive
Citi TechTalk Session 2: Kafka Deep Dive
confluent17 visualizações
WebAssembly por Jens Siebert
WebAssemblyWebAssembly
WebAssembly
Jens Siebert33 visualizações
SAP FOR TYRE INDUSTRY.pdf por Virendra Rai, PMP
SAP FOR TYRE INDUSTRY.pdfSAP FOR TYRE INDUSTRY.pdf
SAP FOR TYRE INDUSTRY.pdf
Virendra Rai, PMP23 visualizações
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge... por Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
Deltares16 visualizações
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx por animuscrm
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
animuscrm13 visualizações
Tridens DevOps por Tridens
Tridens DevOpsTridens DevOps
Tridens DevOps
Tridens9 visualizações
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... por Marc Müller
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Marc Müller36 visualizações
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut... por HCLSoftware
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...
HCLSoftware6 visualizações
DSD-INT 2023 HydroMT model building and river-coast coupling in Python - Bove... por Deltares
DSD-INT 2023 HydroMT model building and river-coast coupling in Python - Bove...DSD-INT 2023 HydroMT model building and river-coast coupling in Python - Bove...
DSD-INT 2023 HydroMT model building and river-coast coupling in Python - Bove...
Deltares17 visualizações
DSD-INT 2023 SFINCS Modelling in the U.S. Pacific Northwest - Parker por Deltares
DSD-INT 2023 SFINCS Modelling in the U.S. Pacific Northwest - ParkerDSD-INT 2023 SFINCS Modelling in the U.S. Pacific Northwest - Parker
DSD-INT 2023 SFINCS Modelling in the U.S. Pacific Northwest - Parker
Deltares9 visualizações
Roadmap y Novedades de producto por Neo4j
Roadmap y Novedades de productoRoadmap y Novedades de producto
Roadmap y Novedades de producto
Neo4j50 visualizações
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports por Ra'Fat Al-Msie'deen
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug ReportsBushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
Ra'Fat Al-Msie'deen5 visualizações
Unleash The Monkeys por Jacob Duijzer
Unleash The MonkeysUnleash The Monkeys
Unleash The Monkeys
Jacob Duijzer7 visualizações
Upgrading Incident Management with Icinga - Icinga Camp Milan 2023 por Icinga
Upgrading Incident Management with Icinga - Icinga Camp Milan 2023Upgrading Incident Management with Icinga - Icinga Camp Milan 2023
Upgrading Incident Management with Icinga - Icinga Camp Milan 2023
Icinga38 visualizações
Software testing company in India.pptx por SakshiPatel82
Software testing company in India.pptxSoftware testing company in India.pptx
Software testing company in India.pptx
SakshiPatel827 visualizações
Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea... por Safe Software
Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea...Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea...
Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea...
Safe Software412 visualizações
Fleet Management Software in India por Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable11 visualizações

Maven