Accessing the buildscript classpath


(cblistserv) #1

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
        }
    }

Figure the classpath of failing tasks from third party plugin
(Hans Dockter) #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 }
}

(detelinyordanov) #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.


(cblistserv) #4

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)
        }
    }
}