Gradle plugin for running SQL scripts.
There's a good FAQ - you may find some answers over there.
Firstly, you'll need to include the plugin in your build script:
For Groovy-based DSL:
plugins {
id "com.nocwriter.runsql" version "1.0"
}
For Kotlin-based DSL:
plugins {
id("com.nocwriter.runsql") version ("1.0")
}
Next, you'll need to create a custom task:
For Groovy-based DSL:
task createTable(type: RunSQL) {
config {
username = "..."
password = "..."
url = "..."
driverClassName = "..."
scriptFile = "/db/createTable.sql"
}
}
For Kotlin-based DSL:
task<RunSQL>("createTable") {
config {
username = "..."
password = "..."
url = "..."
driverClassName = "..."
scriptFile = "/db/createTable.sql"
}
}
Then simple run:
gradle :createTable
You can provide either a single script file or multiple scripts via 'scriptFile' properties:
task<RunSQL>("createTable") {
config {
username = "..."
password = "..."
url = "..."
driverClassName = "..."
scriptFile = arrayOf("/db/createTable.sql", "/db/populateDate.sql")
}
}
You can also provide a direct script, without an external files, e.g.:
task<RunSQL>("createTable") {
config {
username = "..."
password = "..."
url = "..."
driverClassName = "..."
// Use of 'script' instead of 'scriptFile':
script = "CREATE TABLE books (" +
" name VARCHAR(100)," +
" author VARCHAR(100)" +
");
}
}
You cannot use both.
driverClassName property is optional. The plugin will attempt to detect the matching driver class name. As of now, it supports the following: PostgreSQL, MySQL, Oracle, DB2, Sybase, HSQLDB, H2, SQLite and Derby.
The plugin requires Java 8 and above and Gradle 5.4 or above.
This plugin is licensed under Apache License V2.0.
If you'd like to contribute, ask questions or request for new features, you should open the New issues page and leave a message over there (with E-mail to contact you back).
I don't publish my E-mail address directly, as bots tend to abuse it.