Ant-contrib if..then - how?


(Povl Kvols) #1

I’m having a seemingly simple problem importing an Ant build script. I’ve boiled it down to the following. Could someone please help - is this not supported, or what am I missing?

The simple Ant script:

<?xml version="1.0" encoding="windows-1250"?>
<project name="AGradleSandbox" default="check">
    <property name="var2" location="${var1}/some_path"/>
    <echo>Echo from Ant...</echo>
 <target name="check">
        <echo>Ant var1=${var1}</echo>
        <echo>Ant var2=${var2}</echo>
  <if>
        <equals arg1="${var1}" arg2="somevalue"/>
        <then>
          <echo>The values are equal!</echo>
        </then>
  </if>
 </target>
</project>

The Gradle script:

ant.var1=
"somevalue"
ant.importBuild 'build.xml'
  check.dependsOn('configure')
  task configure {
 doFirst {
  println "ant.var1=${ant.var1}"
  println "ant.var2=${ant.var2}"
 }
}

When I run the Gradle script, I get the mysterious error:

Problem: failed to create task or type if Cause: The name is undefined. Action: Check the spelling. Action: Check that any custom tasks/types have been declared. Action: Check that any / declarations have taken place.

Could not execute build using Gradle distribution ‘http://services.gradle.org/distributions/gradle-1.10-bin.zip’.


(Povl Kvols) #2

Solved!

It appeared that a couple of things were missing in the big project this was taken from:

ANT_HOME was not set

-> Updated environment vars

ant.home was not set when running the ant script from Gradle

-> Transferred the ANT_HOME environment variable from Gradle to Ant

The ant-contrib properties file was renamed and changed

-> Following one of many recipes on how to add ant-contrib to the project, modifying it to the actual needs finally worked!