Classloader issue when using jdbc driver in task in buildSrc


(Marcel Overdijk) #1

I’m trying to create a database in a custom task defined in buildSrc.
Although the driver seems on the classpath, when performing Class.forName("org.h2.Driver"); I get a ‘No suitable driver found’.
When creating the Driver class manually via Driver driver = new Driver(); it just creates the instance.

I’ve set up an example at https://github.com/marceloverdijk/test-jdbc-in-buildsrc just run ./gradlew clean createDatabase to reproduce the issue.


(Marcel Overdijk) #2

I solved it by using:

groovy.sql.Sql.loadDriver("org.h2.Driver")

instead of:

Class.forName("org.h2.Driver")