SlideShare uma empresa Scribd logo
1 de 27
Introduction to MavenIntroduction to Maven
Notes
• This is a training NOT a presentation
• Please ask questions
• Prerequisites
– Introduction to the Java Stack
– Basic Java and XML skillz
• Introduce Maven
• Basic Maven Pom File and Project Structure
• Dependencies
Maven Background
• Is a Java build tool
– “project management and comprehension tool”
• An Apache Project
– Mostly sponsored by Sonatype
• History
– Maven 1 (2003)
• Very Ugly
• Used in Stack 1
– Maven 2 (2005)
• Complete rewrite
• Not backwards Compatible
• Used in Stack 2.0,2.1,2.2,3.0
– Maven 3 (2010)
• Same as Maven 2 but more stable
• Used in Stack 2.3, 3.1
Maven Features
• Dependency System
• Multi-module builds
• Consistent project structure
• Consistent build model
• Plugin oriented
• Project generated sites
The Maven Mindset
• All build systems are essentially the same:
– Compile Source code
– Copy Resource
– Compile and Run Tests
– Package Project
– Deploy Project
– Cleanup
• Describe the project and configure the build
– You don’t script a build
– Maven has no concept of a condition
– Plugins are configured
Other Java Build Tools
• Ant (2000)
– Granddaddy of Java Build Tools
– Scripting in XML
– Very flexible
• Ant+Ivy (2004)
– Ant but with Dependency Management
• Gradle (2008)
– Attempt to combine Maven structure with Groovy
Scripting
– Easily extensible
– Immature
Maven Learning Resources
• Maven Homepage
– http://maven.apache.org
• Reference Documentation for Maven
• Reference Documentation for core Plugins
• Sonatype Resources
– http://www.sonatype.com/resource-center.html
• Free Books
• Videos
Maven POM
• Stands for Project Object Model
• Describes a project
– Name and Version
– Artifact Type
– Source Code Locations
– Dependencies
– Plugins
– Profiles (Alternate build configurations)
• Uses XML by Default
– Not the way Ant uses XML
Project Name (GAV)
• Maven uniquely identifies a project using:
– groupID: Arbitrary project grouping identifier (no spaces or
colons)
• Usually loosely based on Java package
– artfiactId: Arbitrary name of project (no spaces or colons)
– version: Version of project
• Format {Major}.{Minor}.{Maintanence}
• Add ‘-SNAPSHOT ‘ to identify in development
• GAV Syntax: groupId:artifactId:version
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.lds.training</groupId>
<artifactId>maven-training</artifactId>
<version>1.0</version>
</project>
Packaging
• Build type identified using the “packaging” element
• Tells Maven how to build the project
• Example packaging types:
– pom, jar, war, ear, custom
– Default is jar
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-training</artifactId>
<groupId>org.lds.training</groupId>
<version>1.0</version>
<packaging>jar</packaging>
</project>
Project Inheritance
• Pom files can inherit configuration
– groupId, version
– Project Config
– Dependencies
– Plugin configuration
– Etc.
<?xml version="1.0" encoding="UTF-8"?>
<project>
<parent>
<artifactId>maven-training-parent</artifactId>
<groupId>org.lds.training</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-training</artifactId>
<packaging>jar</packaging>
</project>
Multi Module Projects
• Maven has 1st
class multi-module support
• Each maven project creates 1 primary artifact
• A parent pom is used to group modules
<project>
...
<packaging>pom</packaging>
<modules>
<module>maven-training</module>
<module>maven-training-web</module>
</modules>
</project>
Maven Conventions
• Maven is opinionated about project structure
• target: Default work directory
• src: All project source files go in this directory
• src/main: All sources that go into primary artifact
• src/test: All sources contributing to testing project
• src/main/java: All java source files
• src/main/webapp: All web source files
• src/main/resources: All non compiled source files
• src/test/java: All java test source files
• src/test/resources: All non compiled test source files
Maven Build Lifecycle
• A Maven build follow a lifecycle
• Default lifecycle
– generate-sources/generate-resources
– compile
– test
– package
– integration-test (pre and post)
– Install
– deploy
• There is also a Clean lifecycle
Example Maven Goals
• To invoke a Maven build you set a lifecycle “goal”
• mvn install
– Invokes generate* and compile, test, package, integration-test,
install
• mvn clean
– Invokes just clean
• mvn clean compile
– Clean old builds and execute generate*, compile
• mvn compile install
– Invokes generate*, compile, test, integration-test, package, install
• mvn test clean
– Invokes generate*, compile, test then cleans
Maven and Dependencies
• Maven revolutionized Java dependency
management
– No more checking libraries into version control
• Introduced the Maven Repository concept
– Established Maven Central
• Created a module metadata file (POM)
• Introduced concept of transitive dependency
• Often include source and javadoc artifacts
Adding a Dependency
• Dependencies consist of:
– GAV
– Scope: compile, test, provided (default=compile)
– Type: jar, pom, war, ear, zip (default=jar)
<project>
...
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Maven Repositories
• Dependencies are downloaded from repositories
– Via http
• Downloaded dependencies are cached in a local
repository
– Usually found in ${user.home}/.m2/repository
• Repository follows a simple directory structure
– {groupId}/{artifactId}/{version}/{artifactId}-{version}.jar
– groupId ‘.’ is replaced with ‘/’
• Maven Central is primary community repo
– http://repo1.maven.org/maven2
Proxy Repositories
• Proxy Repositories are useful:
– Organizationally cache artifacts
– Allow organization some control over dependencies
– Combines repositories
• ICS uses the Nexus repository manager
• All artifacts in Nexus go through approval process
– License verified
– Improve organizational reuse
• To request approval create issue in SDS jira project:
– https://jira.ldschurch.org/jira/browse/SDS
Defining a repository
• Repositories are defined in the pom
• Repositories can be inherited from parent
• Repositories are keyed by id
• Downloading snapshots can be controlled
<project>
...
<repositories>
<repository>
<id>lds-main</id>
<name>LDS Main Repo</name>
<url>http://code.lds.org/nexus/content/groups/main-repo</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
Transitive Dependencies
• Transitive Dependency Definition:
– A dependency that should be included when declaring
project itself is a dependency
• ProjectA depends on ProjectB
• If ProjectC depends on ProjectA then ProjectB is
automatically included
• Only compile and runtime scopes are transitive
• Transitive dependencies are controlled using:
– Exclusions
– Optional declarations
Dependency Exclusions
• Exclusions exclude transitive dependencies
• Dependency consumer solution
<project>
...
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
Optional Dependencies
• Don’t propagate dependency transitively
• Dependency producer solution
• Optional is under used
<project>
...
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
<optional>true</optional>
</dependency>
</dependencies>
</project>
Dependency Management
• What do you do when versions collide?
– Allow Maven to manage it?
• Complex and less predictable
– Take control yourself
• Manage the version manually
• In Java you cannot use both versions
<project>
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Using Dependency Management
• Other uses for Dependency Management
– Allowing parent pom to manage versions
– Unify exclusions
<project>
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency> <!-- Look ma, no version! -->
</dependencies>
</project>
Summary
• Maven is a different kind of build tool
• It is easy to create multi-module builds
• Dependencies are awesome

