SlideShare uma empresa Scribd logo
1 de 38
Maven
Outline
• POM
• Dependency
• Life cycle
• Plugin
• Profile
• SCM
Maven
• Dependency Management
• Remote Repositories
• Universal Reuse of Build Logic
• Tool Portablility/Integration
• Easy Searching and Filtering of Project
Artifact
Project Object Model (POM)
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.estinet</groupId>
<artifactId>controller</artifactId>
<version>1.0.0</version>
</project>
•groupId
•Group identifier
•Java package name
•arti
•project main identifier
Effective POM
• mvn help:effective-pom
• de
Super POM
com.estinet.controller
bod
1.0-SNAPSHOT
com.estinet.switch
broadcom
1.0-SNAPSHOT
Project Inheritance
• dependencies
• developers and contributors
• plugin lists (including reports)
• plugin executions with matching ids
• plugin configuration
• resources
Project Inhertance
<project>
<parent>
<groupId>com.estinet</groupId>
<artifactId>controller</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>bod</artifactId>
</project>
SNAPSHOT Version
• Expand SNAPSHOT to UTC date and
time
• e.g.,
– 1.0-SNAPSHOT
– 1.0-20160616-150000-1
Properties
• env
– exposed by OS
${evn.PATH}
• project
– project variable, defined in POM
${project.groupId}
• setting
– setting variable
– ./.m2/setting.xml
${setting.offline}
Project Dependency
<project>
...
<dependencies>
<dependency>
<groupId>org.codehaus.xfire</groupId>
<artifactId>xfire-java5</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
...
</dependency>
</dependencies>
</project>
Dependency Scope
• compile
– default
• provided
– required on compilation, but not for execution
– provided by JDK or other container
• runtime
– required for execution and test
• test
– for test only
• system
– like provided
– must supply systemPath
Grouping Dependencies
<project>
<groupId>com.estinet.controller</groupId>
<artifactId>controller-dependencies</artifactId>
<version>1.0.0</version>
<packaging>POM<packaging>
<dependencies>
<dependency>
<groupId>org.codehaus.xfire</groupId>
<artifactId>xfire-java5</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
...
</dependency>
</dependencies>
</project>
install POM to your local repository (~/.m2)
mvn install
Grouping Dependencies
<project>
...
<dependencies>
<dependency>
<groupId>com.estinet.controller</groupId>
<artifactId>controller-dependencies</artifactId>
<version>1.0.0</version>
<type>POM</type>
</dependency>
<dependency>
...
</dependency>
</dependencies>
</project>
Multi-Modules
<project>
...
<modules>
<module>simple-weather</module>
<module>simple-webapp</module>
</modules>
</project>
Maven Usages
usage: mvn [options] [<goal(s)>]
[<phase(s)>]
Lifecycle
lifecycle description
clean clean the build directory
default complie, test, package, deploy
site report, document
Clean Lifecycle
Phase
pre-clean
clean
post-clean
command description
mvn clean execute the clean lifecycle
including pre-clean, clean, post-clean
mvn clean:clean execute the clean phase of the clean lifecycle
Default Lifecycle
Phase Phase
validate test
generate-sources prepare-package
process-sources package
generate-resources pre-integration-test
process-resources verify
compile install
generate-test-sources deploy
process-test-sources
generate-test-resources
process-test-resources
test-compile
Default Lifecycle
command description
mvn validate execute validate phase
mvn compile execute from validate phase to compile phase
mvn test execute from validate phase to test phase
mvn install execute fomr validate phase to install phase
Package-specific Lifecycle
(JAR)
Lifecycle Phase Goal <pluging>:<goal>
process-resource resources:resources
compile compiler:compile
process-test-resources resources:testResources
test-compile compiler:testCompile
test surefire:test
package jar:jar
install install:install
deploy deploy:deploy
Package-specific Lifecycle (POM)
Lifecycle Phase Goal <pluging>:<goal>
package site:attach-descriptor
install install:install
deploy deploy:deploy
Test
• Run as JUNIT test
• Variables
– testSourceDirectory
• src/test/java
– testOutputdirectory
• target/test-classes
– result
• target/surefire-reports
• Includsion
– Java filenames that start with "Test"
• **/Test*.java
– Java filenames that end with "Test"
• **/*Test.java
– Java filenames that end with "TestCase"
• **/*TestCase.java
Test
mvn -Dtest=TestCircle test
run test on TestCircle class
mvn -Dtest=TestSquare,TestCi*le test
run multiple names/patterns, separated by commas
mvn -Dtest=TestCircle#mytest test
mvn -Dtest=TestCircle#test* test
mvn -Dtest=TestCircle#testOne+testTwo test
run test on multiple methods
mvn install -Dmaven.test.skip=true
skip test
Package-specific Lifecycle
(Maven Plugin)
Lifecycle Phase Goal <pluging>:<goal>
generate-resource plugin:descriptor
process-resources resources:resources
compile compiler:compile
process-test-resource resources:testResources
test-compile compile:testCompile
test surefire:test
package jar:jar, plugin:addPluginArtifactMetaData
deploy deploy:deploy
Process Resource
copy from
${basedir}/src/main/resource
to
${project.build.outputDirector}
(${basedir}/target/classes by default)
Compile
<project>
...
<build>
...
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</aftifactId>
<configuration>
<source>1.6</source>
<target>1.5</tartet>
</configuratin>
</plugin>
</plugins>
</build>
</project>
source java 1.6
vm java 1.5
Compile
<project>
...
<build>
...
<sourceDirectory>src/java</sourceDirectory>
<outputDirectory>classes</outputDirectory>
</build>
</project>
Plugin
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Configure variable used by plugin
"Maven" is really just a core framework for a collection of Maven Plugins
<project>
...
<build>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure>VersionUnknown</revisionOnScmFailure>
</configuration>
<executions>
<execution>
<goals>
<goal>create</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
execute the plugin goal create in the validate phase
<project>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
......
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
use pluginManagement to
management plugin configuration
Profile
• Per Project
– pom.xml
• Per User
– %USER_HOME%/.m2/settings.xml
• Global
– %M2_HOME%/config/settings.xml
mvn groupId:artifactId:goal -P profile-1,profile-2
Profile for Development
<profile>
<id>development</id>
<properties>
<db.driverClass>oracle.jdbc.driver.OracleDriver</db.driverClass>
<db.connectionURL>jdbc:oracle:thin:@127.0.0.1:1521:XE</db.connectionURL>
<db.username>devuser</db.username>
<db.password>devpassword</db.password>
<logo.image>mylogo.png</logo.image>
</properties>
</profile>
mvn groupId:artifactId:goal -P development
Profile for Production
<profile>
<id>production</id>
<properties>
<db.driverClass>oracle.jdbc.driver.OracleDriver</db.driverClass>
<db.connectionURL>jdbc:oracle:thin:@10.0.1.14:1521:APPS</db.connectionURL>
<db.username>productionuser</db.username>
<db.password>productionpassword</db.password>
<logo.image>production_logo.png</logo.image>
</properties>
</profile>
mvn groupId:artifactId:goal -P production
Resource Filtering
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
Enable resource filtering in specific directory
maven variable in files in the specific directory will be replaced
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
add plugin
configure resource filtering
Resource Filtering
database.jdbc.driverClass=${db.driverClass}
database.jdbc.connectionURL=${db.connectionURL}
database.jdbc.username=${db.username}
database.jdbc.password=${db.password}
model.application.name=MyWebApp
model.stylesheet=/mywebapp.css
database.jdbc.driverClass=oracle.jdbc.driver.OracleDriver
database.jdbc.connectionURL=jdbc:oracle:thin:@127.0.0.1:1521:XE
database.jdbc.username=myusername
database.jdbc.password=mypassword
model.application.name=MyWebApp
model.stylesheet=/mywebapp.css
db.properties source
db.properties source after resource filtering
Profile Activation
<profiles>
<profile>
<id>appserverConfig-dev</id>
<activation>
<property>
<name>env</name>
<value>dev</value>
</property>
</activation>
<properties>
<server.home>/appserver</server.home>
</properties>
</profile>
<profiles>
<profiles>
<profile>
<id>appserverConfig-dev-2</id>
<activation>
<property>
<name>env</name>
<value>dev-2</value>
</property>
</activation>
<properties>
<server.home>/appserver2</server.home>
</properties>
</profile>
<profiles>
actived if env = dev actived if env = dev2
Source Code Management (SCM)
Use SCM to update and checkin code
<project>
...
<scm>
<connection>scm:svn:http://somerepository.com/svn_repo/trunk</connection>
<developerConnection>scm:svn:https://somerepository.com/svn_repo/trunk</developerConnection>
<url>http://somerepository.com/view.cvs</url>
</scm>
...
</project>
mvn -Dmessage="<commit_log_here>" scm:checkin
mvn scm:update
check in code
update
Name Value
-Dmaven.test.skip=true skip test
-o work offline, skip download pom
-P <args> configurate active profile
-X enable debug output
-q quiet output, only show errors
-npu no pluging updates
help:active-profiles
help:effective-pom output effective pom
help:effective-setting output effective setting
help:describe describe plugin, mvn help:describe -Dplugin=help

