This was actually very helpfull and solved my problem. Thank you =)
The Code:
import groovy.sql.Sql
defaultTasks 'connectToDb'
repositories {
flatDir name: 'localRepository', dirs: 'lib'
}
configurations {
driver
}
dependencies {
driver group: 'sql', name: 'sqljdbc4'
}
URLClassLoader loader = GroovyObject.class.classLoader
configurations.driver.each {File file ->
loader.addURL(file.toURL())
}
task connectToDb << {
def props = [user: 'sa', password: 'pw', allowMultiQueries: 'true'] as Properties
def url = 'jdbc:sqlserver://testserver;databaseName=testDB'
def driver = 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
def sql = Sql.newInstance(url, props, driver)
//do stuff
sql.close()
}