You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Quinton McCombs <qm...@nequalsone.com> on 2003/02/05 00:47:16 UTC

How do I pass variables to ant?

Is it possible for an Ant script called by Maven to read properties
defined in maven.xml?  For example, I have an ant file that uses a
variable called "test".  I need to call the ant task several times as I
am building my project each time with a different value for "test".

I thought this was possible by looking at maven.xml from Fulcrum.  I
found the following code being used:

    <!-- Now generate the security service. -->
    <j:set var="torque.project" value="security"/>
    <j:set var="torque.schema.om.includes" value="turbine-schema.xml"/>
    <j:set var="torque.targetPackage" value="${security.package}"/>
    <filter token="DATABASE_DEFAULT" value="${security.database.name}"/>
    <filter token="EXTRA_USER_COLUMNS"
value="${security.extra.user.columns}"/>
    <copy
      file="turbine-schema.xml"
      tofile="${torque.schema.dir}/turbine-schema.xml"
      filtering="yes"/>
    <attainGoal name="torque:om"/>

    <!-- Reset the Torque uptodate check flag. -->
    <j:set var="torque.internal.om.uptodate" value="${null}"/>

    <!-- Now generate the scheduler service. -->
    <j:set var="torque.project" value="scheduler"/>
    <j:set var="torque.schema.om.includes"
value="scheduler-schema.xml"/>
    <j:set var="torque.targetPackage" value="${scheduler.package}"/>
    <filter token="DATABASE_DEFAULT"
value="${scheduler.database.name}"/>
    <filter token="EXTRA_USER_COLUMNS"
value="${scheduler.extra.user.columns}"/>
    <copy
      file="scheduler-schema.xml"
      tofile="${torque.schema.dir}/scheduler-schema.xml"
      filtering="yes"/>
    <attainGoal name="torque:om"/>


As you can see, some of the torque.* variables are being defined before
calling torque:om.  These values a never seen by ant ant script that is
called by the torque plugin though.  

Here is a simple set of goals that can be added to a valid maven.xml
file to demonstrate the problem:

  <goal name="test:ant">
      <attainGoal name="test:ant1"/>
      <attainGoal name="test:ant2"/>
  </goal>

  <goal name="test:ant1" description="test of passing variables to ant">
      <j:set var="test" value="It worked!"/>
      <ant antfile="ant-test.xml" target="test"/>
  </goal>

  <goal name="test:ant2" description="test of passing variables to ant">
      <ant antfile="ant-test.xml" target="test">
          <setProperty name="test" value="It worked!"/>
      </ant>
  </goal>

Here is the ant-test.xml file:

<project name="ant-test" default="test" basedir=".">
    <target name="test">
        <echo message="Test variable = ${test}"/>
    </target>
</project>


Here is the result of maven test:ant:

test:ant:
test:ant1:
    [echo] Test variable = ${test}

test:ant2:
    [echo] Test variable = ${test}


I hope that I am missing something...  Is there some other way to make
this work?

Re: How do I pass variables to ant?

Posted by Incze Lajos <in...@mail.matav.hu>.
> I hope that I am missing something...  Is there some other way to make
> this work?
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-maven-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-maven-user-help@jakarta.apache.org

I've ran your example with the current cvs head maven:

 __  __
|  \/  |__ Jakarta _ ___
| |\/| / _` \ V / -_) ' \  ~ intelligent projects ~
|_|  |_\__,_|\_/\___|_||_|   v. 1.0-beta-8


Attempting to download commons-jelly-tags-xml-SNAPSHOT.jar.
test:ant:
test:ant1:
    [echo] Test variable = It worked!

test:ant2:
    [echo] Test variable = It worked!
BUILD SUCCESSFUL
Total time:  10 seconds


incze