When importing an ant build file in to build.gradle, do I have to redefine the dependencies in Gradle's way?

Hi guys, I’m just getting started with Gradle, so apologies if my question is a bit basic. I’m working on a task of migrating our build system to Gradle from Ant. I want to take it incrementally so I’ll always have a gradle build working. This was one of the main reasons why we chose Gradle over Maven among others.

To begin with, I created a simple build.gradle file with just this line:

# build.gradle:
ant.importBuild 'build.xml'

But when I tried running one of the simple targets in build.xml via gradle, I got this error:

$ gradle clean
[ant:taskdef] Could not load definitions from resource net/sf/antcontrib/antcontrib.properties. It could not be found.
[ant:taskdef] Could not load definitions from resource net/sf/antcontrib/antcontrib.properties. It could not be found.
[ant:taskdef] Could not load definitions from resource org/jacoco/ant/antlib.xml. It could not be found.
:clean
  BUILD SUCCESSFUL
  Total time: 4.145 secs

The ant target “clean” is actually imported in to ‘build.xml’ from another build file called ‘build_helper.xml’, so this tells me nested importing went well, otherwise Gradle wouldn’t have been able to invoke this target. But it couldn’t find antcontrib.properties and antlib.xml which are in my ‘$ANT_HOME/lib’.

This brings the question whether the dependencies have to be mentioned in build.gradle file. Or did it not work here because the jar files of these tasks are outside of the project directory? If it’s the later case, is there a way to tell Gradle to add ‘$ANT_HOME/lib’ to the classpath?

Gradle uses it’s own embedded version of ant so it won’t use your custom install with extra jars in $ANT_HOME/lib

Here’s two solutions: 1. Add to ant’s classpath (build.gradle) http://stackoverflow.com/questions/10220099/classpath-for-ant-plugins-when-using-antbuilder-from-gradle 2. Specify a classpath in the taskdef (build.xml) http://stackoverflow.com/questions/4511129/classpath-for-taskdef

Thanks, Lance. I went with the first workaround.

// build.gradle:
repositories {
    mavenCentral()
}
    configurations {
    antconf
}
    dependencies {
    antconf 'ant-contrib:ant-contrib:1.0b3'
}
    ClassLoader antClassLoader = org.apache.tools.ant.Project.class.classLoader
        configurations.antconf.each { File f ->
            antClassLoader.addURL(f.toURI().toURL())
        }
ant.importBuild 'build.xml'