Reputation: 11
I have a library built with Ant, which uses Ivy for dependency management. Feel free to see repo branch.
I would like to make the library a gradle project, and wrap the Ant build in a gradle build task. This is mostly straightforward, but I encounter an issue with resolving the Ivy jar in the classpath, which I'm unsure of how to resolve.
(The ant build succeeds when running with ant
cli directly, only seeing issues when invoking from Gradle)
I created a build.gradle.kts
file to run the ant compile
task:
//rename ant targets to avoid collisions with Gradle task names
ant.importBuild("build.xml") { antTargetName ->
"ant-" + antTargetName
}
tasks.register("antCompile") {
group = "build"
doLast {
ant.project.executeTarget("compile")
}
}
Now, when I run
./gradlew antCompile
I get this error:
This build requires Ivy and Ivy could not be found in your ant classpath.
...
You can either manually install a copy of Ivy 2.4.0 in your ant classpath:
http://ant.apache.org/manual/install.html#optionalTasks
...
Or this build file can do it for you by running the Ivy Bootstrap target:
ant ivy-bootstrap
As suggested here, I can add an ivy-bootstrap task to run before antCompile
in gradle:
tasks.register("setupAntIvy") {
doLast {
ant.project.executeTarget("ivy-bootstrap")
}
}
tasks.register("antCompile") {
group = "build"
dependsOn("setupAntIvy")
doLast {
ant.project.executeTarget("compile")
}
}
Now, if I try to antCompile
, the setupAntIvy
task succeeds:
installing ivy 2.4.0 to /Users/jasha/.ant/lib
But, antCompile
still fails with the original error, making me think that the classpath for the gradle task is different than for just Ant. Ant docs suggest a couple of other ways to add Ivy to the classpath, but none resolve the error.
My key questions: How do I figure out the classpath where an Ivy jar file needs to live to execute antCompile
in gradle?
Upvotes: 0
Views: 19