Classpath problem using SQL in Gradle Task


(Kyle) #1

I have a script called ‘utilities.gradle’ that I include at the end of my build.gradle file using:
apply from: ‘utilities.gradle’

When executing the utilties.wipe task I’m getting:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test?allowMultiQueries=true

utilities.gradle
buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'mysql:mysql-connector-java:5.1.35'
    }
}

import groovy.sql.Sql
import com.mysql.jdbc.Driver

task wipe {
	group 'Utilities'
	description 'Deletes all record data from the development database'
	
	doLast {
		def url = 'jdbc:mysql://localhost:3306/test?allowMultiQueries=true'
		def user = 'test'
		def password = 'password'
		def driver = 'com.mysql.jdbc.Driver'
		
		Class.forName(driver)
		
		print 'wiping local database... '
		Sql.withInstance(url, user, password, driver) { sql ->
			sql.execute '''
				delete from test_data;
				delete from test_data2;
			'''
		}
		println 'done!'
		
		println 'wipe completed successfully'
	}
}

Any insight into what I’m doing wrong is greatly appreciated!

Edit: I am using Gradle 4.8.1.