Mais conteúdo relacionado

Mais procurados

Mais procurados (19)

Introduction to maven
Introduction to mavenIntroduction to maven
Introduction to maven
 
Maven for Dummies
Maven for DummiesMaven for Dummies
Maven for Dummies
 
Maven
MavenMaven
Maven
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Maven
Maven Maven
Maven
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
Maven
MavenMaven
Maven
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
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
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
Development Tools - Maven
Development Tools - MavenDevelopment Tools - Maven
Development Tools - Maven
 
Maven
MavenMaven
Maven
 

Semelhante a Introduction tomaven

How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.Fazreil Amreen Abdul Jalil
 
Ci jenkins maven svn
Ci jenkins maven svnCi jenkins maven svn
Ci jenkins maven svnAnkur Goyal
 
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 DevOpsSISTechnologies
 
Lorraine JUG (1st June, 2010) - Maven
Lorraine JUG (1st June, 2010) - MavenLorraine JUG (1st June, 2010) - Maven
Lorraine JUG (1st June, 2010) - MavenArnaud Héritier
 
Introduction in Apache Maven2
Introduction in Apache Maven2Introduction in Apache Maven2
Introduction in Apache Maven2Heiko Scherrer
 
Apache Maven - eXo TN presentation
Apache Maven - eXo TN presentationApache Maven - eXo TN presentation
Apache Maven - eXo TN presentationArnaud Héritier
 
