Skip to content

Instantly share code, notes, and snippets.

@mlapierre
Last active May 7, 2018 20:05
Show Gist options
  • Save mlapierre/5185bf9e3742a7f63fab03e5b7f55be1 to your computer and use it in GitHub Desktop.
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
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