Build script doesn't include libs at runtime, only at configuration time

gradle dont use classpath dependencies in runtime

when add dependencies to buildscript they can be used inside of tasks at compile time, but not when I ran the tasks at runtime

buildscript {
    repositories {
        maven {
            url ""
      dependencies {
        classpath 'net.sourceforge.jtds:jtds:1.2.4'
        classpath 'org.codehaus.groovy:groovy-all:2.1.2'
  import groovy.sql.Sql
task myTask << {
    Sql sql = Sql.newInstance('someUrl', 'someuser', 'somepass', 'jdbc:jtds:sqlserver://localhost/db')

the task passes stage 1, but when executed doesn’t find driver class

so that some scenarios like: 1) task which connects to db - doesnt find driver class (dependency is in classpath) 2) task with custom logj4 and doesn’t see appenders, cause is not in classpath

The case above is a known problem with JDBC class loading and Groovy. One solution is to implement the task as a Java class (e.g. in ‘buildSrc/src/main/java’). For other workarounds, search the forums and/or Stack Overflow (this has been asked before).