java - How to connect to MySQL from script in Gradle -
i want connect mysql through build.gradle
not want pick driver specified folder below commented line //loader.addurl(file(jdbc_archive_path).tourl())
. want pick driver dependencies specified in build.gradle dependencies { compile 'mysql:mysql-connector-java:5.1.37' }
how can that?
task loaddriver { urlclassloader loader = groovyobject.class.classloader //loader.addurl(file(jdbc_archive_path).tourl()) java.sql.drivermanager.registerdriver(loader.loadclass(analyticsdriverclassname).newinstance()) } // connect database // task expects following properties: // * analyticsdburl // * analyticsdbusername // * analyticsdbpassword task calldatabase() { println "connecting database '$analyticsdburl' user '$analyticsdbusername' ..." def sql = groovy.sql.sql.newinstance(analyticsdburl, analyticsdbusername, analyticsdbpassword) println '... connected' }
import com.mysql.jdbc.driver buildscript{ repositories{ jcenter() } dependencies{ // dependencies classes want use in buildscript go here classpath 'mysql:mysql-connector-java:5.1.37' } } task something()<<{ driver driver = new driver() }
Comments
Post a Comment