Maven2 Configuration and Build Management Robert Reiz
A presentation is not a documentation! A presentation should just support the speaker! PLOIN Because it's your time Seite 2
1 What is Maven2 2 Short Introduction 3 Maven2 Advanced PLOIN Because it's your time Seite 3
1 What is Maven? PLOIN Because it's your time Seite 4
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. PLOIN Because it's your time Seite 5
1 What is Maven? - A better Ant? - Project Description / Project Management - Reporting (Metrics, Code Coverage, Tracking) - Documentation - Testing PLOIN Because it's your time Seite 6
1 What is Maven? - Description of Dependencys - Convention over Configuration? - Best Practice - DRY - Lifecycle PLOIN Because it's your time Seite 7
1 What is Maven? /src/ /pom.xml PLOIN Because it's your time Seite 8
1 What is Maven? /src/ /target/ /pom.xml PLOIN Because it's your time Seite 9
1 What is Maven? /src/ main/ test/ site/ /pom.xml PLOIN Because it's your time Seite 10
1 What is Maven? /src/ main/ java/ resources/ webcontent/ test/ site/ /pom.xml PLOIN Because it's your time Seite 11
1 What is Maven? /src/ main/ java/ resources/ webcontent/ test/ java/ resources/ site/ /pom.xml PLOIN Because it's your time Seite 12
1 What is Maven? /src/ main/ java/ org.ploin.app.start.java resources/ webcontent/ test/ java/ org.ploin.app.starttest.java resources/ site/ /pom.xml PLOIN Because it's your time Seite 13
1 What is Maven? /src/ main/ java/ org.ploin.app.start.java resources/ webcontent/ test/ java/ org.ploin.app.starttest.java resources/ site/ /pom.xml PLOIN Because it's your time Seite 14
1 What is Maven? <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> PLOIN Because it's your time Seite 15
1 What is Maven? Commandline command: mvn compile http://repo1.maven.org/maven2/ PLOIN Because it's your time Seite 16
1 What is Maven? ~/.m2/repository/ PLOIN Because it's your time Seite 17
1 What is Maven? Lifecycle - Phases validate compile test package integration-test install deploy PLOIN Because it's your time Seite 18
1 What is Maven? Maven Commands: mvn compile mvn test mvn package mvn install mvn eclipse:eclipse mvn idea:idea mvn clean PLOIN Because it's your time Seite 19
1 What is Maven? 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 PLOIN Because it's your time Seite 20
1 What is Maven? 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> PLOIN Because it's your time Seite 21
1 What is Maven? Maven Packeging: mvn -DdownloadJavadocs -DdownloadSources idea:idea mvn -DdownloadJavadocs DdownloadSources eclipse:eclipse PLOIN Because it's your time Seite 22
2 Short Introduction PLOIN Because it's your time Seite 23
2 Short Introduction http://maven.apache.org/ PLOIN Because it's your time Seite 24
2 Short Introduction 1. Download Zip File. 2. Unzip. PLOIN Because it's your time Seite 25
2 Short Introduction 1. export PATH = $PATH:pathToMaven2/bin 2. export M2_HOME = pathtomaven2 3. export M2 = pathtomaven2/bin 4. export JAVA_HOME = pathtoyourjavahome PLOIN Because it's your time Seite 26
2 Short Introduction PLOIN Because it's your time Seite 27
2 Short Introduction 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/ PLOIN Because it's your time Seite 28
indt Eclipse-Plugin PLOIN Because it's your time Seite 29
2 Short Introduction PLOIN Because it's your time Seite 30
2 Short Introduction PLOIN Because it's your time
2 Short Introduction http://m2eclipse.sonatype.org/update/ PLOIN Because it's your time
2 Short Introduction PLOIN Because it's your time
Maven2 - Import Project into Eclipse PLOIN Because it's your time Seite 34
2 Short Introduction In Project-Root (where the pom.xml is located): mvn eclipse:eclipse!! This command generates Eclipse Metafiles PLOIN Because it's your time Seite 35
2 Short Introduction PLOIN Because it's your time
2 Short Introduction PLOIN Because it's your time
2 Short Introduction PLOIN Because it's your time
2 Short Introduction Short Intro: Maven-Quickinstall + Eclipse: http://robert-reiz.com/2008/02/21/maven2-quickinstall-2/ PLOIN Because it's your time
Live Demo PLOIN Because it's your time Seite 40
3 Maven2 Advanced PLOIN Because it's your time Seite 41
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> PLOIN Because it's your time Seite 42
3 Maven2 Advanced 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 PLOIN Because it's your time Seite 43
3 Maven2 Advanced 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> PLOIN Because it's your time Seite 44
3 Maven2 Advanced Your own M2 Repository Server PLOIN Because it's your time Seite 45
3 Maven2 Advanced PLOIN Because it's your time Seite 46
3 Maven2 Advanced Archetypes PLOIN Because it's your time Seite 47
3 Maven2 Advanced 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 PLOIN Because it's your time Seite 48
3 Maven2 Advanced http://robert-reiz.com/tutorials/archetypes/ PLOIN Because it's your time Seite 49
Archetypes Demo PLOIN Because it's your time Seite 50
PLOIN Because it's your time Seite 51
??? PLOIN Because it's your time Seite 52