Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML!...
Transcript of Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML!...
![Page 1: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/1.jpg)
Roberto Cortez Jfokus 2016
Maven Taming the Beast
![Page 2: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/2.jpg)
Roberto Cortez Speaker, Blogger, Triber, Passionate Developer
twitter: @radcortez
mail: [email protected]
blog: http://www.radcortez.com
![Page 3: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/3.jpg)
Do you hate Maven?
![Page 4: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/4.jpg)
It’s slow!
It’s verbose!
It’s XML!
Steep Learning Curve!
It’s complex!
It’s hard to extend!
It’s unreliable!
![Page 5: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/5.jpg)
Popularity
Source: Rebellabs
![Page 6: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/6.jpg)
Facts
• It’s around for more than 10 years
• All developers run into problems
• New developers go through the same hard
learning process
![Page 7: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/7.jpg)
Learn how to play with it!
• What are the most common pitfalls?
• How to fix them or debug them?
• Save countless hours of pain and frustration
![Page 8: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/8.jpg)
Why is this JAR in my Build?
POM Dep
Dep’’
Dep’’
Dep’
Dep’
Dep’
Dep’’’
Transitive Dependencies
![Page 9: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/9.jpg)
Why is this JAR in my Build?
• Use mvn dependency:analyze
• Exclude unneeded dependencies
• Some trial and error involved
![Page 10: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/10.jpg)
I can’t see my changes!
• Dependencies are not build in the local repo
• Dependency version is not correct
• Remote repo has overwritten changes
![Page 11: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/11.jpg)
I can’t see my changes!
POM
DepA
DepB
LocalRepo
RemoteRepo
Code Change
Local Install
mvn install
![Page 12: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/12.jpg)
I can’t see my changes!Dependency Mediation
POM
C
Dv1
A
B
Dv2
Who Wins?
Dv1
![Page 13: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/13.jpg)
I can’t see my changes!
• Use mvn dependency:tree
• SNAPSHOT versions from remote may override
your local changes
![Page 14: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/14.jpg)
A JAR is not being included!
• Usually related with Dependency Scopes
• Might also be excluded somewhere
• Use mvn dependency:list
![Page 15: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/15.jpg)
I can’t find the Artifact!
• “Could not resolve dependencies… Could not
find artifact”
• Even worst than the Java NPE
![Page 16: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/16.jpg)
I can’t find the Artifact!• Dependency defined correctly?
• Remote repo contains the artifact?
• Most recent pom version?
• Jar is corrupted?
• Cached artifact?
• Dependency overriden?
![Page 17: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/17.jpg)
Weapons of Choice
• mvn help:effective-pom
• mvn -Dmaven.repo=/temp/20160210/.m2
• mvn -o
![Page 18: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/18.jpg)
Bonus: Speedup your Build
• Build in parallel
• Build only the modules you need
• You should know about offline, right?
![Page 19: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/19.jpg)
Bonus: Speedup your Build
• mvn -T 1C install
• mvn install -pl moduleName -am / -amd
• mvn install -o
![Page 20: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/20.jpg)
Tamed?
![Page 21: Maven Taming the Beast - Jfokus · Do you hate Maven? It’s slow! It’s verbose! It’s XML! Steep Learning Curve! It’s complex! It’s hard to extend! It’s unreliable! Popularity](https://reader031.fdocuments.in/reader031/viewer/2022011822/5ec9d9bf19d4756e1547e343/html5/thumbnails/21.jpg)
Never trust the IDE!
If it works on the command-line then it’s an IDE problem!