maven2 · a presentation is not a documentation! ... 2 – short introduction 3 – maven2 advanced...

52
Maven2 Configuration and Build Management Robert Reiz

Upload: others

Post on 04-Oct-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

Maven2

Configuration and Build Management

Robert Reiz

Page 2: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 2

A presentation is not a documentation!

A presentation should just support the speaker!

Page 3: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 3

1 – What is Maven2

2 – Short Introduction

3 – Maven2 Advanced

Page 4: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 4

1 What is Maven?

Page 5: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 5

1 – What is Maven?

- Maven exist since 2001.

- Maven2 exist since 2003.

- Maven2 is a completely new development.

- Maven2 is not compatible to Maven1.

- Maven3 is compatible to Maven2.

Page 6: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 6

- A better Ant?

- Project Description / Project Management

- Reporting (Metrics, Code Coverage, Tracking)

- Documentation

- Testing

1 – What is Maven?

Page 7: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 7

- Description of Dependencys

- Convention over Configuration?

- Best Practice

- DRY

- Lifecycle

1 – What is Maven?

Page 8: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 8

/src/ /pom.xml

1 – What is Maven?

Page 9: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 9

/src/ /target/ /pom.xml

1 – What is Maven?

Page 10: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 10

/src/ main/ test/ site/

/pom.xml

1 – What is Maven?

Page 11: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 11

/src/ main/ java/ resources/ webcontent/ test/ site/

/pom.xml

1 – What is Maven?

Page 12: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 12

/src/ main/ java/ resources/ webcontent/ test/ java/ resources/ site/

/pom.xml

1 – What is Maven?

Page 13: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 13

/src/ main/ java/ org.ploin.app.Start.java resources/ webcontent/ test/ java/ org.ploin.app.StartTest.java resources/ site/

/pom.xml

1 – What is Maven?

Page 14: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 14

/src/ main/ java/ org.ploin.app.Start.java resources/ webcontent/ test/ java/ org.ploin.app.StartTest.java resources/ site/

/pom.xml

1 – What is Maven?

Page 15: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 15

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>MyFirstMaven</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>

1 – What is Maven?

Page 16: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 16

http://repo1.maven.org/maven2/

Commandline command: mvn compile

1 – What is Maven?

Page 17: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 17

~/.m2/repository/

1 – What is Maven?

Page 18: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 18

Lifecycle - Phases

•  validate •  compile •  test •  package •  integration-test •  install •  deploy

1 – What is Maven?

Page 19: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 19

Maven Commands:

•  mvn compile •  mvn test •  mvn package •  mvn install •  mvn eclipse:eclipse •  mvn idea:idea •  mvn clean

1 – What is Maven?

Page 20: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 20

Maven Packeging:

•  ploinMailFactory-1.3.1.jar •  ploinMailFactory-1.3.1-javadoc.jar •  ploinMailFactory-1.3.1-sources.jar

•  ploinMailFactory-1.3.1-jdk5.jar •  ploinMailFactory-1.3.1-jdk1.4.jar

1 – What is Maven?

Page 21: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 21

Maven Packeging: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin>

1 – What is Maven?

Page 22: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 22

Maven Packeging:

mvn -DdownloadJavadocs -DdownloadSources idea:idea

mvn -DdownloadJavadocs –DdownloadSources eclipse:eclipse

1 – What is Maven?

Page 23: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 23

2 Short Introduction

Page 24: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 24

2 – Short Introduction

http://maven.apache.org/

Page 25: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 25

1.  Download Zip File.

2.  Unzip.

2 – Short Introduction

Page 26: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 26

1.  export PATH = $PATH:pathToMaven2/bin

2.  export M2_HOME = pathToMaven2

3.  export M2 = pathToMaven2/bin

4.  export JAVA_HOME = pathToYourJavaHome

2 – Short Introduction

Page 27: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 27

2 – Short Introduction

Page 28: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 28

Quick online introduction: Maven-Quickinstall: http://robert-reiz.com/2008/02/21/maven2-quickinstall-2/ Maven-Quickinstall for Mac OS X: http://robert-reiz.com/2010/10/02/maven2-quickinstall-for-mac-os-x/

2 – Short Introduction

Page 29: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 29

indt

Eclipse-Plugin

Page 30: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 30

2 – Short Introduction

Page 31: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time

2 – Short Introduction

Page 32: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time

http://m2eclipse.sonatype.org/update/

2 – Short Introduction

Page 33: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time

2 – Short Introduction

Page 34: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 34

Maven2 - Import Project into Eclipse

Page 35: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 35

In Project-Root (where the pom.xml is located): mvn eclipse:eclipse!! This command generates Eclipse Metafiles

2 – Short Introduction

Page 36: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time

2 – Short Introduction

Page 37: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time

2 – Short Introduction

Page 38: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time

2 – Short Introduction

Page 39: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time

Short Intro: Maven-Quickinstall + Eclipse: http://robert-reiz.com/2008/02/21/maven2-quickinstall-2/

2 – Short Introduction

Page 40: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 40

Live Demo

Page 41: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 41

3 Maven2 Advanced

Page 42: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 42

3 – Maven2 Advanced

Dependencies & Exclusions

<dependency> <groupId>org.springframework</groupId> <artifactId>spring-hibernate3</artifactId> <version>[2.0.8,)</version> <scope>compile</scope> <exclusions> <exclusion> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> </exclusion> </exclusions>

</dependency>

Page 43: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 43

Dependencies – version ranges

<version>[1.0,)</version> -> always the newest version

<version>(,1.0],[1.2,)</version> -> everything but not 1.1

<version>[1.0,2.0]</version> -> everything from 1.0 to 2.0

3 – Maven2 Advanced

Page 44: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 44

Maven through Proxies

<settings> . . <proxies> <proxy> <active>true</active> <protocol>http</protocol>

<host>proxy.somewhere.com</host> <port>8080</port> <username>proxyuser</username> <password>somepassword</password> <nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts> </proxy> </proxies> . .

</settings>

3 – Maven2 Advanced

Page 45: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 45

Your own M2 Repository Server

3 – Maven2 Advanced

Page 46: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 46

3 – Maven2 Advanced

Page 47: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 47

Archetypes

3 – Maven2 Advanced

Page 48: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 48

mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app

mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=com.mycompany.app -DartifactId=my-webapp

3 – Maven2 Advanced

Page 49: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 49

http://robert-reiz.com/tutorials/archetypes/

3 – Maven2 Advanced

Page 50: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 50

Archetypes Demo

Page 51: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 51

Page 52: Maven2 · A presentation is not a documentation! ... 2 – Short Introduction 3 – Maven2 Advanced . PLOIN – Because it's your time Seite 4 1 What is Maven? PLOIN – Because it's

PLOIN – Because it's your time Seite 52

? ? ?