SlideShare a Scribd company logo
1 of 36
Embrace Maven
Guy Marom
Part 1 - Build Tools
What’s it like without a build tool
Part 1 – Build Tools
1.javac -cp ./lib/guava-16.0.jar –d ./target ./src
2.jar cf myService.jar ./target
What’s it like without a build tool
Part 1 – Build Tools
But where did those 3rd party jars come from?
And what if I also want to test my code??
And what if I have several modules???
Maybe like 500…
And if my modules depend on each
other????
Part 1 – Build Tools
This can get very frustrating, very fast!
Some Build tools
Part 1 – Build Tools
C, C++ - Make
Scala - SBT
JavaScript - Grunt, Bower
Java - Ant + Ivy, Maven, Gradle
Part 2 - Maven
Maven’s Philosophy
Part 2 - Maven
Convention over configuration
A Dependency Manager
Part 2 - Maven
• Handles internal and external dependencies
• Local cache ~/.m2
• Provides dependencies for compilation and tests
• Maven central includes most common dependencies
guava-13.0
Image Fetching
Service
Images Rest
API
Internal
External
A Plugin Execution Framework
Part 2 - Maven
• Executes plugins sequentially
• There are plugins for compilation, testing, creating
jars
Maven’s Lifecycles
Part 2 - Maven
A lifecycle is a collection of phases
• clean – Cleaning up stuff…
• site – Creating the project’s site
• deploy – The one you all know and love
Phases
Part 2 - Maven
A lifecycle is composed of phases
• clean – A single phase called clean
• deploy – Several phases deploy lifecycle phases
validate
compile
test
package
verify
install
deploy
mvn install
Plugins and Goals
Part 2 - Maven
• Plugin examples
• maven-compiler-plugin
• maven-jar-plugin
• To run a plugin - mvn <PluginName>:<Goal>
mvn dependency:tree
maven-dependency-plugin
tree analyze
unpack
deploy lifecycle phases
validate
compile
test
package
verify
install
deploy
Some Default Bindings
Part 2 - Maven
• maven-compiler-plugin:compile
• maven-surefire-plugin:test
• maven-jar-plugin:jar
• maven-install-plugin:install
The Execution Pipeline
Part 2 - Maven
Phases
Plugins & Goals
compile test package
maven-jar-plugin
jar
maven-compiler-plugin
compile
maven-surefire-plugin
test
More Than One Plugin In a Phase
Part 2 - Maven
package
maven-jar-plugin
jar
maven-assembly-plugin
tar
Part 3 - The POM
POM
Part 3 – The POM
• It’s an XML file (ouch!)
• Contains project identifier
GAV - groupId:artifactId:version (com.outbrain:ob1k:1.0.1)
• Build info - steps to run during the build
• Dependencies - the “needs” of my project
• Inheritable
Project Structure
Part 3 – The POM
The Super POM
Part 3 – The POM
• Ancestor of all POMs, contains defaults
• Used directories (sources, resources, target)
• Plugin versions
• Maven central repository for downloading dependencies
(junit, hibernate, spring etc.)
Sections in the POM
Part 3 – The POM
The properties Section
Part 3 – The POM
• Key-values – to be used within the POM
• Properties may use each other
The dependencies Section
Part 3 – The POM
• To add a dependency use its GAV
• Dependencies have a scope
Dependency Conflicts
Part 3 – The POM
guava-13.0 guava-18.0
Image Fetching
Service
Image Resize
Service
Images Rest
API
Images DAL Image Sizes
DAL
The dependencyManagement Section
Part 3 – The POM
• Defines dependencies’ versions in a centralized
location
• Helps avoid version conflicts – as long as all child
modules never declare a version
Dependency management Child module
The build Section
Part 3 – The POM
• Build enrichment using plugins for
• Compiling other languages
• Creating different types of archives
IntelliJ Integration
Part 3 – The POM
• IntelliJ can convert the POM into its own project
model
• Re-import rebuilds IntelliJ’s model
• Completely unrelated to mvn clean install
Part 4 - In Practice
Command Line Options
Part 4 – In Practice
• -pl - build specific project(s)
mvn clean install -pl ImageFetchingService,ImageSizesService
• -am - also build project’s dependencies
mvn clean install -pl ImageFetchingService -am
• -amd - also build dependent projects
mvn clean install -pl ImageFetchingService -amd
• -T – parallel build
mvn clean install -T 1C
• -X – Debug level logging
Image Fetching
Service
Image Resize
Service
Images Rest
API
Images DAL Image Sizes
DAL
Running Tests
Part 4 – In Practice
• Run all tests
mvn test
• Run a specific test
mvn test -Dtest=<ClassName>#<TestMethod>
• http://maven.apache.org/surefire/maven-surefire-plugin/index.html
deploy lifecycle phases
validate
compile
test
package
verify
install
deploy
Unused Dependencies
Part 4 – In Practice
• The risk of a version conflict increases
• Your applications will become bigger for no reason
• It’s harder to separate projects
maven-dependency-plugin
Part 4 – In Practice
• mvn dependency:tree -pl <ModuleName> -Dverbose
• mvn dependency:analyze -pl <ModuleName>
• Other useful goals
• copy-dependencies
• unpack
• http://maven.apache.org/plugins/maven-dependency-plugin/
Dependency Conflicts
Part 4 – In Practice
Image Fetching
Service
Image Resize Service
Images Rest API
guava 13.0 guava 18.0
Online Plugin Documentation
Part 4 – In Practice
Part 5 – Maven vs. Gradle
Some Points of Difference
Part 5 - Gradle
• Learning curve – Maven is easier
• Flexibility – Gradle’s strength, it’s easier to define
custom behavior.
• Features – incremental building, in-script logging,
self-documenting tasks (gradle tasks)

