Presentation is loading. Please wait.

Presentation is loading. Please wait.

Managing your builds with Maven 2 Craig Walls LoneStar Software Symposium 2007

Similar presentations


Presentation on theme: "Managing your builds with Maven 2 Craig Walls LoneStar Software Symposium 2007"— Presentation transcript:

1 Managing your builds with Maven 2 Craig Walls LoneStar Software Symposium 2007 craig@habuma.com http://www.springinaction.com

2 About you… Java?.NET? Ruby/Rails? Erlang? –Java 6? Java 5? Java 1.4? Java 1.3? 1.2 or older? Who’s using Maven? How long? –Maven 1? Maven 2?

3 About me Agile developer with Semantra –Natural language data access Developing software professionally for over 13 years –Telecom, Finance, Retail, Education –Java for most of that –Also some C/C++, C#/.NET, Ruby Spring fanatic

4 Agenda Intro to Maven 2 Exploring the POM Dependencies Profiles Project relationships Archetypes Project web site generation Q & A

5 Maven resources “Get the most out of Maven 2 site generation” http://www.javaworld.com/javaworld/jw-02-2006/jw-0227-maven.html “The Maven 2 POM Demystified” http://www.javaworld.com/javaworld/jw-05-2006/jw-0529-maven.html “Better Builds with Maven: How-to Guide for Maven 2” http://www.devzuz.com/web/guest/products/resources#BBWM “Maven: The Definitive Guide” http://www.sonatype.com/book/

6 Intro to Maven 2

7 What is Maven? Build tool? Project management tool? Dependency management tool? Documentation tool?

8 Maven vs. Ant Ant Boilerplate build code Explicit target definitions Explicit project structure Dependencies must be provided by programmer Maven Declarative Common tasks are built-in Project structure imposed by Maven Dependencies declared (Maven gets them for you)

9 MYTH: Maven is hard Maven is different than Ant…but not necessarily harder. Q: Is Chinese harder than English? –1.2 billion people don’t think so. In most cases, Maven is significantly simpler than Ant. You must be willing to think differently about how you build your projects.

10 MYTH: Maven is slow Fact: Maven is slow when it needs to download a lot of dependencies. Dependencies are cached locally, so future builds will be faster. Typical builds are at least as fast (and maybe faster) than Ant.

11 Maven principles Convention over configuration Declarative execution Reuse of build logic Coherent organization of dependencies

12 Consistent directory structure How Maven knows where everything is. How the developer knows where everything is.

13 Maven lifecycle 1.validate 2.generate-sources 3.process-sources 4.generate-resources 5.process-resources 6.compile 7.process-classes 8.generate-test-sources 9.process-test-sources 10.generate-test-resources 11.process-test-resources 12. test-compile 13. test 14. package 15. pre-integration-test 16. integration-test 17. post-integration-test 18. verify 19. install 20. deploy

14 Running Maven % maven [options] [goal(s)] [phase(s)] Examples: % maven -o clean package % maven tomcat:deploy % maven site

15 Exploring the POM

16 Key POM sections Basic project info Build section Dependencies section Reporting section Profiles section

17 Basic project info 4.0.0 Poker Service com.habuma Poker 1.0 war Sample Spring-WS service

18 Build section Poker …

19 Build section: Java 1.5 maven-compiler-plugin 1.5

20 Build section: Cargo org.codehaus.cargo cargo-maven2-plugin 0.2 tomcat5x remote runtime localhost 8080 admin password

21 Build Section: Jetty Adding the Jetty plugin: org.mortbay.jetty maven-jetty-plugin Start Jetty from Maven (and run your app): % mvn jetty:run

22 Misc properties 2.0 org.springframework spring ${spring.version} compile

23 Dependencies

24 Dependency resolution Dependencies are automatically resolved… –First looks in local repository: ~/.m2/repository –Then looks in one or more remote repositories Default: http://repo1.maven.org Transitive dependencies –Your project depends on Hibernate… –…which depends on cglib…which depends on… SNAPSHOT dependencies –Downloaded anew once every day

25 Other repositories http://download.java.net/maven/2/ http://snapshots.repository.codehaus.org http://repository.codehaus.org Add a new repository to your build: Codehaus Codehaus Repository http://repository.codehaus.org default

26 Dependency resolution (2) org.springframework spring 2.0 compile Resolves to: [repository]/org/springframework/spring/spring-2.0.jar

27 Dependency scopes compile - Dependency is made available in all classpaths (compile, test, and runtime) –Most dependencies will be in this scope provided - Dependency is made available during compile, but will be provided by JDK or container at runtime. –The Servlet API JAR is in this scope test - Dependency is made available only at test time –This scope is appropriate for JUnit. runtime - Dependency is made available in test and runtime classpaths, but not at compile-time system - Like “provided” but you must explicitly provide the dependency JAR file.