Mais conteúdo relacionado

Mais procurados

Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
Holasz Kati
 

Mais procurados (20)

Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
 
BDD using Cucumber JVM
BDD using Cucumber JVMBDD using Cucumber JVM
BDD using Cucumber JVM
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
Liferay maven sdk
Liferay maven sdkLiferay maven sdk
Liferay maven sdk
 
Maven
Maven Maven
Maven
 
Maven plugins, properties en profiles: Advanced concepts in Maven
Maven plugins, properties en profiles: Advanced concepts in MavenMaven plugins, properties en profiles: Advanced concepts in Maven
Maven plugins, properties en profiles: Advanced concepts in Maven
 
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-JupiterToolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
Tuscany : Applying OSGi After The Fact
Tuscany : Applying  OSGi After The FactTuscany : Applying  OSGi After The Fact
Tuscany : Applying OSGi After The Fact
 
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
 
Maven, Eclipse and OSGi Working Together - Carlos Sanchez
Maven, Eclipse and OSGi Working Together - Carlos SanchezMaven, Eclipse and OSGi Working Together - Carlos Sanchez
Maven, Eclipse and OSGi Working Together - Carlos Sanchez
 
MyFaces CODI Conversations
MyFaces CODI ConversationsMyFaces CODI Conversations
MyFaces CODI Conversations
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
 