More Related Content

What's hot

Version Management in Maven
Version Management in MavenVersion Management in Maven
Version Management in Maven
Geert Pante
 
Java build tools
Java build toolsJava build tools
Java build tools
Sujit Kumar
 
Continuous Deployment Pipeline with maven
Continuous Deployment Pipeline with mavenContinuous Deployment Pipeline with maven
Continuous Deployment Pipeline with maven
Alan Parkinson
 

What's hot (20)

An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Build Tools & Maven
Build Tools & MavenBuild Tools & Maven
Build Tools & Maven
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Jenkins
JenkinsJenkins
Jenkins
 
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
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
Jenkins presentation
Jenkins presentationJenkins presentation
Jenkins presentation
 
Version Management in Maven
Version Management in MavenVersion Management in Maven
Version Management in Maven
 
Introduction to Apache Maven
Introduction to Apache MavenIntroduction to Apache Maven
Introduction to Apache Maven
 
Java build tools
Java build toolsJava build tools
Java build tools
 
Continuous Deployment Pipeline with maven
Continuous Deployment Pipeline with mavenContinuous Deployment Pipeline with maven
Continuous Deployment Pipeline with maven
 
Jenkins Pipelines
Jenkins PipelinesJenkins Pipelines
Jenkins Pipelines
 
Testing Java Web Apps With Selenium
Testing Java Web Apps With SeleniumTesting Java Web Apps With Selenium
Testing Java Web Apps With Selenium
 
Apache Maven for SoftServe IT Academy
Apache Maven for SoftServe IT AcademyApache Maven for SoftServe IT Academy
Apache Maven for SoftServe IT Academy
 
Pipeline based deployments on Jenkins
Pipeline based deployments  on JenkinsPipeline based deployments  on Jenkins
Pipeline based deployments on Jenkins
 
Symfony 2 under control
Symfony 2 under controlSymfony 2 under control
Symfony 2 under control
 
Introduction to maven
Introduction to mavenIntroduction to maven
Introduction to maven
 
