A sample Gradle task for generating DB documentation using SchemaSpy.
build.gradle
//-----------------------------------------------------------------------------
// Plugins
//-----------------------------------------------------------------------------
plugins {
id 'java'
id 'de.undercouch.download' version '4.0.1'
}
//-----------------------------------------------------------------------------
// Dependency Management
//-----------------------------------------------------------------------------
//Configuration settings
configurations {
//Configuration for JDBC driver
jdbc
}
//Library acquisition repository
repositories {
//JCenter repository
jcenter()
//Maven central repository
mavenCentral()
}
//Dependency settings
dependencies {
//JDBC driver library
jdbc(
'org.mariadb.jdbc:mariadb-java-client:2.5.1'
)
}
//-----------------------------------------------------------------------------
// Tasks
//-----------------------------------------------------------------------------
tasks.register( 'schemaSpy', JavaExec ) {
description = 'Generates database documents.'
group = name
ext.outputDir = file( "${buildDir}/${name}" )
download {
ext.schemaSpyFile = file( "${downloadTaskDir}/${name}/schemaspy.jar" )
src( 'https://github.com/schemaspy/schemaspy/releases/download/v6.1.0/schemaspy-6.1.0.jar' )
dest( schemaSpyFile )
overwrite = false
}
File driverFile = configurations.jdbc.files.first()
main = '-jar'
args = [
schemaSpyFile,
'-t', 'mariadb',
'-dp', driverFile,
'-host', 'localhost',
'-port', '3306',
'-u', 'user',
'-p', 'password',
'-db', 'sample',
'-s', 'sample',
'-o', outputDir
]
doFirst {
outputDir.deleteDir()
}
}
Recommended Posts