Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alessandroscarlatti/6760b619e965943110355b4a7b053f39 to your computer and use it in GitHub Desktop.
Save alessandroscarlatti/6760b619e965943110355b4a7b053f39 to your computer and use it in GitHub Desktop.
H2 Database with H2 Console Gradle Task
spring:
datasource:
url: jdbc:h2:file:./build/datasource;AUTO_SERVER=true
username: sa
password:

H2 Database with H2 Console Gradle Task

Supports concurrent access to database. Database can be accessed at any time via Gradle task.

configurations {
h2
}
configurations.compile.extendsFrom(configurations.h2)
dependencies {
h2 group: 'com.h2database', name: 'h2', version: '1.4.197'
}
task h2Console(type: Exec) {
group = 'application'
description = "run the H2 web console for this application's database"
commandLine 'java', '-jar', configurations.h2.singleFile,
'-url', 'jdbc:h2:file:./build/datasource;AUTO_SERVER=true',
'-user', 'sa'
}
// or without a configuration:
task h2ConsoleWithoutConfiguration(type: Exec) {
group = 'application'
description = "run the H2 web console for this application's database"
def h2Jar = configurations.compile.files.findResult { it.name.startsWith("h2") ? it : null }
commandLine 'java', '-jar', h2Jar,
'-url', 'jdbc:h2:file:./build/datasource;AUTO_SERVER=true',
'-user', 'sa'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment