SlideShare a Scribd company logo
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

PDF
Build Automation using Maven
PPTX
Learning Maven by Example
PPTX
Ci jenkins maven svn
PDF
Continuous delivery-with-maven
PDF
Automated Deployment with Maven - going the whole nine yards
PPTX
Introduction to Maven
PPTX
Build Automation using Maven
Learning Maven by Example
Ci jenkins maven svn
Continuous delivery-with-maven
Automated Deployment with Maven - going the whole nine yards
Introduction to Maven

What's hot (20)

PPTX
An introduction to Maven
PPTX
Maven tutorial
PPTX
Build Tools & Maven
PPTX
Introduction to Maven
PDF
Maven tutorial
PPTX
PPTX
Maven plugins, properties en profiles: Advanced concepts in Maven
PPTX
Maven ppt
PPTX
Jenkins presentation
PPTX
Version Management in Maven
PDF
Introduction to Apache Maven
PPTX
Java build tools
PPTX
Continuous Deployment Pipeline with maven
PDF
Jenkins Pipelines
PPT
Testing Java Web Apps With Selenium
PPTX
Apache Maven for SoftServe IT Academy
ODP
Pipeline based deployments on Jenkins
PPTX
Symfony 2 under control
PPTX
Introduction to maven
PPTX
Maven for Dummies
An introduction to Maven
Maven tutorial
Build Tools & Maven
Introduction to Maven
Maven tutorial
Maven plugins, properties en profiles: Advanced concepts in Maven
Maven ppt
Jenkins presentation
Version Management in Maven
Introduction to Apache Maven
Java build tools
Continuous Deployment Pipeline with maven
Jenkins Pipelines
Testing Java Web Apps With Selenium
Apache Maven for SoftServe IT Academy
Pipeline based deployments on Jenkins
Symfony 2 under control
Introduction to maven
Maven for Dummies
Ad

Viewers also liked (20)

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

Similar to Embrace Maven (20)

PDF
Introduction to maven, its configuration, lifecycle and relationship to JS world
ODP
Maven in Java EE project
PPT
Intro to Maven.ppt
PDF
BMO - Intelligent Projects with Maven
PDF
Mavennotes.pdf
PDF
Intelligent Projects with Maven - DevFest Istanbul
PPT
Introduction tomaven
PPT
Introduction to Maven for projects and carrer ppt
PPTX
PPTX
Apache Maven basics
PPT
MAVEN
PDF
Java Builds with Maven and Ant
PDF
Apache maven
PDF
Fundamental of apache maven
PPTX
(Re)-Introduction to Maven
PPTX
Introduction to Maven for beginners and DevOps
PDF
Apache maven, a software project management tool
PPTX
Maven Basics - Explained
Introduction to maven, its configuration, lifecycle and relationship to JS world
Maven in Java EE project
Intro to Maven.ppt
BMO - Intelligent Projects with Maven
Mavennotes.pdf
Intelligent Projects with Maven - DevFest Istanbul
Introduction tomaven
Introduction to Maven for projects and carrer ppt
Apache Maven basics
MAVEN
Java Builds with Maven and Ant
Apache maven
Fundamental of apache maven
(Re)-Introduction to Maven
Introduction to Maven for beginners and DevOps
Apache maven, a software project management tool
Maven Basics - Explained

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
KodekX | Application Modernization Development
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Approach and Philosophy of On baking technology
PDF
Empathic Computing: Creating Shared Understanding
PPT
Teaching material agriculture food technology
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Cloud computing and distributed systems.
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
20250228 LYD VKU AI Blended-Learning.pptx
cuic standard and advanced reporting.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
KodekX | Application Modernization Development
Per capita expenditure prediction using model stacking based on satellite ima...
Dropbox Q2 2025 Financial Results & Investor Presentation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Monthly Chronicles - July 2025
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Approach and Philosophy of On baking technology
Empathic Computing: Creating Shared Understanding
Teaching material agriculture food technology
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Encapsulation_ Review paper, used for researhc scholars
Understanding_Digital_Forensics_Presentation.pptx
Cloud computing and distributed systems.
Spectral efficient network and resource selection model in 5G networks
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

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

  • #2: 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.
  • #8: 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
  • #9: 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
  • #12: 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.)
  • #13: 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
  • #14: 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...
  • #15: Convention over configuration here – most phases have by default plugins that are bound to them
  • #16: I mentioned that plugins “bind” to a phase, here’s what it looks like during maven’s execution
  • #19: 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
  • #20: Here’s a sample project It has one parent projects and two children that inherit from it
  • #21: Father of all poms, contains defaults Used directories (sources, resources, target) Plugin versions Maven central repository link
  • #22: Gav + packaging (Default packaging is JAR) Properties – key-value items Dependencies – my project’s needs Dependency management Build – plugins to run during the build
  • #24: 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
  • #25: Imaginary app… What happens if the two services depend on conflicting versions of guava?
  • #27: Maven has a lot of plugins available for many many purposes
  • #32: 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
  • #33: 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
  • #34: 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.
  • #37: 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