Maven for Dummies
Maven for DummiesMaven for Dummies
Maven for Dummies
 

Viewers also liked

Trabajo final 2do perido
Trabajo final 2do peridoTrabajo final 2do perido
Trabajo final 2do perido
DannyBui
 
On site malta Präsentation DMC aus Malta
On site malta   Präsentation DMC aus MaltaOn site malta   Präsentation DMC aus Malta
On site malta Präsentation DMC aus Malta
MICEboard
 
Olimpiada alicante 2011
Olimpiada alicante 2011Olimpiada alicante 2011
Olimpiada alicante 2011
Aldhair Medico
 
Los siete hábitos de los adolescentes altamente efectivos
Los siete hábitos de los adolescentes altamente efectivosLos siete hábitos de los adolescentes altamente efectivos
Los siete hábitos de los adolescentes altamente efectivos
Rufeyela H-p
 

Viewers also liked (20)

Migrating 25K lines of Ant scripting to Gradle
Migrating 25K lines of Ant scripting to GradleMigrating 25K lines of Ant scripting to Gradle
Migrating 25K lines of Ant scripting to Gradle
 
JavaOne 2015: Scalable Continous Deployment with Maven
JavaOne 2015: Scalable Continous Deployment with MavenJavaOne 2015: Scalable Continous Deployment with Maven
JavaOne 2015: Scalable Continous Deployment with Maven
 
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven DesignModelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
Idiomatic Gradle Plugin Writing - GradleSummit 2016
Idiomatic Gradle Plugin Writing - GradleSummit 2016Idiomatic Gradle Plugin Writing - GradleSummit 2016
Idiomatic Gradle Plugin Writing - GradleSummit 2016
 
Trabajo final 2do perido
Trabajo final 2do peridoTrabajo final 2do perido
Trabajo final 2do perido
 
Proyecto nube
Proyecto nubeProyecto nube
Proyecto nube
 
On site malta Präsentation DMC aus Malta
On site malta   Präsentation DMC aus MaltaOn site malta   Präsentation DMC aus Malta
On site malta Präsentation DMC aus Malta
 
God’s last name is not
God’s last name is notGod’s last name is not
God’s last name is not
 
Gujarat Dreams
Gujarat DreamsGujarat Dreams
Gujarat Dreams
 
Olimpiada alicante 2011
Olimpiada alicante 2011Olimpiada alicante 2011
Olimpiada alicante 2011
 
Bibliotech_04-05
Bibliotech_04-05Bibliotech_04-05
Bibliotech_04-05
 
Amen ma's sura.vol.1.pic.doc.html
Amen ma's sura.vol.1.pic.doc.htmlAmen ma's sura.vol.1.pic.doc.html
Amen ma's sura.vol.1.pic.doc.html
 
Los siete hábitos de los adolescentes altamente efectivos
Los siete hábitos de los adolescentes altamente efectivosLos siete hábitos de los adolescentes altamente efectivos
Los siete hábitos de los adolescentes altamente efectivos
 
O que é o instituto shc
O que é o instituto shcO que é o instituto shc
O que é o instituto shc
 
Aztex of da wise.vol.3.new.pic.doc.html
Aztex of da wise.vol.3.new.pic.doc.htmlAztex of da wise.vol.3.new.pic.doc.html
Aztex of da wise.vol.3.new.pic.doc.html
 
Responsabilidad penal adolescente: TRIBUNALES DE TRATAMIENTO DE DROGA (TTD).
Responsabilidad penal adolescente: TRIBUNALES DE TRATAMIENTO DE DROGA (TTD).  Responsabilidad penal adolescente: TRIBUNALES DE TRATAMIENTO DE DROGA (TTD).
Responsabilidad penal adolescente: TRIBUNALES DE TRATAMIENTO DE DROGA (TTD).
 
Presentació iniciacio
Presentació iniciacioPresentació iniciacio
Presentació iniciacio
 
Caso Real
Caso RealCaso Real
Caso Real
 
Taller nº 1 melanie espin acosta 1º psicologia
Taller nº 1 melanie espin acosta 1º psicologiaTaller nº 1 melanie espin acosta 1º psicologia
Taller nº 1 melanie espin acosta 1º psicologia
 

Similar to Embrace Maven

Juggling Java EE with Enterprise Apache Maven
Juggling Java EE with Enterprise Apache MavenJuggling Java EE with Enterprise Apache Maven
Juggling Java EE with Enterprise Apache Maven
elliando dias
 

Similar to Embrace Maven (20)

Maven
MavenMaven
Maven
 
A-Z_Maven.pdf
A-Z_Maven.pdfA-Z_Maven.pdf
A-Z_Maven.pdf
 
Juggling Java EE with Enterprise Apache Maven
Juggling Java EE with Enterprise Apache MavenJuggling Java EE with Enterprise Apache Maven
Juggling Java EE with Enterprise Apache Maven
 
4 maven junit
4 maven junit4 maven junit
4 maven junit
 
Maven
MavenMaven
Maven
 
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
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
(Re)-Introduction to Maven
(Re)-Introduction to Maven(Re)-Introduction to Maven
(Re)-Introduction to Maven
 
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
 
Continuous Delivery, Continuous Integration
Continuous Delivery, Continuous Integration Continuous Delivery, Continuous Integration
Continuous Delivery, Continuous Integration
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Mavennotes.pdf
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using Maven
 
Maven
MavenMaven
Maven
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
 
