23
Pulling ITSM together Cedric Gatay - [email protected] Maven Tips & Tricks Brown Bag Lunch - January 2013 1 jeudi 17 janvier 13

Maven Tips - Lunch break slides

Embed Size (px)

DESCRIPTION

Quick tips and tricks done @SRMvision during a lunch break

Citation preview

Page 1: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

MavenTips & Tricks

Brown Bag Lunch - January 2013

1

jeudi 17 janvier 13

Page 2: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

Lifecycle1. process-resources

2. compile

3. process-test-resources

4. test-compile

5. test

6. package

7. install

8. deploy

2

jeudi 17 janvier 13

Page 3: Maven Tips - Lunch break slides

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

jeudi 17 janvier 13

Page 4: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

Artifacts naming

• groupId:artifactId:[classifier:]type:version

4

jeudi 17 janvier 13

Page 5: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

Artifacts naming

• groupId:artifactId:[classifier:]type:version

• follows package naming convention

• reverse FQDN

5

jeudi 17 janvier 13

Page 6: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

Artifacts naming

• groupId:artifactId:[classifier:]type:version

• short explicit names are the best

6

jeudi 17 janvier 13

Page 7: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

Artifacts naming

• groupId:artifactId:[classifier:]type:version

• optional

• allows to specify special versions

7

jeudi 17 janvier 13

Page 8: Maven Tips - Lunch break slides

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

jeudi 17 janvier 13

Page 9: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

Artifacts naming

• groupId:artifactId:[classifier:]type:version

• version number (dot formatted)

• -SNAPSHOT are in development dep.

9

jeudi 17 janvier 13

Page 10: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

Project inheritance

• Allows to group common configuration

• repositories

• codestyle...

• Ease project understanding

10

jeudi 17 janvier 13

Page 11: Maven Tips - Lunch break slides

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

jeudi 17 janvier 13

Page 12: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

Dependencies

• Don’t Repeat Yourself

• Make your dependencies consistent

12

jeudi 17 janvier 13

Page 13: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

Dependencies

• Super POM does the dependenciesManagement

• <groupId>, <artifactId>, <version>, <scope>, <exclusions>

13

jeudi 17 janvier 13

Page 14: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

jeudi 17 janvier 13

Page 15: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

Dependencies

• POMs inherit the Super POM

• only use <dependencies>

• <groupId>, <artifactId>

• specific <scope>

15

jeudi 17 janvier 13

Page 16: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

jeudi 17 janvier 13

Page 17: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

Dependencies

• Plugins follow the same rule

• <pluginManagement> in Super POM

• common <configuration>

17

Always fix plugins’ versions

jeudi 17 janvier 13

Page 18: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

Dependencies

• Plugins follow the same rule

• <plugin> in children

• specific <configuration>

18

jeudi 17 janvier 13

Page 19: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

Properties

• Ease dependency upgrade

• only one value to update

• See all dependencies versions at once

19

jeudi 17 janvier 13

Page 20: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

Troubleshoot

• Debug

• mvn -X

• Work offline

• mvn -o | --offline

20

jeudi 17 janvier 13

Page 21: Maven Tips - Lunch break slides

Pulling ITSM together Cedric Gatay - [email protected]

Troubleshoot

• Get the computed POM

• mvn help:effective-pom

• Get the dependency tree

• mvn dependency:tree

21

jeudi 17 janvier 13

Page 22: Maven Tips - Lunch break slides

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

jeudi 17 janvier 13

Page 23: Maven Tips - Lunch break slides

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

jeudi 17 janvier 13