Hi,
I have been going through Gradle user guide and some online posts about importing ANT script into Gradle so that those ANT targets are available as tasks. But all the examples looks similar and I couldn’t use that in my case.
I would like to download an ANT build script and then import it. Can this be done or does Gradle require the build script to be available during evaluation/configuration phase?
First, I started with Michael Kramer’s download plugin (https://github.com/michel-kraemer/gradle-download-task). Here’s what I have in my build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'de.undercouch:gradle-download-task:3.1.1'
}
}
apply plugin: 'de.undercouch.download'
import de.undercouch.gradle.tasks.download.Download
defaultTasks 'importANTBuild'
// Fetch the build ant file to the file system
task downloadANTBuildFile(type: Download) {
src 'http://mysite.com/path/to/ant/build.xml'
dest new File(buildDir, "build.xml")
}
task importANTBuild(dependsOn: downloadANTBuildFile) {
ant.importBuild(downloadANTBuildFile.dest) { antTaskName ->
"mine-${antTaskName}".toString()
}
// Set group property for all Ant tasks.
tasks.matching { task ->
task.name.startsWith('mine-')
}*.group = 'MY Tasks'
}
The first task can download the xml file successfully. But when I add the 2nd task to the build script, it complains on the following line, because the destination/target xml file does not yet exist.
ant.importBuild
Is it possible to import an ANT build script dynamically?