I tried using using following syntax:
task test << {
gradle.class.classLoader.addURL(new File(‘SQL/ojdbc6.jar’).toURI().toURL())
def sql = groovy.sql.Sql.newInstance(JDBCURL, DB_PROP_SCHEMA, DB_PROP_PASSWORD, ‘oracle.jdbc.driver.OracleDriver’)
String sqlFilePath = “testsql.sql”
String sqlString = new File(sqlFilePath).text
sql.execute(sqlString)
sql.close()
}
st_oehme
(Stefan Oehme)
March 18, 2016, 8:25pm
2
What you are trying to do is modifying the builscript classpath:
buildscript {
dependencies {
classpath files('SQL/ojdbc6.jar')
}
}
Two other approaches:
via buildscript:
buildscript {
dependencies {
classpath("net.sourceforge.jtds:jtds:1.3.1")
}
}
// Configure the classloader to contain JTDS driver (i.e., first jar starting with jtds)
gradle.class.classLoader.addURL(buildscript.configurations.classpath.find { it.name.startsWith('jtds') }.toURI().toURL())
via configuration:
configurations {
driver
}
dependencies {
driver "com.h2database:h2:1.3.171"
}
configurations.driver.each {File file ->
gradle.class.classLoader.addURL(file.toURI().toURL())
}
** Updated to use Gradle classloader
st_oehme
(Stefan Oehme)
March 24, 2016, 4:40pm
4
Nathan_Niesen:
Two other approaches:
You shouldn’t do either of those, the Groovy classloader is an implementation detail that can break at any point.