Learning Maven by Example
Learning Maven by ExampleLearning Maven by Example
Learning Maven by ExampleHsi-Kai Wang
 
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
 
Developing Liferay Plugins with Maven
Developing Liferay Plugins with MavenDeveloping Liferay Plugins with Maven
Developing Liferay Plugins with MavenMika Koivisto
 
Maven introduction in Mule
Maven introduction in MuleMaven introduction in Mule
Maven introduction in MuleShahid Shaik
 
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)Robert Scholte
 
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
 
BP-10 Keeping Your Sanity – Rapid Development & Deployment Tools
BP-10 Keeping Your Sanity – Rapid Development & Deployment ToolsBP-10 Keeping Your Sanity – Rapid Development & Deployment Tools
BP-10 Keeping Your Sanity – Rapid Development & Deployment ToolsAlfresco Software
 

Semelhante a Introduction tomaven (20)

How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.
 
Ci jenkins maven svn
Ci jenkins maven svnCi jenkins maven svn
Ci jenkins maven svn
 
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
 
Intro to Maven.ppt
Intro to Maven.pptIntro to Maven.ppt
Intro to Maven.ppt
 
4 maven junit
4 maven junit4 maven junit
4 maven junit
 
Lorraine JUG (1st June, 2010) - Maven
Lorraine JUG (1st June, 2010) - MavenLorraine JUG (1st June, 2010) - Maven
Lorraine JUG (1st June, 2010) - Maven
 
Introduction in Apache Maven2
Introduction in Apache Maven2Introduction in Apache Maven2
Introduction in Apache Maven2
 
Apache Maven - eXo TN presentation
Apache Maven - eXo TN presentationApache Maven - eXo TN presentation
Apache Maven - eXo TN presentation
 
Maven
MavenMaven
Maven
 
Learning Maven by Example
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
Developing Liferay Plugins with Maven
Developing Liferay Plugins with MavenDeveloping Liferay Plugins with Maven
Developing Liferay Plugins with Maven
 
Maven
MavenMaven
Maven
 
Maven introduction in Mule
Maven introduction in MuleMaven introduction in Mule
Maven introduction in Mule
 
Oracle 12c Launch Event 02 ADF 12c and Maven in Jdeveloper / By Aino Andriessen
Oracle 12c Launch Event 02 ADF 12c and Maven in Jdeveloper / By Aino Andriessen Oracle 12c Launch Event 02 ADF 12c and Maven in Jdeveloper / By Aino Andriessen
Oracle 12c Launch Event 02 ADF 12c and Maven in Jdeveloper / By Aino Andriessen
 
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)
 
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
 
BP-10 Keeping Your Sanity – Rapid Development & Deployment Tools
BP-10 Keeping Your Sanity – Rapid Development & Deployment ToolsBP-10 Keeping Your Sanity – Rapid Development & Deployment Tools
BP-10 Keeping Your Sanity – Rapid Development & Deployment Tools
 
Maven
MavenMaven
Maven
 
MAVEN
MAVENMAVEN
MAVEN
 

Mais de Manav Prasad (20)

Experience with mulesoft
Experience with mulesoftExperience with mulesoft
Experience with mulesoft
 
Mulesoftconnectors
MulesoftconnectorsMulesoftconnectors
Mulesoftconnectors
 
Mule and web services
Mule and web servicesMule and web services
Mule and web services
 
Mulesoft cloudhub
Mulesoft cloudhubMulesoft cloudhub
Mulesoft cloudhub
 
Perl tutorial
Perl tutorialPerl tutorial
Perl tutorial
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Jpa
JpaJpa
Jpa
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Json
Json Json
Json
 