Agile Software Development & Tools
Agile Software Development & ToolsAgile Software Development & Tools
Agile Software Development & Tools
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topic
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

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
 
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...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Embrace Maven

  • 2. Part 1 - Build Tools
  • 3. What’s it like without a build tool Part 1 – Build Tools 1.javac -cp ./lib/guava-16.0.jar –d ./target ./src 2.jar cf myService.jar ./target
  • 4. What’s it like without a build tool Part 1 – Build Tools But where did those 3rd party jars come from? And what if I also want to test my code?? And what if I have several modules??? Maybe like 500… And if my modules depend on each other????
  • 5. Part 1 – Build Tools This can get very frustrating, very fast!
  • 6. Some Build tools Part 1 – Build Tools C, C++ - Make Scala - SBT JavaScript - Grunt, Bower Java - Ant + Ivy, Maven, Gradle
  • 7. Part 2 - Maven
  • 8. Maven’s Philosophy Part 2 - Maven Convention over configuration
  • 9. A Dependency Manager Part 2 - Maven • Handles internal and external dependencies • Local cache ~/.m2 • Provides dependencies for compilation and tests • Maven central includes most common dependencies guava-13.0 Image Fetching Service Images Rest API Internal External
  • 10. A Plugin Execution Framework Part 2 - Maven • Executes plugins sequentially • There are plugins for compilation, testing, creating jars
  • 11. Maven’s Lifecycles Part 2 - Maven A lifecycle is a collection of phases • clean – Cleaning up stuff… • site – Creating the project’s site • deploy – The one you all know and love
  • 12. Phases Part 2 - Maven A lifecycle is composed of phases • clean – A single phase called clean • deploy – Several phases deploy lifecycle phases validate compile test package verify install deploy mvn install
  • 13. Plugins and Goals Part 2 - Maven • Plugin examples • maven-compiler-plugin • maven-jar-plugin • To run a plugin - mvn <PluginName>:<Goal> mvn dependency:tree maven-dependency-plugin tree analyze unpack
  • 14. deploy lifecycle phases validate compile test package verify install deploy Some Default Bindings Part 2 - Maven • maven-compiler-plugin:compile • maven-surefire-plugin:test • maven-jar-plugin:jar • maven-install-plugin:install
  • 15. The Execution Pipeline Part 2 - Maven Phases Plugins & Goals compile test package maven-jar-plugin jar maven-compiler-plugin compile maven-surefire-plugin test
  • 16. More Than One Plugin In a Phase Part 2 - Maven package maven-jar-plugin jar maven-assembly-plugin tar
  • 17. Part 3 - The POM
  • 18. POM Part 3 – The POM • It’s an XML file (ouch!) • Contains project identifier GAV - groupId:artifactId:version (com.outbrain:ob1k:1.0.1) • Build info - steps to run during the build • Dependencies - the “needs” of my project • Inheritable
  • 20. The Super POM Part 3 – The POM • Ancestor of all POMs, contains defaults • Used directories (sources, resources, target) • Plugin versions • Maven central repository for downloading dependencies (junit, hibernate, spring etc.)
  • 21. Sections in the POM Part 3 – The POM
  • 22. The properties Section Part 3 – The POM • Key-values – to be used within the POM • Properties may use each other
  • 23. The dependencies Section Part 3 – The POM • To add a dependency use its GAV • Dependencies have a scope
  • 24. Dependency Conflicts Part 3 – The POM guava-13.0 guava-18.0 Image Fetching Service Image Resize Service Images Rest API Images DAL Image Sizes DAL
  • 25. The dependencyManagement Section Part 3 – The POM • Defines dependencies’ versions in a centralized location • Helps avoid version conflicts – as long as all child modules never declare a version Dependency management Child module
  • 26. The build Section Part 3 – The POM • Build enrichment using plugins for • Compiling other languages • Creating different types of archives
  • 27. IntelliJ Integration Part 3 – The POM • IntelliJ can convert the POM into its own project model • Re-import rebuilds IntelliJ’s model • Completely unrelated to mvn clean install
  • 28. Part 4 - In Practice
  • 29. Command Line Options Part 4 – In Practice • -pl - build specific project(s) mvn clean install -pl ImageFetchingService,ImageSizesService • -am - also build project’s dependencies mvn clean install -pl ImageFetchingService -am • -amd - also build dependent projects mvn clean install -pl ImageFetchingService -amd • -T – parallel build mvn clean install -T 1C • -X – Debug level logging Image Fetching Service Image Resize Service Images Rest API Images DAL Image Sizes DAL
  • 30. Running Tests Part 4 – In Practice • Run all tests mvn test • Run a specific test mvn test -Dtest=<ClassName>#<TestMethod> • http://maven.apache.org/surefire/maven-surefire-plugin/index.html deploy lifecycle phases validate compile test package verify install deploy
  • 31. Unused Dependencies Part 4 – In Practice • The risk of a version conflict increases • Your applications will become bigger for no reason • It’s harder to separate projects
  • 32. maven-dependency-plugin Part 4 – In Practice • mvn dependency:tree -pl <ModuleName> -Dverbose • mvn dependency:analyze -pl <ModuleName> • Other useful goals • copy-dependencies • unpack • http://maven.apache.org/plugins/maven-dependency-plugin/
  • 33. Dependency Conflicts Part 4 – In Practice Image Fetching Service Image Resize Service Images Rest API guava 13.0 guava 18.0
  • 34. Online Plugin Documentation Part 4 – In Practice
  • 35. Part 5 – Maven vs. Gradle
  • 36. Some Points of Difference Part 5 - Gradle • Learning curve – Maven is easier • Flexibility – Gradle’s strength, it’s easier to define custom behavior. • Features – incremental building, in-script logging, self-documenting tasks (gradle tasks)

