Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Maven Tips & Tricks

Maven Tips & Tricks

Presentation done during lunch break at SRMvision. A quick summary of Maven best practices and useful commands to know when dealing with Maven.

Cedric Gatay

January 17, 2013

Transcript

23 slides
  1. Pulling ITSM together Cedric Gatay - [email protected] Lifecycle 1. process-resources

    2. compile 3. process-test-resources 4. test-compile 5. test 6. package 7. install 8. deploy 2
  2. Pulling ITSM together Cedric Gatay - [email protected] Search engines •

    http://search.maven.org/ • search through Maven Central • http://mvnrepository.com/ • http://nexus.srm • in house repository 3
  3. Pulling ITSM together Cedric Gatay - [email protected] Artifacts naming •

    groupId:artifactId:[classifier:]type:version • follows package naming convention • reverse FQDN 5
  4. Pulling ITSM together Cedric Gatay - [email protected] Artifacts naming •

    groupId:artifactId:[classifier:]type:version • short explicit names are the best 6
  5. Pulling ITSM together Cedric Gatay - [email protected] Artifacts naming •

    groupId:artifactId:[classifier:]type:version • optional • allows to specify special versions 7
  6. Pulling ITSM together Cedric Gatay - [email protected] Artifacts naming •

    groupId:artifactId:[classifier:]type:version • one of jar,pom,war,ear... • determines the nature of the dependency 8
  7. Pulling ITSM together Cedric Gatay - [email protected] Artifacts naming •

    groupId:artifactId:[classifier:]type:version • version number (dot formatted) • -SNAPSHOT are in development dep. 9
  8. Pulling ITSM together Cedric Gatay - [email protected] Project inheritance •

    Allows to group common configuration • repositories • codestyle... • Ease project understanding 10
  9. Pulling ITSM together Cedric Gatay - [email protected] Dependencies • Scopes

    • compile (default) : required for the app • runtime : only necessary at runtime • provided : available by the container • test : required for testing phase • system : absolute path (avoid this) 11
  10. Pulling ITSM together Cedric Gatay - [email protected] Dependencies • Don’t

    Repeat Yourself • Make your dependencies consistent 12
  11. Pulling ITSM together Cedric Gatay - [email protected] Dependencies • Super

    POM does the dependenciesManagement • <groupId>, <artifactId>, <version>, <scope>, <exclusions> 13
  12. Pulling ITSM together Cedric Gatay - [email protected] Dependencies • POMs

    inherit the Super POM • only use <dependencies> • <groupId>, <artifactId> • specific <scope> 15
  13. Pulling ITSM together Cedric Gatay - [email protected] Dependencies • Plugins

    follow the same rule • <pluginManagement> in Super POM • common <configuration> 17 Always fix plugins’ versions
  14. Pulling ITSM together Cedric Gatay - [email protected] Dependencies • Plugins

    follow the same rule • <plugin> in children • specific <configuration> 18
  15. Pulling ITSM together Cedric Gatay - [email protected] Properties • Ease

    dependency upgrade • only one value to update • See all dependencies versions at once 19
  16. Pulling ITSM together Cedric Gatay - [email protected] Troubleshoot • Debug

    • mvn -X • Work offline • mvn -o | --offline 20
  17. Pulling ITSM together Cedric Gatay - [email protected] Troubleshoot • Get

    the computed POM • mvn help:effective-pom • Get the dependency tree • mvn dependency:tree 21
  18. Pulling ITSM together Cedric Gatay - [email protected] Clean local repository

    • wget https://raw.github.com/CedricGatay/small- scripts/master/groovy/CleanDir.groovy • groovy CleanDir.groovy • groovy -DdryRun=false CleanDir.groovy 22
  19. Pulling ITSM together Cedric Gatay - [email protected] Resources • Apache

    Maven http://maven.apache.org/ • Maven dependency plugin http://maven.apache.org/plugins/maven-dependency-plugin/ • CleanDir groovy script https://raw.github.com/jettro/small-scripts/master/groovy/CleanDir.groovy 23

More Decks by Cedric Gatay

Other Decks in Programming