jdc 2010 - maven, intelligent projects
TRANSCRIPT
Mert ÇALI!KAN
MAVENINTELLIGENT PROJECTS
Java Developer Conference 2010
About Me• Mert ÇALIŞKAN
• Software Plumber :) SCJP certified bla bla..
• Open Source Software advocate.Involved in numerous OSS projects like PrimeFaces, mesir ...
• Apache Software Foundation memberOpenLogic Expert Community member
http://www.jroller.com/merthttp://www.twitter.com/mertcaliskan
Java Developer Conference 2010
About You
Gradle
+
Java Developer Conference 2010
Agenda• Maven is ?
• Core Concepts- The POM- Build Life Cycle- Dependency Mechanism- Repositories- Plugins
• Archetypes
• IDE Support
• How to increase your MOJOtivity ?
Java Developer Conference 2010
MAVEN ?
Java Developer Conference 2010
Maven is...• A project management framework from ASF
• Uniform build system
• Making the build as easy as possible
• Comprehensive model for software projects
• Versions: 1.x 2.x ( 2.0.x, 2.2.x(jdk1.5) ) 3.x 2.x projects & plugins are still supported completely rewritten - new artifact resolution system / dependency resolving algorithm. Better IDE support
Java Developer Conference 2010
Highlights• Convention over Configuration
• Common Interfaces The time of build engineers is over Stop building the build and focus on development !
• Dependency Management Public repositories
• Plugin Architecture
• Documentation Generate documentation, reports ...
Java Developer Conference 2010
THE POM
Java Developer Conference 2010
The POM• It is what makes your project a maven project
• An XML file
• Not just for building the project project’s relationship, list of team members, license, SCM and etc.
• Not only for Java projects build FLEX code with appropriate plugins
build Microsoft binaries from C# code
Java Developer Conference 2010
The POMhttp://tinyurl.com/maven-xsddoc
Java Developer Conference 2010
The POM<project ...>
<parent /><groupId /> <artifactId /> <version /><packaging /><developers /> <contributors /><scm>... </scm>
<build><plugins>....</plugins>
</build>
<dependencies>....</dependencies><repositories>....</repositories><pluginRepositories>... </pluginRepositories><profiles>...</profiles><reporting>... </reporting>
</project>
Java Developer Conference 2010
Simplest POM<project> <modelVersion>4.0.0</modelVersion> <groupId>org.egjug.jdc2010</groupId> <artifactId>my-app</artifactId> <version>1.0.0</version></project>
$ mvn installcompile code
run testspackage as jar
deploy to local repo}
Java Developer Conference 2010
How is that possible with 6 lines of XML?
Where do I define the source folders, test folders and all other stuff ?
Java Developer Conference 2010
Super POM• Same analogy with java.lang.Object
• ${M2_HOME}/lib/ maven-2.2.1-uber.jar! /org/apache/maven/project/pom-4.0.0.xml
• Standard directory layout
• Locks versions of common plugins >= 2.0.9
• Repo def. for http://repo1.maven.org/maven2
• To see the merged POM: $!mvn help:effective-pom
Java Developer Conference 2010
BUILD LIFE CYCLE
Java Developer Conference 2010
Build Life Cycle• Process for building and distributing an artifact is clearly
defined
• 3 built-in Life Cycles default: handle project deployment clean: clean project files generated by a build site: generate project’s site doc.
• Life Cycle consists of phases in specific order
• Zero or more goals attached to each phase
Java Developer Conference 2010
defaultvalidate
compile
test
package
integration-test
verify
install
deploy
Java Developer Conference 2010
defaultvalidate
compile
test
package
integration-test
verify
install
deploy
$ mvn integration-testvalidate
compile
test
package
integration-test
mvn <phase>mvn <phase:goal>
mvn <phase> <phase:goal>mvn <phase:goal> <phase:goal>
Java Developer Conference 2010
DEPENDENCYMECHANISM
Java Developer Conference 2010
Dependency Mechanism• Gimme the Coordinates ! (GAV factor)
• Transitive Dependencies You can exclude what you don’t want
or omit them all with <optional>false</optional>
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> <scope>compile</scope></dependency>
Java Developer Conference 2010
$ mvn dependency:tree[INFO] net:eniyiyemek:war:1.0-SNAPSHOT[INFO] +- org.jboss.seam:jboss-seam:jar:2.2.0.GA:compile[INFO] | +- xstream:xstream:jar:1.1.3:compile[INFO] | +- xpp3:xpp3_min:jar:1.1.3.4.O:compile[INFO] | \- org.jboss.el:jboss-el:jar:1.0_02.CR4:compile
[INFO] +- org.jboss.seam:jboss-seam-ui:jar:2.2.0.GA:compile[INFO] | +- org.jboss.seam:jboss-seam:ejb:2.2.0.GA:compile[INFO] | +- org.jboss.seam:jboss-seam-jul:jar:2.2.0.GA:compile[INFO] | \- commons-beanutils:commons-beanutils:jar:1.7.0:compile[INFO] +- org.jboss.seam:jboss-seam-mail:jar:2.2.0.GA:compile[INFO] +- javax.mail:mail:jar:1.4.1:compile[INFO] | \- javax.activation:activation:jar:1.1:compile[INFO] +- quartz:quartz:jar:1.6.0:compile[INFO] +- commons-logging:commons-logging:jar:1.1.1:compile[INFO] +- javax.faces:jsf-api:jar:1.2_13:compile[INFO] +- javax.faces:jsf-impl:jar:1.2_13:compile[INFO] +- com.sun.facelets:jsf-facelets:jar:1.1.14:compile[INFO] +- jstl:jstl:jar:1.2:compile[INFO] +- org.primefaces:primefaces-stable:jar:1.0.0:compile[INFO] +- javax.transaction:jta:jar:1.1:compile[INFO] +- org.hibernate:hibernate-core:jar:3.5.0-Beta-2:compile[INFO] | +- antlr:antlr:jar:2.7.6:compile[INFO] | +- dom4j:dom4j:jar:1.6.1:compile[INFO] | \- org.slf4j:slf4j-api:jar:1.5.8:compile[INFO] +- org.hibernate:hibernate-annotations:jar:3.5.0-Beta-2:compile[INFO] | +- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Beta1:compile[INFO] | +- org.hibernate.java-persistence:jpa-api:jar:2.0-cr-1:compile[INFO] | \- hsqldb:hsqldb:jar:1.8.0.2:compile[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.5.0-Beta-2:compile[INFO] | \- cglib:cglib:jar:2.2:compile[INFO] | \- asm:asm:jar:3.1:compile[INFO] +- org.hibernate:hibernate-validator-legacy:jar:4.0.2.GA:compile
Java Developer Conference 2010
$ mvn dependency:analyze
[WARNING] Unused declared dependencies found:[WARNING] org.egjug.jdc2010:projectB:jar:1.0:compile[WARNING] org.egjug.jdc2010:projectC:jar:1.0:compile
[WARNING] Used undeclared dependencies found:[WARNING] opensymphony:xwork:jar:2.0.0:compile
Unused declared deps:
Used undeclared deps:
Java Developer Conference 2010
Scopes for Dependencies
C T R
compile
testruntime
provided
systemimport
Compile
Classpaths
Test Runtime
Java Developer Conference 2010
not needed for compilation but needed @ runtime
compile default scope, compile scoped dependencies will be in classpath
provided similar to the compile, artifact should be provided by JDK / container @ runtime
runtime
CTR
CT
TR
testT only needed for test compilation & execution
system
with maven 2.0.9...dependency to be replaced with the dependencies in that POM's <dependencyManagement> section.
CT
import---
same as provided, but artifact should be provided explicitly with <systemPath />
Java Developer Conference 2010
Versioning and Ranges
(, ) - Exclusive[, ] - Inclusive <version>[3.8,4.0)</version>
<major>.<minor>.<incremental> - <qualifier>
1.2.3 / 1.2.3-alpha-01
1.2.3-alpha-2 > 1.2.3-alpha-10
Be careful with string comparison, ordering at the qualifiers...
Java Developer Conference 2010
SNAPSHOT qualifier• Active development version
• Resolve from remote Repo:
Install to local Repo:
myjar-1.0.0-SNAPSHOT.jar applies pattern date . time - build#resolves to myjar-1.0.0-20100219.141012-1.jar
1.0.0-SNAPSHOT will be 1.0.0-SNAPSHOT
Java Developer Conference 2010
How MavenResolve
Versions?
Compile
Java Developer Conference 2010
A : A : 1.0
B : B : 1.0C : C : 1.0
B : B : 2.0commons-loggingcommons-logging
1.0.1
commons-loggingcommons-logging
1.1.1
commons-loggingcommons-logging
1.1.1
Dependency Graph
D : D : 1.0
commons-loggingcommons-logging
1.0.4
Java Developer Conference 2010
Which B will Maven choose?
A : A : 1.0
B : B : 1.0C : C : 1.0
B : B : 2.0commons-loggingcommons-logging
1.0.1
commons-loggingcommons-logging
1.1.1
commons-loggingcommons-logging
1.1.1
commons-loggingcommons-logging
1.0.4
B : 2.0 ? Highest One?
D : D : 1.0
Java Developer Conference 2010
Closest OneA : A : 1.0
B : B : 1.0C : C : 1.0
B : B : 2.0commons-loggingcommons-logging
1.0.1
commons-loggingcommons-logging
1.1.1
commons-loggingcommons-logging
1.1.1
commons-loggingcommons-logging
1.0.4
D : D : 1.0
Java Developer Conference 2010
Which commons-logging?
?
A : A : 1.0
B : B : 1.0C : C : 1.0
B : B : 2.0commons-loggingcommons-logging
1.0.1
commons-loggingcommons-logging
1.1.1
commons-loggingcommons-logging
1.1.1
commons-loggingcommons-logging
1.0.4 ??
?
D : D : 1.0
Java Developer Conference 2010
The sequential first at the same distance
A : A : 1.0
B : B : 1.0C : C : 1.0
B : B : 2.0commons-loggingcommons-logging
1.0.1
commons-loggingcommons-logging
1.1.1
commons-loggingcommons-logging
1.1.1
commons-loggingcommons-logging
1.0.4
D : D : 1.0
Java Developer Conference 2010
Dependency Graph
A : A : 1.0
B : B : 1.0C : C : 1.0
commons-loggingcommons-logging
1.0.4
D : D : 1.0
Java Developer Conference 2010
Dependency Graph
A : A : 1.0
B : B : 1.0C : C : 1.0
commons-loggingcommons-logging
1.0.4
D : D : 1.0
IS PROJECT A GONNA WORK ?
Java Developer Conference 2010
Dependency Graph
A : A : 1.0
B : B : 1.0C : C : 1.0
commons-loggingcommons-logging
1.0.4
D : D : 1.0
Java Developer Conference 2010
A : A : 1.0
B : B : 1.0C : C : 1.0
B : B : 2.0commons-loggingcommons-logging
1.0.1
commons-loggingcommons-logging
1.1.1
commons-loggingcommons-logging
1.1.1
Dependency Graph
D : D : 1.0
commons-loggingcommons-logging
1.0.4
USE <dependencyManagement />
Java Developer Conference 2010
Managing DependenciesManaging Projects
Inheritance
Aggregation
POM Bundles
Java Developer Conference 2010
Inheritance
<project> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.egjug.jdc2010</groupId> <artifactId>parentapp</artifactId> <version>1.0.0</version> </parent> <groupId>org.egjug.jdc2010</groupId> <artifactId>sampleapp</artifactId> <version>1.0.0</version></project>
parentapp
sampleapp
<<extends>>
Java Developer Conference 2010
Inheritance <dependencyManagement /><project> <modelVersion>4.0.0</modelVersion> <groupId>org.egjug.jdc2010</groupId> <artifactId>parentapp</artifactId> <packaging>pom</packaging> <version>1.0</version> <dependencyManagement> <dependencies>" <dependency>" <groupId>commongs-logging</groupId> " <artifactId>commongs-logging</artifactId>" <version>1.1.1</version> </dependency> </dependencies> </dependencyManagement></project>
parentapp
sampleapp
<<extends>>
Java Developer Conference 2010
Inheritance <dependencyManagement /><project>
<modelVersion>4.0.0</modelVersion>" <parent>" " <groupId>org.egjug.jdc2010</groupId>" " <artifactId>parentapp</artifactId>" " <version>1.0</version>
" </parent> <artifactId>sampleapp</artifactId> <dependencies>" <dependency>
" <groupId>commongs-logging</groupId> ! <artifactId>commongs-logging</artifactId> </dependency> </dependencies></project>
parentapp
sampleapp
<<extends>>
will get version 1.1.1...
Java Developer Conference 2010
Aggregation
ProjectA ProjectB<<depends>> <<depends>>
ProjectC
root $!cd ProjectCprojectC $ mvn compileprojectC $ cd ..root $!cd ProjectBprojectB $ mvn compileprojectB $ cd ..root $!cd ProjectAprojectA $ mvn compile
} 8 lines !!!
Java Developer Conference 2010
modulesapp
ProjectA ProjectB
ProjectC
<<module>><<module>>
<<module>>
root $!cd modulesappmodulesapp $ mvn compile
modulesapp:
<project> <modelVersion>4.0.0</modelVersion> <groupId>org.egjug.jdc2010</groupId> <artifactId>modulesapp</artifactId> <packaging>pom</packaging> <version>1.0</version> <name>modulesapp</name> <modules> <module>projectA</module> <module>projectB</module> <module>projectC</module> </modules></project>
Aggregation
Java Developer Conference 2010
POM Bundles <project> <modelVersion>4.0.0</modelVersion> <groupId>org.egjug.jdc2010</groupId> <artifactId>commonspom</artifactId> <packaging>pom</packaging> <version>1.0</version> <dependencies> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>3.2.1</version> </dependency> <dependency> <groupId>commons-digester</groupId> <artifactId>commons-digester</artifactId> <version>2.0</version> </dependency> ..... </dependencies> </project>
Java Developer Conference 2010
POM Bundles
<dependency> <groupId>org.egjug.jdc2010</groupId> <artifactId>commonspom</artifactId> <version>1.0</version> <type>pom</type> </dependency>
Java Developer Conference 2010
REPOSITORIES
Java Developer Conference 2010
M2_REPO/javax/activation/activation/1.1/activation-1.1.jarM2_REPO/antlr/antlr/2.7.6/antlr-2.7.6.jarM2_REPO/asm/asm/3.1/asm-3.1.jarM2_REPO/cglib/cglib/2.2/cglib-2.2.jarM2_REPO/commons-beanutils/commons-beanutils/1.7.0/commons-beanutils-1.7.0.jar M2_REPO/commons-codec/commons-codec/1.3/commons-codec-1.3.jarM2_REPO/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jarM2_REPO/commons-lang/commons-lang/2.4/commons-lang-2.4.jarM2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar M2_REPO/dom4j/dom4j/1.6.1/dom4j-1.6.1.jarM2_REPO/javax/el/el-api/1.0/el-api-1.0.jarM2_REPO/org/hibernate/hibernate-annotations/3.5.0-Beta-2/hibernate-annotations-3.5.0-Beta-2.jarM2_REPO/org/hibernate/hibernate-commons-annotations/3.2.0.Beta1/hibernate-commons-annotations-3.2.0.Beta1.jarM2_REPO/org/hibernate/hibernate-core/3.5.0-Beta-2/hibernate-core-3.5.0-Beta-2.jarM2_REPO/org/hibernate/hibernate-entitymanager/3.5.0-Beta-2/hibernate-entitymanager-3.5.0-Beta-2.jarM2_REPO/org/hibernate/hibernate-validator-legacy/4.0.2.GA/hibernate-validator-legacy-4.0.2.GA.jarM2_REPO/hsqldb/hsqldb/1.8.0.2/hsqldb-1.8.0.2.jarM2_REPO/javassist/javassist/3.10.0.GA/javassist-3.10.0.GA.jarM2_REPO/org/jboss/el/jboss-el/1.0_02.CR4/jboss-el-1.0_02.CR4.jarM2_REPO/org/jboss/seam/jboss-seam/2.2.0.GA/jboss-seam-2.2.0.GA.jarM2_REPO/org/jboss/seam/jboss-seam-jul/2.2.0.GA/jboss-seam-jul-2.2.0.GA.jarM2_REPO/org/jboss/seam/jboss-seam-mail/2.2.0.GA/jboss-seam-mail-2.2.0.GA.jarM2_REPO/org/jboss/seam/jboss-seam-ui/2.2.0.GA/jboss-seam-ui-2.2.0.GA.jarM2_REPO/org/hibernate/java-persistence/jpa-api/2.0-cr-1/jpa-api-2.0-cr-1.jarM2_REPO/javax/faces/jsf-api/1.2_13/jsf-api-1.2_13.jarM2_REPO/com/sun/facelets/jsf-facelets/1.1.14/jsf-facelets-1.1.14.jarM2_REPO/javax/faces/jsf-impl/1.2_13/jsf-impl-1.2_13.jarM2_REPO/jstl/jstl/1.2/jstl-1.2.jarM2_REPO/javax/transaction/jta/1.1/jta-1.1.jarM2_REPO/junit/junit/3.8.1/junit-3.8.1.jarM2_REPO/javax/mail/mail/1.4.1/mail-1.4.1.jarM2_REPO/postgresql/postgresql/8.4-701.jdbc3/postgresql-8.4-701.jdbc3.jarM2_REPO/org/primefaces/primefaces-stable/1.0.0/primefaces-stable-1.0.0.jarM2_REPO/quartz/quartz/1.6.0/quartz-1.6.0.jarM2_REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5.jarM2_REPO/org/slf4j/slf4j-api/1.5.8/slf4j-api-1.5.8.jarM2_REPO/org/slf4j/slf4j-nop/1.5.6/slf4j-nop-1.5.6.jarM2_REPO/org/testng/testng/5.9/testng-5.9.jarM2_REPO/xpp3/xpp3_min/1.1.3.4.O/xpp3_min-1.1.3.4.O.jarM2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar
Stack
JSFPrimeFacesSeamJPA
Hibernate
Java Developer Conference 2010
M2_REPO/javax/activation/activation/1.1/activation-1.1.jarM2_REPO/antlr/antlr/2.7.6/antlr-2.7.6.jarM2_REPO/asm/asm/3.1/asm-3.1.jarM2_REPO/cglib/cglib/2.2/cglib-2.2.jarM2_REPO/commons-beanutils/commons-beanutils/1.7.0/commons-beanutils-1.7.0.jar M2_REPO/commons-codec/commons-codec/1.3/commons-codec-1.3.jarM2_REPO/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jarM2_REPO/commons-lang/commons-lang/2.4/commons-lang-2.4.jarM2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar M2_REPO/dom4j/dom4j/1.6.1/dom4j-1.6.1.jarM2_REPO/javax/el/el-api/1.0/el-api-1.0.jarM2_REPO/org/hibernate/hibernate-annotations/3.5.0-Beta-2/hibernate-annotations-3.5.0-Beta-2.jarM2_REPO/org/hibernate/hibernate-commons-annotations/3.2.0.Beta1/hibernate-commons-annotations-3.2.0.Beta1.jarM2_REPO/org/hibernate/hibernate-core/3.5.0-Beta-2/hibernate-core-3.5.0-Beta-2.jarM2_REPO/org/hibernate/hibernate-entitymanager/3.5.0-Beta-2/hibernate-entitymanager-3.5.0-Beta-2.jarM2_REPO/org/hibernate/hibernate-validator-legacy/4.0.2.GA/hibernate-validator-legacy-4.0.2.GA.jarM2_REPO/hsqldb/hsqldb/1.8.0.2/hsqldb-1.8.0.2.jarM2_REPO/javassist/javassist/3.10.0.GA/javassist-3.10.0.GA.jarM2_REPO/org/jboss/el/jboss-el/1.0_02.CR4/jboss-el-1.0_02.CR4.jarM2_REPO/org/jboss/seam/jboss-seam/2.2.0.GA/jboss-seam-2.2.0.GA.jarM2_REPO/org/jboss/seam/jboss-seam-jul/2.2.0.GA/jboss-seam-jul-2.2.0.GA.jarM2_REPO/org/jboss/seam/jboss-seam-mail/2.2.0.GA/jboss-seam-mail-2.2.0.GA.jarM2_REPO/org/jboss/seam/jboss-seam-ui/2.2.0.GA/jboss-seam-ui-2.2.0.GA.jarM2_REPO/org/hibernate/java-persistence/jpa-api/2.0-cr-1/jpa-api-2.0-cr-1.jarM2_REPO/javax/faces/jsf-api/1.2_13/jsf-api-1.2_13.jarM2_REPO/com/sun/facelets/jsf-facelets/1.1.14/jsf-facelets-1.1.14.jarM2_REPO/javax/faces/jsf-impl/1.2_13/jsf-impl-1.2_13.jarM2_REPO/jstl/jstl/1.2/jstl-1.2.jarM2_REPO/javax/transaction/jta/1.1/jta-1.1.jarM2_REPO/junit/junit/3.8.1/junit-3.8.1.jarM2_REPO/javax/mail/mail/1.4.1/mail-1.4.1.jarM2_REPO/postgresql/postgresql/8.4-701.jdbc3/postgresql-8.4-701.jdbc3.jarM2_REPO/org/primefaces/primefaces-stable/1.0.0/primefaces-stable-1.0.0.jarM2_REPO/quartz/quartz/1.6.0/quartz-1.6.0.jarM2_REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5.jarM2_REPO/org/slf4j/slf4j-api/1.5.8/slf4j-api-1.5.8.jarM2_REPO/org/slf4j/slf4j-nop/1.5.6/slf4j-nop-1.5.6.jarM2_REPO/org/testng/testng/5.9/testng-5.9.jarM2_REPO/xpp3/xpp3_min/1.1.3.4.O/xpp3_min-1.1.3.4.O.jarM2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar
40
Java Developer Conference 2010
Repositories• Repositories are for managing build artifacts and
dependencies
• local or remote repositories
• Can store jar, war, ear, ejb, rar ....
• Maven looks to at least 2 repository if none specified - local one - http://repo1.maven.org/maven2 /uber-pom/
• Release & Snapshot repositories
Java Developer Conference 2010
Repositories <repository> <id>jboss-repo</id> <name>The Release JBoss maven repo</name> <url>http://repository.jboss.org/maven2</url> <releases> <enabled>true</enabled> </releases> </repository>
<repository> <id>jboss-snapshot-repo</id> <name>The Snapshot JBoss maven repo</name> <url>http://snapshots.jboss.org/maven2</url> <snapshots> <enabled>true</enabled> </snapshots> </repository>
Java Developer Conference 2010
Create Your own Repo • Go Corporate !
• Deploy and share your projects artifacts across your team
• Cache dependencies Decrease the internet dependency
• Proxy Repo configurations
• OSS Alternatives: Nexus Archiva Artifactory
Java Developer Conference 2010
Sonatype NexusNexus Repository Manager
• Just a Web App, nice UI
• Upload artifacts via HTTP, RESTful style
• Indexing and searching for repository artifacts
• LDAP Integration with v1.5
Nexus Professional ($$$)- Staging repository- Eclipse plugin repository and more...
Java Developer Conference 2010
Searching for Artifacts
• http://repository.apache.org
• http://www.jarvana.com
• http://www.artifact-repository.org
• http://mvnrepository.com
• http://www.mvnbrowser.com
• http://mavensearch.net
Java Developer Conference 2010
PLUGINS
Java Developer Conference 2010
Plugins• Plugin-oriented Architecture
plugin for even compiling the code..
• A maven artifact w/ descriptor (plugin.xml) and one or more MOJOs
• Plexus as its IoC Why not Spring?
• Where to look for plugins: org.apache.maven.plugins org.codehaus.mojo
Java Developer Conference 2010
Plugins available @ maven
Maven Repo
cleancompilerdeployfailsafeinstallresourcessitesurefireverifier
Core EclipseIDEA
Integration
AntAntlr
AntrunArchetypeAssembly
HelpRelease
Tools
jar war ear ejb rar pom shade
Packaging
Cargojaxme
jettytomcat
Others
ChangelogChanges
CheckstyleClover
JavadocsPMD
Surefire-reports
Reporting
Java Developer Conference 2010
ARCHETYPES
Java Developer Conference 2010
Archetypes• Templates for maven projects
• Descriptor XML files + velocity templates
• To create a maven project:
mvn archetype:generate \ -DgroupId=org.egjug.jdc2010 \ -DartifactId=archetype-quickstart \ -Dversion=1.0-SNAPSHOT \ -DarchetypeGroupId=org.apache.maven.archetypes \ -DarchetypeArtifactId=maven-archetype-quickstart \ -DarchetypeVersion=1.0
Java Developer Conference 2010
Archetype Catalogs• Descriptor file to share Archetypes globally.
<?xml version="1.0" encoding="UTF-8"?><archetype-catalog> <archetypes> .... <archetype> <groupId>org.jboss.weld.archetypes</groupId> <artifactId>weld-jsf-servlet-minimal</artifactId> <version>1.0.0-BETA1</version> <description>....</description> </archetype>" ..... </archetypes></archetype-catalog>
• $!mvn archetype:generate -DarchetypeCatalog=http://anonsvn.jboss.org/repos/weld/archetypes/tags/1.0.0-BETA1
Java Developer Conference 2010
Archetypes from Existing Project
$ mvn archetype:create-from-project
• generated archetype under : target / generated-sources / archetype
• Use an existing project as a seed for archetype
Java Developer Conference 2010
IDE Support
Java Developer Conference 2010
Maven with IDEs• Eclipse 3.5 Galileo
Eclipse IAM (formerly Q4E) m2eclipse maven-eclipse-plugin @ central-repo
• NetBeans 6.8 out of the box - embedded maven
• Intellij IDEA 9 out of the box - embedded maven maven-idea-plugin @ central-repo
Java Developer Conference 2010
m2eclipse
• Eclipse plug-in from Sonatype
• Checkout maven project from Source Control
• Create new Project from Archetype
• Nice POM Editor
• Embedded Maven Console
• You might need subclipse & AJDT plugins.
• A quick Demo...
Java Developer Conference 2010
INCREASE YOUR
MOJOTIVITY
Java Developer Conference 2010
Maven Help Pluginmvn help:describe -Dplugin=<anygoal>
• Lists & describes the goals of the plugin
mvn help:system
• Lists system properties and env. variables
<profile> <id>production</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <debug>false</debug> <optimize>true</optimize> </configuration> </plugin> </plugins> </build></profile>
Java Developer Conference 2010
Use Profiles•Create profiles for : development, staging and production
<profiles> <profile> <activation> <jdk>[1.3,1.6)</jdk> </activation> ... </profile>• invoke like
$ mvn <phase> -Pproduction
Java Developer Conference 2010
Property Referencesenv.* environment variables exposed by OS or Shell ${env.JAVA_HOME}
project.* POM elements ${project.groupId} ${project.parent.groupId}
settings.* Maven settings.xml properties ${settings.localRepository}
${foo} <properties> <foo>bar</foo> </properties>
Java Developer Conference 2010
Debugging Maven
• Output full error stacktrace mvn <anygoal> -e
• Output for debugging mvn <anygoal> -X
Always use when submitting questions or bug reports.
Java Developer Conference 2010
• If you are starting from scratch, start with MAVEN..!
• A Repository Manager is a MUST Have a Corporate Repo
• Have a company specific POM, try to keep your POM simple portable avoid any hardcoding..
• Use profiles...
• Use <dependencyManagement /> coerce Maven to use a particular version enforce consistency within projects
GOOD PRACTICES
Java Developer Conference 2010
• Make it so that you can, Release early, Release Often - Quick, easy and reproducible releases - CI tool integration
• Each project should output its own artifact (SoC)
• Use IDE integrations from stone age to iron age...
•Do not ignore or skip your tests! -Dmaven.test.skip=true -Dmaven.test.failure.ignore=true
GOOD PRACTICES
Java Developer Conference 2010
Online Resources
http://www.sonatype.com/book Maven: The Complete Reference Maven By Example m2eclipse Book Nexus Book http://www.maestrodev.com/better-build-maven Better Builds with Maven
Java Developer Conference 2010
Questions
Thank you
Sponsored by: