I am trying to pass parameters to an ant target in another build file in a different location .
Here is what I did :-
<target name="run">
<ant dir="../${dir}" target="package" inheritAll="false"/>
<property name="-Darg.vendor" value="arm"/>
<property name="-Darg.tech" value="tsmc40g"/>
</ant>
</target>
I pass the dir from command line and run the target package from the build file there.
I am trying to pass the parameters but it is not accepting them.
Can anyone please help me fix this
Don't include the command line switches :
<target name="run">
<ant dir="../${dir}" target="package" inheritAll="false"/>
<property name="arg.vendor" value="arm"/>
<property name="arg.tech" value="tsmc40g"/>
</ant>
</target>
Related
build.xml
<target name="main">
<ant antfile="build-foo.xml" dir="${basedir}" target="foo"
inheritAll="false" useNativeBasedir="true">
<property name="messages" value="NOT_FOO_BAR"/>
</ant>
</target>
build-foo.xml
<target name="foo">
<property name="messages" value="FOO"/>
<ant antfile="build-bar.xml" dir="${basedir}" target="bar"
inheritAll="false" useNativeBasedir="true">
</ant>
</target>
build-bar.xml
<target name="bar">
<property name="messages" value="BAR"/>
<echo message="messages = ${messages}"/>
</target>
Tried:
ant -buildfile build-foo.xml foo
the messages is BAR, as expected.
ant -buildfile build.xml main
the messages is NOT_FOO_BAR.
The properties from main is passed multi-level down, even if it is not desired in build-foo.xml: inheritAll=false.
How to prevent the properties from being passed down to its descendant calls? Thanks.
From ant manual ant task :
You can also set properties in the new project from the old project by
using nested property tags. These properties are always passed to
the new project and any project created in that project regardless
of the setting of inheritAll. This allows you to parameterize your
subprojects.
instead :
<target name="main">
<ant antfile="build-foo.xml" dir="${basedir}" target="foo"
inheritAll="false" useNativeBasedir="true"/>
<property name="messages" value="NOT_FOO_BAR"/>
</target>
meets your expections.
I have installed Ant in my centos 6.3 , installed location are
/opt/ant and also ANT_HOME env are same
I have created build.xml to test by deleting testdir. This directory exist in the /opt/ant/testdir like this.
build.xml
<?xml version="1.0"?>
<project name="testdir" default="all" basedir=".">
<property name="src" value="src"/>
<property name="build" value="build"/>
<property name="lib" value="lib"/>
<target name="all" depends="clean, compile" description="Builds the whole project">
<echo>Doing all</echo>
</target>
<target name="clean">
<echo message="Deleting bin/java ..." />
<delete dir="testdir/test" />
</target>
</project>
Using Command :-
ant -buildfile build.xml Clean
getting error:-
BUILD FAILED
Target "Clean" does not exist in the project "testdir".
Any suggestion to make it work?
You mis-spelt the target name ? 'Clean' as against 'clean' ??
I have found solution. I missed target="compile" block in build.xml.
<target name="compile">
<echo message="Compiling source code"/>
</target>
Run command :-
ant clean
I have a master build file which is calling other build.xml files of different projects.
One of my build file needs a command line argument for the execution
ant -Denv=81 -buildfile build_war.xml
I wrote one task in master build.xml to call build_war.xml
<target name="buildDataExtractor">
<ant antfile="..\SEFTooling\build_war.xml" inheritall="false" />
</target>
How do I pass the "-Denv=81" parameter so that build_war.xml will be executed correctly.
Try passing properties to the ant task:
<ant antfile="..\SEFTooling\build_war.xml" inheritall="false">
<property name="env" value="${env}"/>
</ant>
NOTE: in order for this to work properly, you will need to call your main build with ant -Denv=81 or set a property in the main build.xml as such:
<property name="env" value="81"/>
I have a build.xml sitting at the top level and I want the script to run a target for each subdirectory and pass in the subdirectory name as a parameter to the ANT target.
Can you help ?/??
Thanks
Take a look at the subant task. From that page:
<project name="subant" default="subant1">
<property name="build.dir" value="subant.build"/>
<target name="subant1">
<subant target="">
<property name="build.dir" value="subant1.build"/>
<property name="not.overloaded" value="not.overloaded"/>
<fileset dir="." includes="*/build.xml"/>
</subant>
</target>
</project>
this snippet build file will run ant in each subdirectory of the project directory, where a file called build.xml can be found. The property build.dir will have the value subant1.build in the ant projects called by subant.
this is might be what you looking for,
put this as one of your target in your parent build.xml
<target name="executeChildBuild">
<ant antfile="sub1/build.xml" target="build" />
<ant antfile="sub2/build.xml" target="build" />
</target>
If you would like to do it in ant build file, you could use Ant Contrib's for task to iterate over list of subdirectories and execute ant task for each of them.
<for param="subdir">
<dirset dir="${build.dir}">
<include name="./**"/>
</dirset>
<sequential>
<subant target="${target}">
<property name="subdir.name" value="#{subdir}"/>
</subant>
</sequential>
</for>
I didn't test this code since don't have ant installed, but it is close to what you're trying to do I suppose.
If I read the question correctly, this may be what you are looking for instead.
So for your example...
<target name="do-all">
<antcall target="do-first">
<param name="dir-name" value="first"/>
<param name="intented-target" value="init"/>
</antcall>
<antcall target="do-first">
<param name="dir-name" value="second"/>
<param name="intented-target" value="build"/>
</antcall>
<antcall target="do-first">
<param name="dir-name" value="third"/>
<param name="intented-target" value="compile"/>
</antcall>
</target>
<target name="do-first">
<echo>Hello from ${dir-name} ${intented-target}</echo>
<ant antfile="${dir-name}/build.xml" target="${intented-target}"/>
</target>
When you are calling this from Ant, you would enter this at the command line:
ant do-all
and your output should look like this:
do-all:
do-first:
[echo] Hello from first init
do-first:
[echo] Hello from second build
do-first:
[echo] Hello from third compile
BUILD SUCCESSFUL
Total time: 1 second
You will of course need to make sure that the directory name that you are using as a param actually exists, or the build will fail.
You can also always feed the variable that you want to use by adding the value to the build.properties file.
I have a little ant script which should create 3 tar files.
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." >
<property name="dcc-shell.dir" value="${basedir}"/>
<property name="dcc-mdp.dir" value="${dcc-shell.dir}/eq-mo-drop-copy-converter-mdp"/>
<property name="mdp-code.dir" value="${dcc-mdp.dir}/src/main/*"/>
<property name="dcc-srv.dir" value="${dcc-shell.dir}/eq-mo-drop-copy-converter-server"/>
<property name="srv-code.dir" value="${dcc-srv.dir}/src/main/*"/>
<property name="dcc-trans.dir" value="${dcc-shell.dir}/eq-mo-drop-copy-converter-transformer"/>
<property name="trans-code.dir" value="${dcc-trans.dir}/src/main/*"/>
<target name="create MDP Tar">
<tar destfile="${dcc-shell.dir}/mdp.tar"
basedir="${dcc-mdp.dir}/**"
excludes="${dcc-mdp.dir}/target/*"
/>
</target>
<target name="create Trans Tar">
<tar destfile="${dcc-shell.dir}/trans.tar"
basedir="${dcc-trans.dir}/**"
excludes="${dcc-trans.dir}/target/*"
/>
</target>
<target name="create SRV Tar">
<tar destfile="${dcc-shell.dir}/srv.tar"
basedir="${dcc-srv.dir}/**"
excludes="${dcc-srv.dir}/target/*"
/>
</target>
</project>
The script runs fine:
Buildfile: C:\eq-Drop-Copy\eq-mo-drop-copy-converter-shell\build.xml
BUILD SUCCESSFUL
Total time: 94 milliseconds
However no tar files are created within the project. Somewhat of a mystery to myself
EDIT
I have been getting the following error!
<target name="create MDP.Tar">
<tar destfile="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/mdp.tar"
basedir="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/eq-mo-drop-copy-converter-mdp/*"
excludes="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/eq-mo-drop-copy-converter-mdp/target/*"
/>
</target>
I have changed the xml to the absoulet paths:
<target name="create MDP.Tar">
<tar destfile="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/mdp.tar"
basedir="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/eq-mo-drop-copy-converter-mdp/*"
excludes="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/eq-mo-drop-copy-converter-mdp/target/*"
/>
</target>
However still the same error how can the basedir not exist the build file is contained within it. The basedir within the MDP target is pointing to an absoulet path and tar all the files within that. why would this be giving an error?
Most likely you called it without giving a target. Your printout does not show any tar targets executed.
Try calling it with target name as argument to ant. Then you will also find out that using spaces in target names may not be such a good idea.
I corrected several issues:
basedir attribute shouldn't have "*" in it. It'll automatically do the whole tree.
Targets can't contain spaces
You probably didn't specify targets. Therefore, I simply added a default target "create_all_tars", and used <antcall> to call the needed targets.
<project basedir="." default="create_all_tars" >
<property name="dcc-shell.dir"
value="${basedir}"/>
<property name="dcc-mdp.dir"
value="${dcc-shell.dir}/eq-mo-drop-copy-converter-mdp"/>
<property name="mdp-code.dir"
value="${dcc-mdp.dir}/src/main/*"/>
<property name="dcc-srv.dir"
value="${dcc-shell.dir}/eq-mo-drop-copy-converter-server"/>
<property name="srv-code.dir"
value="${dcc-srv.dir}/src/main/*"/>
<property name="dcc-trans.dir"
value="${dcc-shell.dir}/eq-mo-drop-copy-converter-transformer"/>
<property name="trans-code.dir"
value="${dcc-trans.dir}/src/main/*"/>
<target name="create_all_tars">
<antcall target="create_MDP_Tar"/>
<antcall target="create_Trans_Tar"/>
<antcall target="create_SRV_tar"/>
</target>
<target name="create_MDP_Tar">
<tar destfile="${dcc-shell.dir}/mdp.tar"
basedir="${dcc-mdp.dir}"
excludes="${dcc-mdp.dir}/target/**"/>
</target>
<target name="create_Trans_Tar">
<tar destfile="${dcc-shell.dir}/trans.tar"
basedir="${dcc-trans.dir}"
excludes="${dcc-trans.dir}/target/**"/>
</target>
<target name="create_SRV_Tar">
<tar destfile="${dcc-shell.dir}/srv.tar"
basedir="${dcc-srv.dir}"
excludes="${dcc-srv.dir}/target/**"/>
</target>
Does this help?