Per the documentation it is possible to configure a classpath for the script itself http://www.gradle.org/current/docs/userguide/userguide_single.html#sec:external_dependencies
I am wondering if this classpath can be accessed programmatically and passed to an Ant taskdef definition.
i.e. :
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.liquibase', name: 'liquibase-core', version: '1.9.5'
}
}
ant.taskdef(resource: 'liquibasetasks.properties') {
classpath {
// somehow get the above liquibase jar on the classpath here
}
}
hansd
(Hans Dockter)
October 6, 2011, 6:43pm
2
You would not need the buildscript section for this scenario, as you just need it for the ant classpath and not the build script classpath. Have a look at example 17.7 in the user’s guide of how we would do it: http://gradle.org/releases/1.0-milestone-3/docs/userguide/ant.html#N112E8
Nonetheless, you can access the build script dependencies:
task show << {
buildscript.configurations.classpath.each { println it }
}
Detelin
(detelinyordanov)
October 6, 2011, 6:54pm
3
Since buildscript.configurations.classpath is an instance of FileCollection, you could try with FileCollection#addToAntBuilder . I’ve just seen this in the javadocs, but have not tried it myself.
Thanks guys, that helped me figure things out.
Hans, my thinking here is that Ant dependencies are morally equivalent to build script dependencies.
So I would like to define and access those the same way, separate from the module dependencies.
Does that make sense or can you think of a preferable way?
def liquibaseTaskdef() {
ant.taskdef(resource: 'liquibasetasks.properties') {
classpath {
pathElement(location: buildscript.configurations.classpath.asPath)
}
}
}