0% found this document useful (0 votes)
90 views

Maven2 Quick Reference

A quick reference card in four letter-sized pages for Apache's Maven 2. Based on Apache's POM documentation.

Uploaded by

nathandelane5347
Copyright
© Attribution ShareAlike (BY-SA)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

Maven2 Quick Reference

A quick reference card in four letter-sized pages for Apache's Maven 2. Based on Apache's POM documentation.

Uploaded by

nathandelane5347
Copyright
© Attribution ShareAlike (BY-SA)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Maven2 Quick Reference

Created by nathandelane
Project
<project xmlns=http://maven.apache.org/POM/4.0.0 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://maven.apache.org/POM/4.0.0 Http://maven.apache.org/xsd/maven-4.0.0.xsd> <modelVersion>4.0.0</modelVersion> <groupId>com.your.group</groupId> <artifactId>your-project</artifactId> <packaging>jar</packaging> <!-- optional --> <classifier></classifier> <!-- optional --> <version>1.0</version> </project> groupId: Organization or primary project package. artifactId: Name of project. version: Version of the project. packaging: jar packaging is default if not defined; others include war, pom, maven-plugin, ejb, war, ear, rar, and par. classifier:

Inheritance
packaging: Must be pom for parent of aggregation (multi-module projects. elements inherited by children: dependencies, developers and contributors, plugin lists reports lists, plugin executions with matching Ids, and plugin configuration.

<parent> <groupId>org.codehaus.mojo</groupId> <artifactId>my-parent</artifactId> <version>2.0</version> <relativePath>../my-parent</artifactId> </parent> relativePath: Not required, but may be used as search path for Maven for project's parent, used before searching local and remote repos.

Aggregation
<modules> <module>my-project</module> <module>another-project</module> </modules> Do not need to consider inter-module dependencies when listing modules and order is not important. Maven will topologically sort the modules such that dependencies are always built before dependent modules.

groupId:artifactId:packaging:classifier:version

Dependencies
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.0</version> <type>jar</type> <scope>test</scope> <optional>true</optional> </dependency> ... </dependencies> groupId, artifactId, version: Same as project. Can install dependency using install plugin if no Maven repo is available: mvn install:install-file -Dfile=non-maven-proj.jar -DgroupId=some.group \ -DartifactId=non-maven-proj -Dversion=1.0 -Dpackaging=jar classifier: Allows distinguishment of artifacts built from same POM that differ in contents. Consider artifiacts targetting different JDKs. type: Depedent artifact's type. scope:Refers to classpath of the task and how to limit transitivity. Scopes are: compile, provided, runtime, test, and system. systemPath: used only if scope is system. Path must be absolute, i.e. ${java.home}/lib. optional: marks a dependency optional.

Properties
Properties are value place holders. They are used like variables throughout the POM. Definition <properties> <property.name>value</property.name> </properties> Usage <version>${property.name}</version> ...

Exclusions
<dependencies> <dependency> <groupId>org.apache.maven</groupId> <artifactId>manev-embedder</artifactId> <version>2.0</version> <exclusions> <exclusion> <exclusion> <groupId>org.apache.maven</groupId> <artifactId>maven-core</artifactId> </exclusion> </exclusion> </exclusions> </dependency> </dependencies>

Builds

BaseBuild: Elements common to both build elements (top-level and profile). Build: Contains BaseBuild set and more elements for the top-level definition.

<build>...</build> <profiles> <profile> <build>...</build> </profile> </profiles> (Continued on next page.)

exclusions: Exclusions contain one of more exlusion elements, each with groupId and artifactId.

Builds (continued)
<build> <defaultGoal>install</defaultGoal> <directory>${basedir}/target</directory> <finalName>${artifactId}-${version}</finalName> <filters> <filter>filters/filter1.properties</filter> </filters> </build> defaultGoal: Default goal or phase to execute if none is given. Define as jar:jar on the command line. directory: Directory where build will dump files (target). Defaults to ${basedir}/target. finalName: Name of the bundled project when built. filter: Defines *.properties files that contain poperties to apply to resources which accept their settings. The name=value pairs define values to be used as ${name} within resources on build.

Executions
<plugin> <executions> <execution> <id>echodir</id> <goals> <goal>run</goal> </goals> <phase>verify</phase> <inherited>false</inherited> <configuration> <tasks> <echo>Build Dir: ${project.build.directory}</echo> </tasks> </configuration> </execution> </executions> </plugin> id: Id of the execution. goals: Plugin goals for execution. phase: Phase in which the list of goals will be executed. inherited: Setting to false suppresses Maven from passing this execution to children. configuration: Confines configuration to this specific list of goals.

Build Resources
<build> ... <resources> <resource> <targetPath>META_INF/plexus</targetPath> <filtering>false</filtering> <directory>${basedir}/src/main/plexus</directory> <includes> <include>configuration.xml</include> </includes> <excludes> <exclude>**/*.properties</exclude> </excludes> </resource> </resources> <testResources> </testResources> </build> resources: List of resource elements. targetPath: Output path for resources. filtering: May be true or false, denoting whether filtering is enabled for this resource. directory: Defines where the resources are found. includes: Set of files patterns which specifcy files to include as resources. excludes: Same as includes but excludes files identified by patterns. testResources: Similar to resources but are used during testing phase.

Plugin Management
pluginManagement: Surrounds plugins optionally. Used for children plugin inheritance in parent POM for plugins. Children may override in their own plugins section.

Build Element Set Directories


<build> <sourceDirectory>${basedir}/src/main/java</sourceDirectory> <scriptSourceDirectory>${basedir}/src/main/scripts</scriptSourceDirectory> <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory> <outputDirectory>${basedir}/target/classes</outpurDirectory> <testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory> ... </build>

Build Element Set Extensions


<build> <extensions> <extension> <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-ftp</artifactId> <version>1.0-alpha-3</version> </extension> </extension> </extensions> ... </build>

Plugins
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.0</version> <extensions>false</extensions> <inherited>true</inherited> <configuration> <classifier>test</classifier> </configuration> <dependencies>...</dependencies> <executions>...</executions> </plugin> </plugins> </build> extensions: true or false, whether or not to load extensions of this plugin. Default is false. inherited: true or false, whether or not this plugin configuration should apply to POMs which inherit from this one. configuration: Plugin configuration. Properties can be specified here:

<configuration> <items> <item>parent-1</item> </items> <properties> <parentKey>parent</parentKey> </properties> </configuration> dependencies: Dependencies of plugin. See project dependencies. executions: Multiple goals for plugin.

Reporting
<reporting> <outputDirectory>${basedir}/target/site</outputDirectory> <plugins> <plugin> <artifactId>maven-project-info-reports-plugin</artifactId> <version>2.0.1</version> <reportSets> <reportSet></reportSet>

Reporting (continued)
... </reportSets> </plugin> </plugins> </reporting>

Report Sets
<reportSets> <reportSet> <id>sunlink</id> <reports> <report>javadoc</report> </reports> <inherited>true</inherited> <configuration> <links> <link>http://java.sun.com/j2se/1.5.0/docs/api/</link> </links> </configuration> </reportSet> </reportSets>

<url>http://eric.propellors.net</url> <organization>Codehaus</organization> <organizationUrl>http://mojo.codehaus.org</organizationUrl> <roles> <role>architect</role> <role>developer</role> </roles> <timezone>-6</timezone> <properties> <picUrl>http://tinyurl.com/prv4t</picUrl> </properties> </developer> </developers> id, name and email: Correspond to developer's identification. organization and organizationUrl: Orgnaization-related attributes. roles: Roles of the developer played in the organization. timezone: Timezone offset from GMT where the developer lives. properties: Any other properties that are related to the developer. Plugins may use these properties or they may be used for readability and informational purposes.

Contributors
<contributors> <contributor> <id>eric</id> <name>Noelle</name> <email>[email protected]</email> <url>http://noellemarie.com</url> <organization>Noelle Marie</organization> <organizationUrl>http://noellemarie.com</organizationUrl> <roles> <role>tester</role> </roles> <timezone>-5</timezone> <properties> <gtalk>[email protected]</gtalk> </properties> </contributor> </contributors>

More Project Information


name: Conversational name of project beyond the artifactId. Like Natty Narwhal for Ubuntu 11.04. description: Description of the project. url: URL for where the project lives, like a homepage or Sourceforge.net site. inceptionYear: What year the project began to be a project.

Licenses
<licenses> <license> <name>Apache 2</name> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> <distribution>repo</distribution> <comments>A business-friendly OSS license</comments> </license> </licenses> name, url and comments: Encouraged for better description. distribution: This describes how the project is legally distributed. Two stated methods are repo (Maven repository) and manual (manually installed).

Issue Management
<issueManagement> <system>Bugzilla</system> <url>http://127.0.0.1/bugzilla/</url> </issueManagement>

Organization
<organization> <name>Codehaus Mojo</name> <url>http://mojo.codehaus.org</url> </organization>

SCM
<scm> <connection>scm:svn:http://127.0.0.1/svn/my-project</connection> <developerConnection>scm:svn:https://127.0.0.1/svn/my-project</developerConnection> <tag>HEAD</tag> <url>http://127.0.0.1/websvn/my-project</url> </scm> connection and developerConnection: Connection URLs to scm. Connection is readonly for Maven. tag: Specifies the tag that the project lives under. url: Publicly browsable repository URL. (continued on next page)

Developers
<developers> <developer> <id>eric</id> <name>Eric</name> <email>[email protected]</email> (continued above)

SCM (continued)
<prerequisites> <maven>2.0.4</maven> </prerequisites>

prerequisites: The POM may have certain prerequisites in order to execute properly.

Repositories
<repositories> <repository> <releases> <enabled>false</enabled> <updatePolicy>always</updatePolicy> <cheksumPolicy>warn</checksumPolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>never</updatePolicy> <checksumPolicy>fail</checksumPolicy> </snapshots> <id>codehausSnapshots</id> <name>Codehaus Snapshots</name> <url>http://snapshots.maven.codehaus.org</url> <layout>default</layout> </repository> </repositories> <pluginRepositories> </pluginRepositories> releases and snapshots: Policies for each type of artifact, Releas or Snapshot. enabled: true or false whether this repository is enabled for the respective type. updatePolicy: How often updates should occur. Choices are always, daily (default), interval:X (where X is an integer in minutes) or never. checksumPolicy: When Maven deploys files to repository it also deploys corresponding checksum files. Options are ignore, fail or warn on missing or incorrect checksums. layout: Corresponds to Maven repository layout. May be default or legacy (Maven 1.x).

<property> <name>mavenVersion</property> <value>2.0.3</value> </property> <file> <exists>${basedir}/file2.properties</exists> <missing>${basedir}/file1.properties</missing> </file> </activation> jdk: Built-in jdk-checking os: OS enforcement property: Profile automatically activates if Maven detects a property of the corresponding name=value pair. file: A given filename may activate the profile by its existence or its being missing.

Distribution Management
<distributionManagement> <downloadUrl>http://mojo.codehaus.org/my-project</downloadUrl> <status>deployed</status> </distributionManagement> downloadUrl: URL of the repository from where another POM may be pointed to grab this POM's artifact. status: Maven will set this status to either none, converted, partner, deployed, or verified.

Repository
<distributionManagement> <repository> <uniqueVersion>false</uniqueVersion> <id>corpl</id> <name>Corporate Repository</name> <url>scp://repol/maven2</url> <layout>default</layout> </repository> <snapshotRepository> <uniqueVersion>true</uniqueVersion> <id>propSnap</id> <name>Propellors Snapshots</name> <url>sftp://properllors.net/maven</url> <layout>legacy</layout> </snapshotRepository> </distributionManagement> id and name: The id used to uniquely identify this repository among many and the human readable name. uniqueVersion: true or false, denotes whether artifacts deployed to this repository get a uniquely generated version number or use the version number as part of the address. url: Specified transport protocol to be used to transfer a built artifact. layout: Same as before, either default or legacy (for Maven 1.x).

Profiles
<profiles> <profile> <id>test</id> <activation>...</activation> <build>...</build> <modules>...</modules> <repositories>...</repositories> <pluginRepositories>...</pluginRepositories> <dependencies>...</dependencies> <reporting>...</reporting> <dependencyManagement>...</dependencyManagement> <distributionManagement>...</distributionManagement> </profile> </profile>

Activation
<activation> <activeByDefault>false</activeByDefault> <jdk>1.5</jdk> <os> <name>Windows XP</name> <family>Windows</family> <arch>x86</arch> <version>5.1.2600</version> </os> (continued above)

You might also like