Hello, I just started to learn about Gradle and I’m currently playing around a little. The first thing I’m interested in is the Ant integration, so I wrote an Ant script that compiles a custom Ant task and then uses this task. Then I wanted to use the Ant tasks from Gradle. Unfortunately, while this works perfectly in Ant, it does not work when I want to use these Ant tasks with Gradle. Instead, I get “package org.apache.tools.ant does not exist” and “cannot find symbol: class Task”. Since Gradle fully integrates Ant, I thought that this should work out of the box but it seems like Gradle does not include the Ant Jar file from its lib directory. Can anyone explain to me, why there is a difference between Ant and Gradle here and how I can get this to work? Here is my code:
The custom Ant task:
package example.ant.tasks;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
public class MyAntTask extends Task
{
public MyAntTask()
{
}
public void execute() throws BuildException
{
log("*******MyAntTask*********");
}
}
The Ant build script:
<project name="ant-example" default="useTask" basedir=".">
<target name="compileTask">
<mkdir dir="../src/MyAntTask/bin"/>
<javac destdir="../src/MyAntTask/bin">
<src path="../src/MyAntTask/src"/>
</javac>
</target>
<target name="useTask" depends="compileTask">
<taskdef name = "myAntTask" classname = "example.ant.tasks.MyAntTask" classpath= "../src/MyAntTask/bin"/>
<myAntTask/>
</target>
<target name="clean">
<delete dir="../src/MyAntTask/bin"/>
</target>
</project>
The Gradle build script
ant.importBuild 'build.xml'