configuration. Eg. Ruby on Rails, EJB 3.0 Special variable project.basedir - The directory that the current project resides in. ${project.basedir }/ src/main/java /resources /test/java /resources /scripts /target/classes /test -classes /site Defaults without configuring. Apache Ant has to explicitly define these locations Jestine Paul Overview of Dependency Mechanism and Plugin Framework
Is Dumb Just parses a few XML files and keeps track of life cycle and plugins. Action happens in plugin goals - compilation, testing, producing JAR files, reporting, etc. Jestine Paul Overview of Dependency Mechanism and Plugin Framework
M2 HOME=/home/jestinepaul/apache-maven-3.1.0 PATH=${PATH}:${M2 HOME}/bin MAVEN OPTS= -Xms256m -Xmx512m Verifing the installation, mvn -version Global settings - ${MAVEN HOME}/conf/settings.xml User settings - ∼/.m2/settings.xml Effective setting of a user, mvn help:effective -settings Jestine Paul Overview of Dependency Mechanism and Plugin Framework
POM Dependency Mechanism Multi-Module Project Maven Coordinates groupId unique amongst an organization or a project generally resemble a Java package name artifactId name that the project is known by Avoid using dot in artifactId version major.minor.incremental-qualifier If the version contains the string SNAPSHOT, it gets expanded to UTC date and time value packaing - jar, pom, maven-plugin, ejb, war, ear, rar, par classifier - eg. Maven identifies binary and source Jestine Paul Overview of Dependency Mechanism and Plugin Framework
POM Dependency Mechanism Multi-Module Project Super POM Maven always execute against an effective POM - combination of project , parent and super POM. mvn help:effective -pom All Maven pom inherits the super pom. pom-4.0.0.xml in the lib/maven-model-builder-3.0.3¬ .jar:org/apache/maven/model/pom-4.0.0.xml Defines Maven central repository - contains official releases of Maven core plugins java.net , oracle, .. Default values for directories Jestine Paul Overview of Dependency Mechanism and Plugin Framework
POM Dependency Mechanism Multi-Module Project pom-4.0.0.xml V </profiles > </project > Jestine Paul Overview of Dependency Mechanism and Plugin Framework
POM Dependency Mechanism Multi-Module Project Dependency Resolution mvn dependency :tree -Dverbose -Dincludes=commons - collections The verbose flag instructs the dependency tree to display conflicting dependencies that were omitted from the resolved dependency tree [INFO] [dependency:tree] [INFO] org.apache.maven.plugins:maven -dependency -plugin:maven -plug [INFO] +- org.apache.maven.reporting:maven -reporting -impl:jar :2.0. [INFO] | \- commons -validator:commons -validator:jar :1.2.0: compile [INFO] | \- commons -digester:commons -digester:jar :1.6: compile [INFO] | \- (commons - collections :commons - collections :jar :2. [INFO] \- org.apache.maven.doxia:doxia -site -renderer:jar :1.0 - alpha [INFO] \- org.codehaus.plexus:plexus -velocity:jar :1.1.3: compile [INFO] \- commons - collections :commons - collections :jar :2.0: co Thus we can see that Commons Collections 2.0 was chosen over 2.1 since it is nearer, and by default Maven resolves version conflicts with a nearest-wins strategy. Jestine Paul Overview of Dependency Mechanism and Plugin Framework
POM Dependency Mechanism Multi-Module Project Property <properties > <dbDriver >postgresql </ dbDriver > </properties > or mvn ... -DdDriver=mysql Used as ${dbDriver} to define POM values except the coordinates. Jestine Paul Overview of Dependency Mechanism and Plugin Framework
POM Dependency Mechanism Multi-Module Project Multi-Module Project Aggregation <modules > <module >simple -weather </ module > <module >simple -webapp </ module > </modules > Inheritance <parent > <groupId >org.sonatype.mavenbook.ch06 </ groupId > <artifactId >simple -parent </ artifactId > <version >1.0 </ version > </parent > Inheritance and aggregation are two separate features that can be used separately, however they are frequently used together. Jestine Paul Overview of Dependency Mechanism and Plugin Framework
POM Dependency Mechanism Multi-Module Project Multi-Module Project Inheritance and aggregation are two separate features that can be used separately, however they are frequently used together. Maven reactor takes care of the order in the <modules> tag Child project can omit <version> and <exclusion> if <dependencyManagament> tag is defined in parent pom, Use <pluginManagement> tag in parent pom to eliminate duplicate plugin configuration in child pom Use built-in ${project.version} ${project.groupId} when referring to a sibling project. Jestine Paul Overview of Dependency Mechanism and Plugin Framework
Lifecycle Plugins Naming convention xxxxx-maven-plugin for official Apache Maven plugins, maven-xxxxx-plugin Two types: Build - configured in <build> Reporting - configured in <reporting> Help goal mvn javadoc:help -Ddetail -Dgoal=javadoc shows the help for javadoc:javadoc goal Jestine Paul Overview of Dependency Mechanism and Plugin Framework
Lifecycle GreetingMojo I package sample.plugin; import org.apache.maven.plugin. AbstractMojo ; import org.apache.maven.plugin. MojoExecutionException ; import org.apache.maven.plugins. annotations .Mojo; /** * @goal sayhi * @phase package */ public class GreetingMojo extends AbstractMojo { // When reading the configuration , // the text "true" causes the parameter to be set to true // and all other text causes the parameter to be set to false. @Parameter private boolean myBoolean; // byte , Byte , int , Integer , long , Long , short , and Short. Jestine Paul Overview of Dependency Mechanism and Plugin Framework
Lifecycle GreetingMojo II // converted to an integer value using // either Integer.parseInt () // or the valueOf () method of the appropriate class. @Parameter private Integer myInteger; // double , Double , float , and Float // converted to binary form using the // valueOf () method for the appropriate class @Parameter private Double myDouble; // parsing is done using DateFormat.parse () @Parameter private Date myDate; // If the path is relative // (does not start with / or a drive letter like C:), // the path is relative to the directory containing the POM @Parameter Jestine Paul Overview of Dependency Mechanism and Plugin Framework
Lifecycle GreetingMojo III private File myFile; // scheme :// host:port/path/to/file @Parameter private URL myURL; // plain text // char , Character , StringBuffer and String @Parameter private String [] myArray; // any class which implements java.util. Collection // such as ArrayList or HashSet @Parameter private List myList; // any class which implements java.util.Map such as HashMap // but does not implement java.util. Properties @Parameter Jestine Paul Overview of Dependency Mechanism and Plugin Framework
Lifecycle Invoking the Mojo mvn sample.plugin:hello -maven -plugin :1.0 - SNAPSHOT:sayhi Jestine Paul Overview of Dependency Mechanism and Plugin Framework
Lifecycle Shortening the Command Line mvn hello:sayhi omit version - takes the latest shortened-prefix - if prefix-maven-plugin naming convention is followed to omit groupid - ${user.home}/.m2/settings.xml file: <pluginGroups > <pluginGroup >sample.plugin </ pluginGroup > </pluginGroups > Jestine Paul Overview of Dependency Mechanism and Plugin Framework
Lifecycle Build Lifecycle Organised sequence of phases that exist to give order to a set of goals packaged in maven plugin objects. Maven core defines three lifecycles clean - removed all files from ${project.build.directory} default - generates artifacts into ${project.build.directory} site - generates documentation website Each life cycle is an ordered list of phases. Execution of one phase will trigger ordered list of previous phases. dependency Jestine Paul Overview of Dependency Mechanism and Plugin Framework
Lifecycle Standard Life Cycle I clean pre-clean clean post-clean default validate initialize generate-sources process-sources generate-resources process-resources compile process-classes generate-test-sources process-test-sources Jestine Paul Overview of Dependency Mechanism and Plugin Framework
Lifecycle Standard Life Cycle II generate-test-resources process-test-resources process-test-classes test prepare-package package pre-integration-test integration-test post-integration-test verify install deploy site pre-site site Jestine Paul Overview of Dependency Mechanism and Plugin Framework
Lifecycle Packaging pom package site:attach-descriptor install install:install deploy deploy:deploy pom packaging does not produce any artifact aggregates dependencies used in parent pom Jestine Paul Overview of Dependency Mechanism and Plugin Framework
Lifecycle Dependency Scope Specify whether a dependency is involved or not in following phases of build life cycle compile test package Dependency scope values compile - compile, test, package provided - compile, test test - test runtime - package system Import Jestine Paul Overview of Dependency Mechanism and Plugin Framework