Destaque

Version Management in Maven
Version Management in MavenVersion Management in Maven
Version Management in Maven
Geert Pante
 

Destaque (7)

Maven 3 / Tycho
Maven 3 / TychoMaven 3 / Tycho
Maven 3 / Tycho
 
Version Management in Maven
Version Management in MavenVersion Management in Maven
Version Management in Maven
 
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
 
Maven and ANT
Maven and ANTMaven and ANT
Maven and ANT
 
Automated Deployment with Maven - going the whole nine yards
Automated Deployment with Maven - going the whole nine yardsAutomated Deployment with Maven - going the whole nine yards
Automated Deployment with Maven - going the whole nine yards
 
Continuous delivery-with-maven
Continuous delivery-with-mavenContinuous delivery-with-maven
Continuous delivery-with-maven
 
Maven 2 in the real world
Maven 2 in the real worldMaven 2 in the real world
Maven 2 in the real world
 

Semelhante a Maven basic concept

Semelhante a Maven basic concept (20)

Maven
MavenMaven
Maven
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
4 maven junit
4 maven junit4 maven junit
4 maven junit
 
Developing Liferay Plugins with Maven
Developing Liferay Plugins with MavenDeveloping Liferay Plugins with Maven
Developing Liferay Plugins with Maven
 
Learning Maven by Example
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
 
Maven in Mule
Maven in MuleMaven in Mule
Maven in Mule
 
Apache Maven basics
Apache Maven basicsApache Maven basics
Apache Maven basics
 
Introduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOpsIntroduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOps
 
Maven
MavenMaven
Maven
 
Introduction tomaven
Introduction tomavenIntroduction tomaven
Introduction tomaven
 
Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)
 
Maven advanced
Maven advancedMaven advanced
Maven advanced
 
Testing with Spring 4.x
Testing with Spring 4.xTesting with Spring 4.x
Testing with Spring 4.x
 
Maven
MavenMaven
Maven
 
Maven introduction in Mule
Maven introduction in MuleMaven introduction in Mule
Maven introduction in Mule
 
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
MavenMaven
Maven
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
 

Último

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Último (20)

WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
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
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
%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
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
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 Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

Maven basic concept