using maven 2

15
Using Maven 2 Andreas Andreou [email protected] amplafi.com, co-founder apache tapestry, committer – PMC

Upload: andyhot

Post on 30-Aug-2014

8.138 views

Category:

Technology


0 download

DESCRIPTION

Quick introduction to maven2

TRANSCRIPT

Page 1: Using Maven 2

Using Maven 2

Andreas [email protected]

amplafi.com, co-founderapache tapestry, committer – PMC

Page 2: Using Maven 2

History

• Alexandria• Forrest• Gump• Maven• Turbine• Tomcat• Ant• James Duncan Davidson, Sam Ruby, Jason van

Zyl, Bob McWhirter

Page 3: Using Maven 2

What is Maven?

• Project management tool = more than a build tool

• POM (project object model)• Dependency management system• Convention over configuration• Project lifecycle• Execution logic for each phase in lifecycle

Page 4: Using Maven 2

POM

• Project coordinates – groupId– artifactId– version– packaging (jar, war, ear, maven-plugin, …)

• Project info (developers, website, scm url)• Dependencies• Plugins

Page 5: Using Maven 2

Installing Maven

• Download / extract zip• Set M2_HOME env-var • Add M2_HOME/bin to path

• Folders created when maven is used:– USER_HOME/.m2/repository/– USER_HOME/.m2/settings.xml

Page 6: Using Maven 2

Simplest pom.xml

<project><modelVersion>4.0.0</modelVersion><groupId>gr.jhug</groupId><artifactId>javabb</artifactId><version>1.0-SNAPSHOT</version><packaging>jar</packaging><name>PHPBB-NUKE-killer</name>

</project> src/main/src/main/java/src/main/resources/src/test/src/test/javasrc/test/resources

Page 7: Using Maven 2

Maven Lifecycle• validate• generate-sources• process-resources• compile• test-compile• test• package• install• verify• deploy

• Maven execution needs phase and runs all previous:– mvn compile

• … or standalone plugin goal:– mvn jetty:run– mvn scm:update

Page 8: Using Maven 2

Some more plugins• maven-clean-plugin• maven-compiler-plugin• maven-jar-plugin• maven-war-plugin• maven-dependency-plugin• maven-release-plugin• maven-source-plugin• maven-surefire-plugin• maven-ant-plugin• maven-archetype-plugin• maven-checkstyle-plugin• maven-pmd-plugin

Page 9: Using Maven 2

Dependencies• Uses groupId, artifactId, version• Supports transitive dependencies• Needs correct usage of ‘scope’– compile– test– provided– runtime– system

• Retrieved from public locations (ibiblio, e.t.c.)• Stored on local repo (~/.m2/repository/)

Page 10: Using Maven 2

Versions in Dependencies

• <major>.<minor>.<revision>([ -<qualifier> ] | [ -<build> ])

• 4.1.6• 4.1.6-SNAPSHOT• [4.1.6,5)• If same dependency included more than once

(how???), biggest wins

Page 11: Using Maven 2

Maven & IDEs

• Supported in all major IDEs• From pom.xml generate IDE specific files– mvn eclipse:eclipse– mvn idea:idea

• Directly read pom.xml and setup project– 2 plugins for eclipse: m2eclipse, q4e– Bundled plugin in IDEA– Plugin from update center for Netbeans

• … but maven is (still) more powerful!

Page 12: Using Maven 2

Repository Manager

• Proxies between your organization and the public Maven repositories

• Deployment destination for your own generated artifacts

• Sonatype Nexus• Maven Archiva• Artifactory

Page 13: Using Maven 2

Links• http://ant.apache.org/faq.html• http://maven.apache.org/background/history-of-

maven.html• http://jakarta.apache.org/alexandria/legacy/• http://gump.apache.org/why.html• http://www.sonatype.com/books/maven-book/

index.html• http://maven.apache.org/repository-

management.html• http://delicious.com/andyhot/maven

Page 14: Using Maven 2

Demo - Q&A

Page 15: Using Maven 2

Companies

• sonatype.com– Jason van Zyl, Mark de Visser, Brian Fox, John

Casey– Nexus, m2eclipse

• Exist <- DevZuz <- Mergere– Brett Porter, Carlos Sanchez– q4e