| ------ |
| Mvn |
| ------ |
| Paul Gier |
| ------ |
| 2009-05-06 |
| ------ |
| |
| ~~ Licensed to the Apache Software Foundation (ASF) under one |
| ~~ or more contributor license agreements. See the NOTICE file |
| ~~ distributed with this work for additional information |
| ~~ regarding copyright ownership. The ASF licenses this file |
| ~~ to you under the Apache License, Version 2.0 (the |
| ~~ "License"); you may not use this file except in compliance |
| ~~ with the License. You may obtain a copy of the License at |
| ~~ |
| ~~ http://www.apache.org/licenses/LICENSE-2.0 |
| ~~ |
| ~~ Unless required by applicable law or agreed to in writing, |
| ~~ software distributed under the License is distributed on an |
| ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| ~~ KIND, either express or implied. See the License for the |
| ~~ specific language governing permissions and limitations |
| ~~ under the License. |
| |
| ~~ NOTE: For help with the syntax of this file, see: |
| ~~ http://maven.apache.org/doxia/references/apt-format.html |
| |
| The Mvn Task |
| |
| <<Note: This task is available since version 2.0.10 of the Maven Ant Tasks>> |
| |
| The Maven Ant Tasks have some limited support for calling a full Maven build from Ant. |
| The <<<mvn>>> task is a subclass of the Ant {{{http://ant.apache.org/manual/CoreTasks/java.html}java}} |
| task and supports all of its options such as args, fork, resultproperty, etc. |
| |
| If Maven is already installed on the local system, the Maven build can be called using |
| this local installation by specifying the <<<mavenHome>>> parameter. |
| |
| ----- |
| <artifact:mvn mavenHome="/path/to/maven-2.0.x"> |
| <arg value="install"/> |
| </artifact:mvn> |
| ----- |
| |
| Maven will search for a pom.xml file in the current directory and run the <<<install>>> goal. |
| |
| If the pom file is not located in the current directory, an alternate path to the pom can |
| be specified. |
| |
| ----- |
| <artifact:mvn pom="path/to/my-pom.xml" mavenHome="/path/to/maven-2.0.x"> |
| <arg value="install"/> |
| </artifact:mvn> |
| ----- |
| |
| Running the Mvn Task without a Maven Installation |
| |
| If no local Maven installation is available, the mvn task will attempt to resolve (download) |
| the necessary jar files from the central Maven repository and run the Maven build using |
| these jar files. |
| |
| When the <<<mavenHome>>> attribute is not set, the <<<mvn>>> task will attempt to automatically |
| resolve the required jar files. |
| |
| ----- |
| <artifact:mvn pom="path/to/my-pom.xml"> |
| <arg value="install"/> |
| </artifact:mvn> |
| ----- |
| |
| <<Note: this will use version ${mavenVersion} of the core Maven libraries, contained in the Maven Ant Tasks jar>> |
| |
| Using the Java Task |
| |
| The java task can be used directly without any need for the Maven Ant Tasks. However, |
| this method requires that Maven is already installed on the system. A |
| property called <<<maven.home>>> must be set to point to the local Maven installation, |
| then an Ant macro can be defined for calling Maven. |
| |
| ----- |
| <macrodef name="maven"> |
| <attribute name="options" default="" /> |
| <attribute name="goal" /> |
| <attribute name="basedir" /> |
| <attribute name="resultproperty" default="maven.result" /> |
| <element name="args" implicit="true" optional="true" /> |
| <sequential> |
| <java classname="org.codehaus.classworlds.Launcher" fork="true" |
| dir="@{basedir}" resultproperty="@{resultproperty}"> |
| <jvmarg value="-Xmx512m"/> |
| <classpath> |
| <fileset dir="${maven.home}/boot"> |
| <include name="*.jar" /> |
| </fileset> |
| <fileset dir="${maven.home}/lib"> |
| <include name="*.jar" /> |
| </fileset> |
| </classpath> |
| <sysproperty key="classworlds.conf" value="${maven.home}/bin/m2.conf" /> |
| <sysproperty key="maven.home" value="${maven.home}" /> |
| <arg line="--batch-mode @{options} @{goal}" /> |
| </java> |
| </sequential> |
| </macrodef> |
| ----- |
| |
| This example defines an Ant macro called <<<maven>>>. The macro can then be used in |
| the build like this: |
| |
| ----- |
| <maven basedir="${basedir}" |
| options="${maven.opts}" |
| goal="install" |
| resultproperty="maven.build.result"/> |
| ----- |
| |