Editor's Notes

  1. Welcome to the Embrace Maven session. This presentation is for people who are using maven and want to learn a little more about it in order to be more effective with it.
  2. Yiddish for “מבין” At the time Maven was created, Ant was the most popular build tool. It was very verbose and it didn’t even have dependency management
  3. Maven’s philosophy - Convention over configuration = reasonable default behavior. A project that has no special needs can be very easily created. Just put your code under src/main/java and your tests under src/test/java etc.. By doing only that with a pom file you get a project that compiles, tests and packages itself. Opinionated means There’s a way to do stuff Doing stuff the wrong way has consequences
  4. Three built-in lifecycles - clean, deploy and site Clean has to do with cleaning stuff up (duh) – basically deletes your target folder Site creates the project’s site – htmls, test reports, javadoc Deploy is the lifecycle we’re using most of the time (compilation, testing etc.)
  5. Clean – has a single phase that cleans the target folder There are 8 phases in the deploy lifecycle, among them: compile - compiles java files and puts the classes file under target/classes (maven-compiler-plugin) tests - runs unit tests (surefire-plugin) package - creates a jar file, or any other configured package (maven-jar-plugin) install - installs the packages into the local repository (maven-install-plugin) Phases are additive so running mvn install will run all phases up to and including the install phase
  6. A plugin is a collection of goals The maven-dependency-plugin contains several goals, amongst them tree, analyze and unpack Other plugin examples – maven-compiler-plugin, maven-jar-plugin This is how you run a plugin with Maven...
  7. Convention over configuration here – most phases have by default plugins that are bound to them
  8. I mentioned that plugins “bind” to a phase, here’s what it looks like during maven’s execution
  9. POM stands for Project Object Model. The pom contains all info related to the project What to build When to do it Where should the artifacts be located It’s an XML file – back then XML was considered cool GAV - The unique identifier of the module. If a module is to be used by another one this is how you would reference it. Build info - what steps should run during the build, and at what order Dependencies needed in order to compile the project, test it and run it The data in the pom can be used by inheriting poms
  10. Here’s a sample project It has one parent projects and two children that inherit from it
  11. Father of all poms, contains defaults Used directories (sources, resources, target) Plugin versions Maven central repository link
  12. Gav + packaging (Default packaging is JAR) Properties – key-value items Dependencies – my project’s needs Dependency management Build – plugins to run during the build
  13. Dependencies are what the project needs in order to be compiled tested or run A dependency is added by adding its GAV to the dependencies section Dependencies can be scoped according to those needs. Compile is the default scope
  14. Imaginary app… What happens if the two services depend on conflicting versions of guava?
  15. Maven has a lot of plugins available for many many purposes
  16. Why are superfluous dependencies bad for you? Because of what’s written above. This is very important for open-source writers and in general people who release libraries for other people’s usage. You can keep your room filthy, but keep your living room spotless You don’t want your lib to be the cause for dependency conflicts
  17. dependency:tree – you can see what dependencies you have and where they came from. If you also want to see dependencies that maven did not take you should use –Dverbose
  18. Maven’s way to resolve conflicts is to avoid them - the dependency closest to the built module wins, and if there are two dependencies the same distance the first one declared wins. If you’re lucky nothing has changes between the versions and everything will work. If you’re less lucky you’ll get a compilation error (That’s if WebServer is using a transitive dependency of Guava). If you’re less lucky - it will fail in tests with a NoClassDefFoundError Even less lucky - it will fail in runtime. Worst luck - implementation has changed and you’ll get bugs and not know why :( It’s even possible for something in ImageFetchingService/ImageResizeService to break when running in the context of WebServer because the actual guava version in the classpath is different than the one they were tested with. That’s why it’s best to use dependency management and have uniform versions.
  19. Learning curve - Gradle is harder to learn. Probably any maven project you clone from github will be compiled by mvn clean install. Gradle is easier to add behavior to which means a person needs to learn your company’s comventions. Flexibility – adding behavior is very easy in gradle, you simply write a task inside the gradle file. For maven it’s either a new plugin or using ant or groovy plugins. Remember maven is opinionated Features Incremental building – Gradle’s is better. It recognized when the inputs/configuration of a task changed and executes that task Gradle files are code, you can just add logging inside gradle tasks – shows you the available tasks to run