Apache Maven 2 Overview                                                         Part 2                                    ...
The Goal•   Understand several Maven capabilities•   Build multi-module project with Maven•   Some special pom blocks•   N...
Maven in real world      WORKING WITH MULTI-MODULE                      PROJECTSExigen Services confidential              ...
Project contents                 GWT               application                                     EJB A   EJB B          ...
What to do with Maven?• 4 independent artifacts with dependencies  •   Build in one step?  •   Organize versioning?  •   K...
Maven Inheritance & Aggregation•   <packaging>pom</packaging>•   Super pom•   Data in parent pom is inherited•   Maven dep...
Maven Inheritance & Aggregation                                     Parent                                           pom E...
Maven in action<project …>    <modelVersion>4.0.0</modelVersion>    <groupId>ru.exigenservices</groupId>    <artifactId>my...
Maven in action• What about deployment?  • EAR needed  • Special step needed• Maybe divide frontend and backend?• NB! One ...
Maven in action                                       Parent                                              pom       Fronte...
Multimodal hierarchy                                •    Parent pom                                <project …>            ...
Dependency&Plugin management• Changeable, overriddable and inheritable• In parent  • GroupId & ArtifactId  • Version  • Ev...
Dependency&Plugin ManagementParent:<dependencyManagement>   <dependencies>    <dependency>         <groupId>javax</groupId...
Flat vs Tree, Flat   .   |-- my-module   | `-- pom.xml   `--parent       `--pom.xml• Pom.xml for my-module:  <project>   <...
Maven reactor• Collects all the available modules to build• Sorts the projects into the correct build order   • a project ...
Conclusion•   Inheritance and aggregation•   Flat/Tree structure•   Maven reactor•   Dependency&Plugin management•   Deplo...
What will help you                           PROPERTIES, PROFILES,                              EXECUTION BLOCKSExigen Ser...
Maven properties• Just as common Ant properties• ${property_name}• Case sensitive  • Upper case for environment variables•...
Predefined properties• Build in properties   • ${basedir} – directory with pom   • ${version} – artifact version• Project ...
Maven profiles• Maven profile – special way for configuring  build• Different environments – different results  • Renaming...
Maven profiles• Per project  • pom.xml• Per user  • %USER_HOME%/.m2/settings.xml• Per computer (Global)  • %M2_HOME%/conf/...
Maven profiles• Activation  • By hand (-P profile1,profile2)  • <activeProfiles>  • <activation>     • By environment sett...
Maven profiles<profiles>   <profile>    <activation>        <jdk>[1.3,1.6)</jdk>    </activation>   ...   </profile>   <pr...
Mojo• Plugin  • Executing action• Mojo – magical charm in hoodoo  •   Just a Goal  •   Plugin consists of Mojos  •   Some ...
Mojo• When we should use mojos?• Run from command line• Different execution parameters for different  configurations• Grou...
Execution blocksPlugin:time<plugin>    <groupId>com.mycompany.example</groupId>    <artifactId>plugin</artifactId>    <ver...
SCM SourceCodeManagement•   CVS, Mercurial, Perforce, Subversion, etc.•   Commit/update•   scm:bootstrap – build project• ...
Maven archetypes• Create folders, poms, general stuff• Archetype  Project• For creating project:  • archetype:generate  ...
Provided Arhetypes• maven-archetype-archetype   • Sample archetype• maven-archetype-j2ee-simple   • Simplified sample J2EE...
archetype:create-from-project• Sample project• mvn archetype:create-from-project   • src catalog   • Pom.xml (maven-archet...
Good configuration - great advantage                                                NEXUS                                 ...
Sonatype Nexus•   Artifact repository•   Nexus and Nexus Pro•   Rather simple•   Widely used• Other Maven Repository Manag...
Nexus hints• Nexus configuration + local configuration• Proxy repositories  • Add everything and cache it!  • Add to Publi...
Settings.xml• Servers                                                      • Profile   <servers>                          ...
updatePolicy• UpdatePolicy  •   Always  •   Daily (default)  •   Interval:X (X – integer in minutes)  •   Never• Repositor...
When you have free time…LICENSE, ORGANIZATION, DEVELOPER                 S, CONTRIBUTORS   Exigen Services confidential   ...
Licenses• How your project could be used?<licenses>  <license>   <name>The Apache Software License, Version 2.0</name>   <...
Organization• Just tell everybody!<organization>  <name>Exigen Services</name>  <url>http://www.exigenservices.ru/</url></...
Developers & Contributors block•   Id, name, email•   Organization, organizationUrl•   Roles•   Timezone•   Properties• Co...
Developers block<developers> <developer>    <id>anatoly.k</id>    <name>Anatoly</name>    <email>Anatoly.Kondratiev@exigen...
Final notes• A great amount of plugins• Ant-run• Mirrors on local repo, not on computer      Exigen Services confidential ...
Now it’s your turn…                                QUESTIONSExigen Services confidential                    45
Upcoming SlideShare
Loading in...5
×

Apache Maven 2 Part 2

346

Published on

Presenter: Anatoly Kondratiev

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
346
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Apache Maven 2 Part 2"

  1. 1. Apache Maven 2 Overview Part 2 Advanced Topics of Apache Maven 2 Anatoly Kondratyev September 201230 January 2013 Exigen Services confidential Exigen Services confidential
  2. 2. The Goal• Understand several Maven capabilities• Build multi-module project with Maven• Some special pom blocks• Nexus configuration notes Exigen Services confidential 2
  3. 3. Maven in real world WORKING WITH MULTI-MODULE PROJECTSExigen Services confidential 3
  4. 4. Project contents GWT application EJB A EJB B My Library Exigen Services confidential 4
  5. 5. What to do with Maven?• 4 independent artifacts with dependencies • Build in one step? • Organize versioning? • Keeping up to date? • Wrong!• Maven Inheritance and Aggregation • Solves the above problems • Right! Exigen Services confidential 5
  6. 6. Maven Inheritance & Aggregation• <packaging>pom</packaging>• Super pom• Data in parent pom is inherited• Maven dependency reactor• Notes • No cyclic dependencies • No same modules Exigen Services confidential 6
  7. 7. Maven Inheritance & Aggregation Parent pom EJB A EJB B Gwt My library ejb ejb war jar Exigen Services confidential 7
  8. 8. Maven in action<project …> <modelVersion>4.0.0</modelVersion> <groupId>ru.exigenservices</groupId> <artifactId>my-parent</artifactId> <version>1.0.1-SNAPSHOT</version> <packaging>pom</packaging> <modules> <module>EJB-A</module> <module>EJB-B</module> <module>Gwt</module> <module>MyLibrary</module> </modules></project> Exigen Services confidential 8
  9. 9. Maven in action• What about deployment? • EAR needed • Special step needed• Maybe divide frontend and backend?• NB! One pom – one artifact Exigen Services confidential 9
  10. 10. Maven in action Parent pom Frontend Backend pom pom Frontend Backend Gwt EJB A EJB B My library wrapper wrapper jar war ear ejb ejb ear Exigen Services confidential 10
  11. 11. Multimodal hierarchy • Parent pom <project …> <groupId>exigen</groupId> <artifactId>parent</artifactId> <version>1.0.1-SNAPSHOT</version> <packaging>pom</packaging> <modules> <module>backend</module> <module>frontend</module> </modules> </project> • Frontend pom <project …> <parent> <groupId>exigen</groupId> <artifactId>parent</artifactId> <version>1.0.1-SNAPSHOT</version> </parent> <artifactId>frontend</artifactId> <packaging>pom</packaging> <modules> <module>Gwt</module> </modules> </project> Exigen Services confidential 11
  12. 12. Dependency&Plugin management• Changeable, overriddable and inheritable• In parent • GroupId & ArtifactId • Version • Everything you can configure • Type, packaging• In child • GroupId & ArtifactId Exigen Services confidential 12
  13. 13. Dependency&Plugin ManagementParent:<dependencyManagement> <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0</version> <scope>provided</scope> </dependency> </dependencies></dependencyManagement>Child:<dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> </dependency></dependencies> Exigen Services confidential 13
  14. 14. Flat vs Tree, Flat . |-- my-module | `-- pom.xml `--parent `--pom.xml• Pom.xml for my-module: <project> <parent> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <version>1</version> <relativePath>.../parent/pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>my-module</artifactId> </project> Exigen Services confidential 15
  15. 15. Maven reactor• Collects all the available modules to build• Sorts the projects into the correct build order • a project dependency on another module in the build • different rules with plugins dependencies • the order declared in the <modules> element (if no other rule applies)• Builds the selected projects in order• Be aware of cycles and same modules on different parents Exigen Services confidential 16
  16. 16. Conclusion• Inheritance and aggregation• Flat/Tree structure• Maven reactor• Dependency&Plugin management• Deploy to Nexus/Weblogic problem Exigen Services confidential 17
  17. 17. What will help you PROPERTIES, PROFILES, EXECUTION BLOCKSExigen Services confidential 18
  18. 18. Maven properties• Just as common Ant properties• ${property_name}• Case sensitive • Upper case for environment variables• Dot(.) notated path Exigen Services confidential 19
  19. 19. Predefined properties• Build in properties • ${basedir} – directory with pom • ${version} – artifact version• Project properties • ${project.build.directory} • ${project.build.outputDirectory} (target/classes) • ${project.name} • ${project.version}• Local user settings • ${settings.localRepository}• Environment properties • ${env.M2_HOME} Exigen Services confidential 20
  20. 20. Maven profiles• Maven profile – special way for configuring build• Different environments – different results • Renaming • Different build cycles • Special plugin configuration• Just different targets• For different users Exigen Services confidential 22
  21. 21. Maven profiles• Per project • pom.xml• Per user • %USER_HOME%/.m2/settings.xml• Per computer (Global) • %M2_HOME%/conf/settings.xml Exigen Services confidential 23
  22. 22. Maven profiles• Activation • By hand (-P profile1,profile2) • <activeProfiles> • <activation> • By environment settings • By properties Exigen Services confidential 24
  23. 23. Maven profiles<profiles> <profile> <activation> <jdk>[1.3,1.6)</jdk> </activation> ... </profile> <profile> <activation> <property> <name>environment</name> <value>test</value> </property> </activation> ... </profile></profiles> Exigen Services confidential 25
  24. 24. Mojo• Plugin • Executing action• Mojo – magical charm in hoodoo • Just a Goal • Plugin consists of Mojos • Some parameters • MOJO aka POJO (Plain-old-Java-object) Exigen Services confidential 27
  25. 25. Mojo• When we should use mojos?• Run from command line• Different execution parameters for different configurations• Group of mojos from same plugin with different configuration Exigen Services confidential 28
  26. 26. Execution blocksPlugin:time<plugin> <groupId>com.mycompany.example</groupId> <artifactId>plugin</artifactId> <version>1.0</version> <executions> <execution> <id>first</id> <phase>test</phase> <goals> <goal>time</goal> </goals> <configuration> … </configuration> </execution> <execution> <id>default</id> … <!– No phase block --> </execution> </executions></plugin> Exigen Services confidential 29
  27. 27. SCM SourceCodeManagement• CVS, Mercurial, Perforce, Subversion, etc.• Commit/update• scm:bootstrap – build project• Maven Release Plugin • Snapshot  Version • Check everything • Commit Exigen Services confidential 30
  28. 28. Maven archetypes• Create folders, poms, general stuff• Archetype  Project• For creating project: • archetype:generate • Select archetype from list • Set up groupId, artifactId, version, … • Get all project structure and draft files • maven-archetype-quickstart• For creating archetype: • archetype:create-from-project Exigen Services confidential 31
  29. 29. Provided Arhetypes• maven-archetype-archetype • Sample archetype• maven-archetype-j2ee-simple • Simplified sample J2EE application• maven-archetype-plugin • Sample Maven plugin• maven-archetype-quickstart • Sample Maven project• maven-archetype-webapp • Sample Maven Webapp project• More information: http://maven.apache.org/archetype/maven-archetype-bundles/ Exigen Services confidential 32
  30. 30. archetype:create-from-project• Sample project• mvn archetype:create-from-project • src catalog • Pom.xml (maven-archetype) • Some resources• Modify code (…targetgenerated-sourcesarchetype) • archetype-metadata.xml • Update properties and default values; review• Go to target, run “mvn install”• To test archetype “mvn archetype:generate -DarchetypeCatalog=local” Exigen Services confidential 33
  31. 31. Good configuration - great advantage NEXUS SETTING.XMLExigen Services confidential 34
  32. 32. Sonatype Nexus• Artifact repository• Nexus and Nexus Pro• Rather simple• Widely used• Other Maven Repository Managers • Apache Archiva • Artifactory • Comparison http://docs.codehaus.org/display/MAVENUSER/Maven+Repository+Manager+Fe ature+Matrix Exigen Services confidential 35
  33. 33. Nexus hints• Nexus configuration + local configuration• Proxy repositories • Add everything and cache it! • Add to Public Repositories group• Restrictions on uploading artifacts • UI: Artifact Upload Exigen Services confidential 36
  34. 34. Settings.xml• Servers • Profile <servers> <profiles> <server> <profile> <id>nexus</id> <id>nexus</id> <username>…</username> <repositories> <password>…</password> <repository> </server> <id>central</id> </servers> <url>http://central</url>• Mirrors (2.0.9) <releases> <mirrors> <enabled>true</enabled> <mirror> <updatePolicy>never</updatePolicy> <id>nexus</id> </releases> <mirrorOf>*</mirrorOf> <snapshots> <url>http://localserver:8081/nexus/content/groups/public/ <enabled>true</enabled> </url> </snapshots> </mirror> </repository> </mirrors> </repositories>• Active Profile <pluginRepositories> <activeProfiles> … </pluginRepositories> <activeProfile>nexus</activeProfile> </profile> </activeProfiles> </profiles> Exigen Services confidential 37
  35. 35. updatePolicy• UpdatePolicy • Always • Daily (default) • Interval:X (X – integer in minutes) • Never• Repository Snapshots • Enabled true/false Exigen Services confidential 38
  36. 36. When you have free time…LICENSE, ORGANIZATION, DEVELOPER S, CONTRIBUTORS Exigen Services confidential 39
  37. 37. Licenses• How your project could be used?<licenses> <license> <name>The Apache Software License, Version 2.0</name> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> <distribution>repo</distribution> <comments>A business-friendly OSS license</comments> </license></licenses> Exigen Services confidential 40
  38. 38. Organization• Just tell everybody!<organization> <name>Exigen Services</name> <url>http://www.exigenservices.ru/</url></organization> Exigen Services confidential 41
  39. 39. Developers & Contributors block• Id, name, email• Organization, organizationUrl• Roles• Timezone• Properties• Contributors don’t have Id Exigen Services confidential 42
  40. 40. Developers block<developers> <developer> <id>anatoly.k</id> <name>Anatoly</name> <email>Anatoly.Kondratiev@exigenservices.com</email> <organization>Exigen</organization> <organizationUrl>http://www.exigenservices.ru/</organizationUrl> <roles> <role>Configuration Manager</role> <role>Developer</role> </roles> <timezone>+3</timezone> <properties> <skype>anatoly.kondratyev</skype> </properties> </developer></developers> Exigen Services confidential
  41. 41. Final notes• A great amount of plugins• Ant-run• Mirrors on local repo, not on computer Exigen Services confidential 44
  42. 42. Now it’s your turn… QUESTIONSExigen Services confidential 45

×