Error migrating Oracle Ant build to Gradle


(Sion Williams) #1

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'
  ant.properties."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="soa.oracle.home" 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.">
    <condition>
      <not><available file="${common.components.home}" type="dir"/></not>
    </condition>
  </fail>
    <property name="common.components.modules" value="${common.components.home}/modules"/>
    <property name="soa.modules" value="${soa.oracle.home}/soa/modules"/>
    <condition property="oracle.soa.mgmt.home"
             value="${common.components.home}"
             else="${oracle.home}">
    <available file="${common.components.home}/soa/modules/oracle.soa.mgmt_11.1.1/soa-infra-mgmt.jar"/>
  </condition>
</project>

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$importBuild.call(Unknown Source)
        at build_38ucqn8eb28c7dgbrrac1ppa65.run(C:\path\to\Scripts\Gradle\import_ant_sca\build.gradle:1)
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
        ... 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 org.apache.tools.ant.taskdefs.Exit.execute(Exit.java:164)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:435)
        at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:179)
        at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:93)
        at org.apache.tools.ant.ProjectHelper$configureProject.call(Unknown Source)
        at org.gradle.api.internal.project.DefaultAntBuilder.importBuild(DefaultAntBuilder.groovy:76)

(Peter Niederwieser) #2

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


(Sion Williams) #3

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 '${ant.properties.build}'."
    }
      doLast {
        logger.quiet "Starting from a clean slate."
    }
}
  ext.antBuildDir = '../ant/build'
ant.properties.build = "$antBuildDir/classes"
ant.properties.dist = "$antBuildDir/libs"
  task sourcesJar(type: Jar) {
    baseName = 'my-app'
    classifier = 'sources'
    version = ant.properties.version
    destinationDir = file(ant.properties.dist)
    from new File(ant.properties.src, 'main/java')
}
  dist.dependsOn sourcesJar
  compile {
    inputs.dir file(ant.properties.src)
    outputs.dir file(ant.properties.build)
}
  task downloadReleaseDocumentation << {
    logging.level = LogLevel.INFO
    ext.repoUrl = 'https://repository-gradle-in-action.forge.cloudbees.com/release'
      ant.get(dest: ant.properties.build) {
        url(url: "$repoUrl/files/README.txt")
        url(url: "$repoUrl/files/RELEASE_NOTES.txt")
    }
}
  dist.dependsOn downloadReleaseDocumentation
  configurations {
    antCompile
}
  repositories {
    mavenCentral()
}
  dependencies {
    antCompile 'org.apache.commons:commons-lang3:3.1'
}
  ant.properties.antCompileClasspath = 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>
      <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>
      <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>
      <target name="clean" description="clean up">
        <!-- Delete the ${build} and ${dist} directory trees -->
        <delete dir="${build}"/>
        <delete dir="${dist}"/>
    </target>
</project>

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?


(Luke Daley) #4

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