28 Online vs. offline Remote dependency resolution depends on internet connection. If you’ll be offline, run Maven with -o switch –Dependencies will only be resolved from local repository –Of course, dependencies must be in local repository

29 Those pesky firewalls Create ~/.m2/settings.xml: true http proxy.habuma.com 8080 mwalls letmeout01

30 What if a JAR isn’t in repository? If it’s open source, look again. It’s probably there. Licenses prevent commercial and some other (SUN) JAR files from being placed in public Maven repositories. –Options: Install in your own private corporate repository Install in your local repository

31 Installing JARs % mvn install:install-file -DgroupId=com.webmethods -DartifactId=glue -Dversion=6.5.1 -Dpackaging=jar -Dfile=glue-6.5.1.jar

32 Profiles

33 Profiles enable you to override certain properties for different scenarios. Defined in section: itest … Enacted with -P switch on command line.

34 Trick: Excluding integration tests In normal SureFire plugin maven-surefire-plugin **/*ITest* Test classes whose names end with “ITest” won’t be run.

35 Excluding integration tests(part 2) In “itest” profile itest org.apache.maven.plugins maven-surefire-plugin none Run integration tests with… % mvn test -Pitest

36 Project relationships

37 Parent POMs Projects can inherit project details from parent projects. –Properties, build details, and even dependencies are inherited Unless declared otherwise, a POM inherits from the “Super POM” –Think of it as Maven’s java.lang.Object Use in child POM: com.habuma basepom 1.0

38 Multi-module projects Base projects with POM containing… – pom – … Child projects to build individual JARs, WARs, etc. Could inherit common properties and dependencies from base project Child projects could be built individually or all at once (by building base project)

39 Archetypes

40 Zero to working app in 10 secs Archetypes are great way to kick-start a project. Running archetype generates a baseline project structure, ready to build. You add project details.

41 Running an archetype % mvn archetype:create -DarchetypeGroupId=com.habuma -DarchetypeArtifactId=spring-webapp-archetype -DarchetypeVersion=1.0 -DgroupId=com.habuma -DartifactId=MySillyWebApp -Dversion=0.1

42 Creating an archetype Build a project with the following structure:

43 An archetype’s pom.xml 4.0.0 com.habuma spring-webapp-archetype maven-plugin 1.0

44 META-INF/archetype.xml webapp src/main/java/HomeController.java src/main/java/AddressFormController.java src/main/java/Address.java src/test/java/HomeControllerTest.java.project.classpath.springBeans src/main/webapp/WEB-INF/web.xml src/main/webapp/WEB-INF/mvc.xml …

45 archetype-resources Where the project template lives Includes any resources and source code that needs to be included in generated project. Source files are “packaged” automatically (be sure to include ${package} in.java files). Text files are filtered and placeholders are replaced.

46 Site generation

47 Developer list craig Craig Walls craig@habuma.com Head honcho Developer habuma.com -5

48 Continuous Integration Cruise Control http://ci.habuma.com/cruisecontrol dev@habuma.com

49 Issue Management JIRA jira.habuma.com

50 Licenses Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.txt repo

51 Mailing Lists Poker Service Mailing List subscribe@habuma.com unsubscribe@habuma.com> poker-dev@habuma.com http://mail-archives.habuma.com

52 Reporting: JavaDoc maven-javadoc-plugin

53 Reporting: Java XRef org.codehaus.mojo jxr-maven-plugin

54 Reporting: Test coverage org.codehaus.mojo cobertura-maven-plugin

55 Reporting: Test reports org.apache.maven.plugins maven-surefire-plugin

56 Reporting: JDepend org.codehaus.mojo jdepend-maven-plugin

57 Additional site content Placed in src/site/… –…/apt : Almost plain text –…/fml : FAQ markup –…/xdoc : XDoc files –site.xml : Site structure

58 Final tips, gotchas and help

59 Tips & Gotchas Resolve dependency ambiguities manually Avoid SNAPSHOT dependencies Only deploy non- SNAPSHOT dependencies once Not all projects have quality POM files Be careful when upgrading Maven--test first!

60 Maven help help:active-profiles –Lists the profiles that are currently active for the build help:effective-pom –Displays the effective POM for the current build, with active profiles factored in help:effective-settings –Prints out calculated settings for the project, given any profile enhancement and the inheritence of global settings into the user settings. help:describe –Describes a plugin and its attributes

61 Q & A Feel free to ask by e-mail anytime: craig@habuma.com Recommended reading:

62 Thank you! Have a great day! Remember to return evaluations!


Download ppt "Managing your builds with Maven 2 Craig Walls LoneStar Software Symposium 2007"

Similar presentations


Ads by Google