MAGx2
MAGx2

Reputation: 3189

How to provide Gradle dependencies for Ant build

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.

Upvotes: 3

Views: 1851

Answers (1)

Invisible Arrow
Invisible Arrow

Reputation: 4905

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.

Upvotes: 3

Related Questions