Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to provide Gradle dependencies for Ant build

Tags:

gradle

groovy

ant

I'm trying to migrate from ant to gradle. First phase of this is to move all dependecies to gradle.build and still build war via ant.

To import ant builds I'm using this code:

ant.importBuild('build.xml') { antTargetName ->
    'ant_' + antTargetName
}

To copy all dependencies from gradle to ant I'm trying to use this:

task copyDependenciesForAnt() {
    def antLibsPath = ant."tmp.build.dir" + "/" + ant."project.libs.folder"
    configurations.compile.each { Files.copy(Paths.get(it), Paths.get(antLibsPath)) }
}
ant_war.mustRunAfter copyDependenciesForAnt

With this code I have problem because i don't know how to use Files.copy here. Also there is probably easier way to achieve this in gradle, but I don't know how.

like image 978
MAGx2 Avatar asked Nov 28 '25 12:11

MAGx2


1 Answers

You can define a copy task in Gradle, as follows:

task copyDependenciesForAnt(type: Copy) {
    from configurations.compile
    into ant."tmp.build.dir" + "/" + ant."project.libs.folder"
}

ant_war.dependsOn copyDependenciesForAnt

Also, I suggest using dependsOn rather than mustRunAfter for task dependency wiring which ensures correct execution order.

like image 199
Invisible Arrow Avatar answered Nov 30 '25 04:11

Invisible Arrow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!