Maven overview


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • "convention over configuration" guarantees success!
  • First thing that maven downloads is itself! plugins, etc. ("Maven downloads the internet")
  • Adding a Maven repo for the team to proxy central share internal artifacts between team members share releases with outsiders (until we're on central...)
  • Maven overview

    1. 1. Maven overviewSamuel Langlois – November 2012
    2. 2. Maven history• Started by Jason Van Zyl in 2001! o Standardising the build of Apache Turbine• Version history o 1.0 in July 2004, after loads of betas o 2.0 in October 2005, completely redesigned o 3.0 in October 2010, fully compatible o 3.0.4 is the latest• Today controlled by Sonatype o Future: "Tesla"?
    3. 3. Maven is *not* a better Ant build.xml pom.xml<project> <project> <target name="compile"> <groupId>org.alfresco</> <javac ...> <artifactId>alfresco-core</> <version>4.1.0</> </target> <name>Alfresco Core</> <dependencies> <target name="test"> <dependency> <junit ..> <groupId>commons-logging</> </target> <artifactId>commons-logging</> <version>1.1</> </dependency> <target name="package"> </dependencies> <jar ..> </project> </target></project>
    4. 4. Maven is *not* a better Ant build.xml pom.xml<project> <project> <target name="compile"> <groupId>org.alfresco</> <javac ...> <artifactId>alfresco-core</> <version>4.1.0</> </target> <name>Alfresco Core</> <dependencies> <target name="test"> <dependency> <junit ..> <groupId>commons-logging</> </target> <artifactId>commons-logging</> <version>1.1</> COD </dependency> <target E name="package"> </dependencies> DATA <jar ..> </project> </target></project>
    5. 5. Maven plugins• Written in Java (MOJO), or ...• Entry-points are called goals• Examples: o Core  maven-compiler-plugin  maven-resources-plugin - including filtering  maven-surefire-plugin - executes tests o Reporting  maven-javadoc-plugin  maven-findbugs-plugin o Code Generation  antlr3-maven-plugin o maven-alfresco-plugin !! o .......
    6. 6. Configuring a plug-in<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration><source>1.6</source><source>1.6</source><debug>false</debug> </configuration></plugin>
    7. 7. Maven phases Phase Default binding for jar packaging initialize generate-sources process-resources resources:resources compile compiler:compile generate-test-sources process-test-resources resources:testResources test-compile compiler:testCompile test surefire:test package jar:jar pre-integration-test integration-test post-integration-test install install:install deploy deploy:deploy
    8. 8. Plugging a plug-in<plugin> <artifactId>maven-jetty-plugin</artifactId> <executions> <execution> <id>start-jetty</id> <phase>pre-integration-test</phase> <goals> <goal>run</goal> </goals> </execution> <execution> <id>stop-jetty</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> </executions> <configuration><port>9876</port> </configuration></plugin>
    9. 9. Maven conventions• tree layout o pom.xml o src  main • java • resources  test • java • resources o target• tests are executed as part of the buildFollow the Maven way!
    10. 10. Maven dependencyA dependency (internal or external) is made of:• mandatory : GAV o groupId (org.alfresco) o artifactId (alfresco-datamodel) o version  release: 4.1.0  snapshot: 4.1-SNAPSHOT• optionally: o scope (compile, test, provided, ...) o classifier (jdk6, sources, javadocs, ...)Dependencies are transitive!• mvn dependency:tree dependency:list
    11. 11. Maven dependency management Maven Central local Maven repo mvn install mvn ~/.m2/repository
    12. 12. Maven dependency management Maven Central Team Repo mvn deploy local Maven repo mvn install mvn ~/.m2/repository
    13. 13. Invoking Maven• call a phase o mvn clean install o mvn test• call a goal o mvn surefire:test o mvn javadoc:javadoc• Useful switches o -o : offline o -U : force check for snapshot updates o -X : verbose, to check plugin configuration• Adding command-line params for plugins o -DskipTests o -Dtest=MyClassTest
    14. 14. Multimodule builds• call sub-projects in parent folder <packaging>pom</packaging> <modules> <module>core</module> <module>web-client</module> </modules>• pom inheritance in sub-projects <parent> <groupId>... <artifactId>... <version>... </parent>• computing the actual pom • mvn help:effective-pom
    15. 15. Maven profiles• conditional parts in the pom.xml o plug/unplug a submodule o run a different set of tests o test various platforms o ...• Triggering a profile o command line: -P profile1,!profile3 o presence/absence of a property o automatically: JDK, OS, platform, existence of a file, ...
    16. 16. IDE integration• "Old school": Maven generating IDE project o mvn eclipse:eclipse [-DdownloadSources=true] o mvn idea:idea o mvn netbeans:netbeans• Recommended: IDE directly reading pom.xml o m2e plugin, included in "Eclipse IDE for Java Devs"
    17. 17. Reporting - Maven site
    18. 18. Reporting - Sonar
    19. 19. Want some more?• Maven "official" doc from Sonatype o Maven by Example o Reference• pom.xml reference• Maven Plugins reference o Apache o Codehaus