Using Maven 2
-
Upload
andyhot -
Category
Technology
-
view
8.138 -
download
0
description
Transcript of Using Maven 2
History
• Alexandria• Forrest• Gump• Maven• Turbine• Tomcat• Ant• James Duncan Davidson, Sam Ruby, Jason van
Zyl, Bob McWhirter
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
POM
• Project coordinates – groupId– artifactId– version– packaging (jar, war, ear, maven-plugin, …)
• Project info (developers, website, scm url)• Dependencies• Plugins
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
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
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
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
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/)
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
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!
Repository Manager
• Proxies between your organization and the public Maven repositories
• Deployment destination for your own generated artifacts
• Sonatype Nexus• Maven Archiva• Artifactory
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
Demo - Q&A
Companies
• sonatype.com– Jason van Zyl, Mark de Visser, Brian Fox, John
Casey– Nexus, m2eclipse
• Exist <- DevZuz <- Mergere– Brett Porter, Carlos Sanchez– q4e