Error migrating Oracle Ant build to Gradle

I’m trying to use some of Oracles SOA Suites Ant build files, but I’m having errors with the simplest use case.

When I try to set a property in Gradle, I still cant seem to evaluate the ant build file.

My build file is:

ant.importBuild './ant-soa-common.xml'"oracle.home" = "C:\oracle\Middleware\Oracle_SOA1"

and the build file I’m importing is:

<?xml version="1.0"?>
<project name="ant-soa-common" default="" basedir=".">
  <property name="" value="${oracle.home}"/>
    <property name="mw.home" value="${oracle.home}/.."/>
    <property name="common.components.home" value="${mw.home}/oracle_common"/>
  <fail message="common.components.home: ${common.components.home} doesn't exist.">
      <not><available file="${common.components.home}" type="dir"/></not>
    <property name="common.components.modules" value="${common.components.home}/modules"/>
    <property name="soa.modules" value="${}/soa/modules"/>
    <condition property="oracle.soa.mgmt.home"
    <available file="${common.components.home}/soa/modules/oracle.soa.mgmt_11.1.1/soa-infra-mgmt.jar"/>

And finally the exception is:

Caused by: org.gradle.api.GradleException: Could not import Ant build file 'C:\path\to\Scripts\Gradle\import_ant_sca\ant-soa-common.xml'.
        at org.gradle.api.internal.project.DefaultAntBuilder.importBuild(DefaultAntBuilder.groovy:78)
        at org.gradle.api.internal.project.DefaultAntBuilder$ Source)
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$
        ... 30 more
Caused by: C:\LV\src\other\Scripts\Gradle\import_ant_sca\ant-soa-common.xml:28: common.components.home: ${oracle.home}/../oracle_common doesn't exist.
        at$ Source)
        at org.gradle.api.internal.project.DefaultAntBuilder.importBuild(DefaultAntBuilder.groovy:76)

I guess you have to set the property before you import the build.

Ok, I sort of feel stupid for not trying that, but I can qualify why I never.

In this example gradle build:

ant.importBuild '../ant/build.xml'
  [init, compile, dist]*.logging*.level = LogLevel.INFO
  init {
    doFirst {
        logger.quiet "Deleting the directory '${}'."
      doLast {
        logger.quiet "Starting from a clean slate."
  ext.antBuildDir = '../ant/build' = "$antBuildDir/classes" = "$antBuildDir/libs"
  task sourcesJar(type: Jar) {
    baseName = 'my-app'
    classifier = 'sources'
    version =
    destinationDir = file(
    from new File(, 'main/java')
  dist.dependsOn sourcesJar
  compile {
    inputs.dir file(
    outputs.dir file(
  task downloadReleaseDocumentation << {
    logging.level = LogLevel.INFO
    ext.repoUrl = ''
      ant.get(dest: {
        url(url: "$repoUrl/files/README.txt")
        url(url: "$repoUrl/files/RELEASE_NOTES.txt")
  dist.dependsOn downloadReleaseDocumentation
  configurations {
  repositories {
  dependencies {
    antCompile 'org.apache.commons:commons-lang3:3.1'
} = configurations.antCompile.asPath

and the ant file:

<project name="my-app" default="dist" basedir=".">
    <!-- set global properties for this build -->
    <property name="src" location="src"/>
    <property name="build" location="build"/>
    <property name="lib" location="lib"/>
    <property name="dist" location="dist"/>
    <property name="version" value="1.0"/>
      <target name="init">
        <!-- Create the build directory structure used by compile -->
        <mkdir dir="${build}"/>
      <target name="compile" depends="init" description="compile the source">
        <!-- Compile the java code from ${src} into ${build} -->
        <javac srcdir="${src}" destdir="${build}" classpath="${antCompileClasspath}" includeantruntime="false"/>
      <target name="dist" depends="compile" description="generate the distribution">
        <!-- Create the distribution directory -->
        <mkdir dir="${dist}"/>
          <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
        <jar jarfile="${dist}/my-app-${version}.jar" basedir="${build}"/>
      <target name="clean" description="clean up">
        <!-- Delete the ${build} and ${dist} directory trees -->
        <delete dir="${build}"/>
        <delete dir="${dist}"/>

The import is before.

Is it therefore safe to say that properties used inside a target are not evaluated immediately, but anything outside a target needs to be set before the import?

It depends on when the property is being actually used when “parsing” the ant XML. It might not be needed until target execution time.