Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call for a Maven goal within an Ant script?

Tags:

java

maven

ant

Is it possible to call or execute a Maven goal within an Ant script?

Say I have an ant target called 'distribute' and inside which I need to call a maven 'compile' goal from another pom.xml.

like image 957
Dunith Dhanushka Avatar asked Sep 28 '11 09:09

Dunith Dhanushka


People also ask

How do I run a specific target in Ant?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.

Can we use Maven and Ant together?

You can use the maven-antrun-plugin to invoke the ant build. Then use the build-helper-maven-plugin to attach the jar produced by ant to the project. The attached artifact will be installed/deployed alongside the pom. If you specify your project with packaging pom , Maven will not conflict with the ant build.

Which goal is used to invoke Ant tasks for a Maven build?

The maven-antrun-plugin has only one goal, run . This allows Maven to run Ant tasks.


2 Answers

Since none of the solutions worked for me, this is what I came up with:

Assuming you are running on Windows:

<target name="mvn">     <exec dir="." executable="cmd">         <arg line="/c mvn clean install" />     </exec> </target> 

or on UNIX:

<target name="mvn">     <exec dir="." executable="sh">         <arg line="-c 'mvn clean install'" />     </exec> </target> 

or if you want it to work on both UNIX and Windows:

<condition property="isWindows">     <os family="windows" /> </condition>  <condition property="isUnix">     <os family="unix" /> </condition>  <target name="all" depends="mvn_windows, mvn_unix"/>  <target name="mvn_windows" if="isWindows">     <exec dir="." executable="cmd">         <arg line="/c mvn clean install" />     </exec> </target>  <target name="mvn_unix" if="isUnix">     <exec dir="." executable="sh">         <arg line="-c 'mvn clean install'" />     </exec> </target> 
like image 118
Adam Siemion Avatar answered Sep 22 '22 22:09

Adam Siemion


An example of use of exec task utilizing Maven run from the Windows CLI would be:

<target name="buildProject" description="Builds the individual project">     <exec dir="${source.dir}\${projectName}" executable="cmd">         <arg value="/C"/>         <arg value="${env.MAVEN_HOME}\bin\mvn.bat"/>         <arg line="clean install" /> </exec> </target> 
like image 38
mateusz.fiolka Avatar answered Sep 19 '22 22:09

mateusz.fiolka