The spring framework
The spring frameworkThe spring framework
The spring framework
 
Rest introduction
Rest introductionRest introduction
Rest introduction
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
 
Junit
JunitJunit
Junit
 
Xml parsers
Xml parsersXml parsers
Xml parsers
 
Xpath
XpathXpath
Xpath
 
Xslt
XsltXslt
Xslt
 
Xhtml
XhtmlXhtml
Xhtml
 
Css
CssCss
Css
 
Introduction to html5
Introduction to html5Introduction to html5
Introduction to html5
 
Ajax
AjaxAjax
Ajax
 

Último

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Último (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Introduction tomaven

  • 2. Notes • This is a training NOT a presentation • Please ask questions • Prerequisites – Introduction to the Java Stack – Basic Java and XML skillz
  • 3. • Introduce Maven • Basic Maven Pom File and Project Structure • Dependencies
  • 4. Maven Background • Is a Java build tool – “project management and comprehension tool” • An Apache Project – Mostly sponsored by Sonatype • History – Maven 1 (2003) • Very Ugly • Used in Stack 1 – Maven 2 (2005) • Complete rewrite • Not backwards Compatible • Used in Stack 2.0,2.1,2.2,3.0 – Maven 3 (2010) • Same as Maven 2 but more stable • Used in Stack 2.3, 3.1
  • 5. Maven Features • Dependency System • Multi-module builds • Consistent project structure • Consistent build model • Plugin oriented • Project generated sites
  • 6. The Maven Mindset • All build systems are essentially the same: – Compile Source code – Copy Resource – Compile and Run Tests – Package Project – Deploy Project – Cleanup • Describe the project and configure the build – You don’t script a build – Maven has no concept of a condition – Plugins are configured
  • 7. Other Java Build Tools • Ant (2000) – Granddaddy of Java Build Tools – Scripting in XML – Very flexible • Ant+Ivy (2004) – Ant but with Dependency Management • Gradle (2008) – Attempt to combine Maven structure with Groovy Scripting – Easily extensible – Immature
  • 8. Maven Learning Resources • Maven Homepage – http://maven.apache.org • Reference Documentation for Maven • Reference Documentation for core Plugins • Sonatype Resources – http://www.sonatype.com/resource-center.html • Free Books • Videos
  • 9. Maven POM • Stands for Project Object Model • Describes a project – Name and Version – Artifact Type – Source Code Locations – Dependencies – Plugins – Profiles (Alternate build configurations) • Uses XML by Default – Not the way Ant uses XML
  • 10. Project Name (GAV) • Maven uniquely identifies a project using: – groupID: Arbitrary project grouping identifier (no spaces or colons) • Usually loosely based on Java package – artfiactId: Arbitrary name of project (no spaces or colons) – version: Version of project • Format {Major}.{Minor}.{Maintanence} • Add ‘-SNAPSHOT ‘ to identify in development • GAV Syntax: groupId:artifactId:version <?xml version="1.0" encoding="UTF-8"?> <project> <modelVersion>4.0.0</modelVersion> <groupId>org.lds.training</groupId> <artifactId>maven-training</artifactId> <version>1.0</version> </project>
  • 11. Packaging • Build type identified using the “packaging” element • Tells Maven how to build the project • Example packaging types: – pom, jar, war, ear, custom – Default is jar <?xml version="1.0" encoding="UTF-8"?> <project> <modelVersion>4.0.0</modelVersion> <artifactId>maven-training</artifactId> <groupId>org.lds.training</groupId> <version>1.0</version> <packaging>jar</packaging> </project>
  • 12. Project Inheritance • Pom files can inherit configuration – groupId, version – Project Config – Dependencies – Plugin configuration – Etc. <?xml version="1.0" encoding="UTF-8"?> <project> <parent> <artifactId>maven-training-parent</artifactId> <groupId>org.lds.training</groupId> <version>1.0</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>maven-training</artifactId> <packaging>jar</packaging> </project>
  • 13. Multi Module Projects • Maven has 1st class multi-module support • Each maven project creates 1 primary artifact • A parent pom is used to group modules <project> ... <packaging>pom</packaging> <modules> <module>maven-training</module> <module>maven-training-web</module> </modules> </project>
  • 14. Maven Conventions • Maven is opinionated about project structure • target: Default work directory • src: All project source files go in this directory • src/main: All sources that go into primary artifact • src/test: All sources contributing to testing project • src/main/java: All java source files • src/main/webapp: All web source files • src/main/resources: All non compiled source files • src/test/java: All java test source files • src/test/resources: All non compiled test source files
  • 15. Maven Build Lifecycle • A Maven build follow a lifecycle • Default lifecycle – generate-sources/generate-resources – compile – test – package – integration-test (pre and post) – Install – deploy • There is also a Clean lifecycle
  • 16. Example Maven Goals • To invoke a Maven build you set a lifecycle “goal” • mvn install – Invokes generate* and compile, test, package, integration-test, install • mvn clean – Invokes just clean • mvn clean compile – Clean old builds and execute generate*, compile • mvn compile install – Invokes generate*, compile, test, integration-test, package, install • mvn test clean – Invokes generate*, compile, test then cleans
  • 17. Maven and Dependencies • Maven revolutionized Java dependency management – No more checking libraries into version control • Introduced the Maven Repository concept – Established Maven Central • Created a module metadata file (POM) • Introduced concept of transitive dependency • Often include source and javadoc artifacts
  • 18. Adding a Dependency • Dependencies consist of: – GAV – Scope: compile, test, provided (default=compile) – Type: jar, pom, war, ear, zip (default=jar) <project> ... <dependencies> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> </dependencies> </project>
  • 19. Maven Repositories • Dependencies are downloaded from repositories – Via http • Downloaded dependencies are cached in a local repository – Usually found in ${user.home}/.m2/repository • Repository follows a simple directory structure – {groupId}/{artifactId}/{version}/{artifactId}-{version}.jar – groupId ‘.’ is replaced with ‘/’ • Maven Central is primary community repo – http://repo1.maven.org/maven2
  • 20. Proxy Repositories • Proxy Repositories are useful: – Organizationally cache artifacts – Allow organization some control over dependencies – Combines repositories • ICS uses the Nexus repository manager • All artifacts in Nexus go through approval process – License verified – Improve organizational reuse • To request approval create issue in SDS jira project: – https://jira.ldschurch.org/jira/browse/SDS
  • 21. Defining a repository • Repositories are defined in the pom • Repositories can be inherited from parent • Repositories are keyed by id • Downloading snapshots can be controlled <project> ... <repositories> <repository> <id>lds-main</id> <name>LDS Main Repo</name> <url>http://code.lds.org/nexus/content/groups/main-repo</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> </project>
  • 22. Transitive Dependencies • Transitive Dependency Definition: – A dependency that should be included when declaring project itself is a dependency • ProjectA depends on ProjectB • If ProjectC depends on ProjectA then ProjectB is automatically included • Only compile and runtime scopes are transitive • Transitive dependencies are controlled using: – Exclusions – Optional declarations
  • 23. Dependency Exclusions • Exclusions exclude transitive dependencies • Dependency consumer solution <project> ... <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.0.5.RELEASE</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> </exclusions> </dependency> </dependencies> </project>
  • 24. Optional Dependencies • Don’t propagate dependency transitively • Dependency producer solution • Optional is under used <project> ... <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.0.5.RELEASE</version> <optional>true</optional> </dependency> </dependencies> </project>
  • 25. Dependency Management • What do you do when versions collide? – Allow Maven to manage it? • Complex and less predictable – Take control yourself • Manage the version manually • In Java you cannot use both versions <project> ... <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.0.5.RELEASE</version> </dependency> </dependencies> </dependencyManagement> </project>
  • 26. Using Dependency Management • Other uses for Dependency Management – Allowing parent pom to manage versions – Unify exclusions <project> ... <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.0.5.RELEASE</version> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> </dependency> <!-- Look ma, no version! --> </dependencies> </project>
  • 27. Summary • Maven is a different kind of build tool • It is easy to create multi-module builds • Dependencies are awesome

Notas do Editor

  1. A few disclaimers to get things started