Ant task imported from build.xml in Gradle script is running automatically
I have this Java project there I import an Ant build.xml file with some tasks, like this:
ant.importBuild 'build.xml'
task myTaskA(dependsOn: ':Modules:MyModule:assemble') << {
// do stuff here...
}
compileJava.dependsOn(myTaskA)
configure(jar) {
include 'classes.dex'
}
jar.dependsOn(antCompile)
The task antCompile
comes from the Ant build.xml script. However, for some reason, this task is being called at start up when invoke gradlew assemble
, it doesn't even wait for the jar
task to start.
Also, the antCompile
task is defined as the following target in build.xml:
<target name="antCompile" depends="-setup">
</target>
That Ant target, -compile
is always the first task to be executed when I invoke gradlew assemble
. This doesn't make any sense. That task is never invoked anywhere, it's only a dependency of antCompile
. Why is it being executed?
This is, obviously, not what I want... How can I prevent such behaviors?
Seems to work as expected. The build script makes jar
depend on antCompile
, which according to your words depends on -compile
. assemble
depends on jar
, so executing gradle assembmle
should run -compile
first.
In any case, it should be said that ant.importBuild
has known limitations, and can result in differences in behavior compared to running the Ant build directly. Also you'll lose many of Gradle's advantages when not describing the build in terms of Gradle's own abstractions. Therefore I recommend to port the build to Gradle, rather than using ant.importBuild
(which isn't used that often in the real world). Note that it's perfectly fine to reuse Ant tasks in cases where Gradle doesn't provide any equivalent.