berry_burr
berry_burr

Reputation: 351

Run Ant target within Gradle task

I am pretty new in using Gradle, and I have some troubles. I'm trying to import ant script into gradle and then run some ant targets. Then I cal gradle task in Jenkins.

So far what I have:

task MyAnt<< {
    ant.importBuild 'build.xml'
    def antTargetsNames = ant.references.get("ant.targets").collect { it.name }
    println "\nAnt Targets: ${antTargetsNames}\n" 
    call Ant traget, e.g. compileAnt
}

Basically I print all targets now, but I do not know how to call ant target within gradle task. Is it possible to do?

Upvotes: 5

Views: 8127

Answers (1)

Peter Niederwieser
Peter Niederwieser

Reputation: 123996

ant.importBuild 'build.xml' has to happen outside the task action. The result is that you'll get a Gradle task for each Ant target, which can be executed from the command line. Tasks can't execute other tasks but can depend on them (e.g. myTask.dependsOn(someAntTarget), again outside a task action. For more information, check the Gradle User Guide and the samples in the gradle-all distribution.

Upvotes: 6

Related Questions