Your SlideShare is downloading. ×
Apache Maven
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Apache Maven

219
views

Published on

This is a talk I gave recently to the department of Computer Science at University of Illinois at Chicago on Apache Maven. Hope it's useful. …

This is a talk I gave recently to the department of Computer Science at University of Illinois at Chicago on Apache Maven. Hope it's useful.

http://www.cs.uic.edu/Main/NewsItem?audience=public&ind=498

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
219
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Apache Maven : A maven in build automation Venkat Raghavan G M.S - Computer Science ADVIS Laboratory.Department of Computer Science University of Illinois at Chicago.
  • 2. Motivation.. • Large number of modules with proper description/status. • • Rectify implementation issues – Eg: Integrate with a build server or use JARs with other projects. • How about decreasing training time for developers? • Spend more time on programming than organizing it. • What about Ant, buildr… Gradle*? • The goal is to simplify tests, build, integrations and reporting.University of Illinois at Chicago. Venkat Raghavan G
  • 3. Maven - Introduction • Officially described as “Software project management & comprehension” tool. • • Widely recognized as a build automation tool, typically for Java projects. • Based on Project-Object-Model (POM) • It has a plugin execution framework . • Maintains a model of a project : • Dependency management • Remote repositories • Reuse of build logic • Tool portabilityUniversity of Illinois at Chicago. Venkat Raghavan G
  • 4. Today’s talk.. • Maven Introduction • • POM • Plugin execution framework • Build Lifecycle • Creating a maven project • Advanced Topics*University of Illinois at Chicago. Venkat Raghavan G
  • 5. Maven - History • Initiated in 2001 as an Apache Jakarta project. • • Moved to Turbine after that. • Active development by 2003 • Maven 2.0 in 2005 (POM) • Maven 3.0 in 2010 • Maven 3.0.4 in Jan 2012University of Illinois at Chicago. Venkat Raghavan G
  • 6. Installation • Download tar.gz and extract to ~/ • • Set ‘M2_HOME’ environment variable to ~/<maven> • Set ‘M2_HOME/bin’ to PATH : use bashrc or make a symbolic link in /usr/bin • Type ‘mvn’ to see the options.University of Illinois at Chicago. Venkat Raghavan G
  • 7. Project Object Model (POM) • Heart of Maven 2 • • XML – Containing Project info and configuration details • build path, dependencies, testing resources, team members, structure etc. • Super POM – Default POM. All POMs extend Super POM. <project> <modelVersion>3.0.0</modelVersion> <name>Maven Project</name> <repositories> <repository> <id>central</id> <name>In-house Repository </name> <layout>default</layout> <url>http://repos.uic.edu/maven2</url> <snapshots> </repository> </repositories> …..University of Illinois at Chicago. Venkat Raghavan G
  • 8. Ant “build.xml” <project name=“sample" default="dist" basedir="."> <description> • Compare Ant & POM </description> <property name="src" location="src/main/java"/> <property name="build" location="target/classes"/> <property name="dist" location="target"/> Maven “POM.xml” <target name="init"> <project> <mkdir dir="${build}"/> <modelVersion>1.0.0</modelVersion> </target> <groupId>edu.uic.lab1</groupId> <target name="compile" depends="init“ description="compile the source " > <artifactId>Project1</artifactId> <javac srcdir="${src}" destdir="${build}"/> <version>1.0</version> </target> </project> <target name="dist" depends="compile“ description="generate the distribution" > <mkdir dir="${dist}/lib"/> <jar jarfile="${dist}/build/sample.jar" basedir="${build}"/> </target> … …….University of Illinois at Chicago. Venkat Raghavan G
  • 9. Convention over configuration.. src/main/java Application/Library sources • src/main/resources Application/Library resources • Standardized structure src/main/filters Resource filter files • Can be overridden but src/main/assembly Assembly descriptors not recommended src/main/config Configuration files src/main/scripts Application/Library scripts src/main/webapp Web application sources src/test/java Test sources src/test/resources Test resources src/test/filters Test resource filter files src/site Site LICENSE.txt Projects license Notices and attributions required by libraries NOTICE.txt that the project depends on README.txt Projects readmeUniversity of Illinois at Chicago. Venkat Raghavan G
  • 10. More on POM.. <project> <modelVersion>1.0.0</modelVersion> <groupId>edu.uic.lab1</groupId> Default POM <artifactId>Project1</artifactId> <version>1.0</version> <properties> <project.build.sourceEncoding>UTF-8 Properties – encoding, Java </project.build.sourceEncoding> system, user-defined, etc. </properties> <repositories> <repository> <id>repo1</id> Location for maven to lookup <url>http://project1.uic.edu/maven2</url> when materializing the project. </repository> </repositories> ..University of Illinois at Chicago. Venkat Raghavan G
  • 11. More on POM.. <dependencies> <dependency> <groupId>log4j</groupId> Defining dependencies <artifactId>log4j</artifactId> <version>1.2.12</version> </dependency> </dependencies> <build> <sourceDirectory>src</sourceDirectory> <testSourceDirectory>test</testSourceDirectory> <resources> <resource> SuperPOM - Overriding <directory>resources</directory> </resource> </resources> </build>University of Illinois at Chicago. Venkat Raghavan G
  • 12. Dependency configuration • Artifact is identified by coordinates • <dependencies> <dependency> • groupid, artifactid, version <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.12</version> • No more version conflicts or binary data in VCS. <scope> test</scope> • Quick checkout, reuse artifacts </dependency> </dependencies> • Version : <major>.<minor>.<revision> • Dependency scopes: 1. compile – packaged into the build file => JAR, WAR 2. provided – not packaged but used for compile => Servlet 3. runtime – not for compile but for tests => taglibs 4. test – used only for test => JUnit 5. system – similar to ‘provided’ => 3rd party softwaresUniversity of Illinois at Chicago. Venkat Raghavan G
  • 13. Plugin execution framework <build> ••Maven, by itself, is a dummy XML framework <plugins> <plugin> • Plugins turn them into a giant tool. <artifactId>maven-enforcer-plugin </artifactId> • Collection of one or more ‘goals’ <version>1.1.1</version> <executions> • Does ‘executions’. <execution> <id>enforce-java</id> <goals> • Custom plugin can be written. <goal>enforce</goal> </goals> • Java, Groovy, Ruby etc. <configuration> <rules> <requireJavaVersion> <version>[1.6.0-0,1.6.0-32]</version> </requireJavaVersion> </rules> </configuration>…..University of Illinois at Chicago. Venkat Raghavan G
  • 14. Repository configuration ••Central repository : <repositories> <repository> • http://repo1.maven.org/maven2 <id>central</id> • Huge set of libraries are available <url>http://repo1.maven.org/maven2 </url> </repository> • Local repository : </repositories> • ~/${maven-folder}/repository • Contains artifacts • used by maven • used by projects • created by projectsUniversity of Illinois at Chicago. Venkat Raghavan G
  • 15. Creating a new repository ••Get a web space. • Create a new maven project. • Add ‘extension’ for a protocol in POM: Eg: – wagon-ftp • Add ‘distributionManagement’ repository – the new FTP address • To keep it secure, add credentials to ~/.m2/settings.xml • mvn deploy • Share your repository link to the world!University of Illinois at Chicago. Venkat Raghavan G
  • 16. Default life-cycle.. Plugins generate-sources archetype compile compiler test-compile test POM surefire package integration-test jar install deploy installUniversity of Illinois at Chicago. Venkat Raghavan G
  • 17. Few maven commands.. ••mvn dependency:analyze  Cleans up the dependencies again • mvn dependency:tree (or) mvn dependency:list  To learn about dependencies. • mvn install  Install the o/p to the repository • mvn clean  Cleans the target directory • mvn package  Creates war/jar • mvn compile  Compiles the project • mvn test  Tests as defined in POMUniversity of Illinois at Chicago. Venkat Raghavan G
  • 18. Creating a maven project.. • Understand “archetype” • mvn archetype:generate -DgroupId=edu.uic –DartifactId=project1 – DarchetypeGroupId=maven-archetype-quickstart • Creates maven project with default POM • Creates src/main/java and src/test/java foldersUniversity of Illinois at Chicago. Venkat Raghavan G
  • 19. Extra POM elements.. • <developers> <developer>…. • <contributors><contributor>… • <organization> • <licenses><license>… • <reporting> And so on…University of Illinois at Chicago. Venkat Raghavan G
  • 20. Some useful links.. ••POM Reference -- http://maven.apache.org/pom.html • Repository using FTP -- http://stuartsierra.com/2009/09/08/run-your-own-maven- repository • Advanced reading -- http://shop.oreilly.com/product/9780596517335.doUniversity of Illinois at Chicago. Venkat Raghavan G
  • 21. Advanced topics.. • Inheritance • “Management” prefix keyword. • ‘pluginManagement’ and ‘dependencyManagement’ • Does inheritance • Used in more complex projects • Be careful! Not to be confused with ‘plugins’/’dependencies’University of Illinois at Chicago. Venkat Raghavan G
  • 22. Advanced topics.. • Profiles • Customize build based on environments. • Eg: production, development • Allows build portability <profiles> <profile> <id>production</id> <build> …. </build> </profile> </profiles>University of Illinois at Chicago. Venkat Raghavan G
  • 23. Advanced topics.. • Creating website • Create a maven project • Add jetty plugin and run “mvn jetty:run” • Add site-descriptors to pom.xml • Document using APT, Xdoc or FML (Maven uses Doxia) • DeployUniversity of Illinois at Chicago. Venkat Raghavan G
  • 24. Advanced topics.. • Add security • Restrict users for deployment, build, distribution etc. • Create a private key : mvn –ecrypt-master-password myPassword • Add <settingssecurity> to ~/{maven2}/settings-security.xml • You can register in the server through “settings.xml”.University of Illinois at Chicago. Venkat Raghavan G
  • 25. Summary • Maven – more than a build automation tool • Convention over configuration • Central repository and dependency management • Execution of life-cycle phases through plugin • Software project management services viz. websites, reporting etc. • Integration with eclipse IDE through m2e pluginUniversity of Illinois at Chicago. Venkat Raghavan G
  • 26. • Thank You!!University of Illinois at Chicago. Venkat Raghavan G