Last active
May 7, 2018 20:05
-
-
Save mlapierre/5185bf9e3742a7f63fab03e5b7f55be1 to your computer and use it in GitHub Desktop.
Gradle: Add MSSQL JDBC drivers to the buildscript and groovy.sql.Sql classpath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.sql.Sql | |
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath 'com.microsoft.sqlserver:mssql-jdbc:6.4.0.jre8' | |
} | |
configurations.classpath.each { Sql.classLoader.addURL it.toURI().toURL() } | |
} | |
task somethingWithMSSQL() { | |
def dbHost = "host" | |
def dbPort = "1433" | |
def dbUsername = "username" | |
def dbPassword = "password" | |
def dbName = "database" | |
def dbDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver" | |
def jdbcUrl = "jdbc:sqlserver://$dbHost:$dbPort;databaseName=$dbName" | |
def sql = Sql.newInstance(jdbcUrl, dbUsername, dbPassword, dbDriver) | |
// do something with MSSQL | |
sql.close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment