How do I load the Oracle driver from the local file system?

How do I load the Oracle driver from the local file system? This should be simple, but gradle is turning this into a multi-hour task.

The following doesn’t work because it doesn’t know find the ojdbc-14.jar file in the lib/ directory:

repositories {

flatDir name: ‘localRepository’, dirs: ‘lib’ }

configurations {

driver }

task loadOracle() << {

URLClassLoader loader = GroovyObject.class.classLoader

configurations.driver.each {File file ->


println file.toURL()


//Class driverClass = loader.loadClass(‘oracle.jdbc.OracleDriver’)


java.sql.Driver driverInstance = driverClass.newInstance()



Sql sql = Sql.newInstance(‘jdbc-url’,‘username’,‘password’) }

1 Like

It should be like this

buildscript {
  dependencies {
    classpath files('lib/ojdbc-14.jar')

See my answer on Stack Overflow. Please don’t double-post.

The example code looked like he wanted to use the sql driver from within the build script (didn’t mentioned that it was for jetty)…

Could be an alternative.

With this line, it works for me.

dependencies {
 runtimeWithoutCompile fileTree(dir: 'lib', include: '*.jar')