Generate DB documentation using SchemaSpy in Gradle

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

Generate DB documentation using SchemaSpy in Gradle
Automatically generate DDL using [jpa-schema-gradle-plugin] plugin in Spring × Gradle
Automatically generate jpa entity using Gradle
ERRORCODE = -4471 occurs in Java application using Db2.
Resolve "Cannot resolve symbol" in IntelliJ projects using Gradle
[Note] Struts2 environment construction using Gradle in Eclipse
DB access using Exposed
Jigsaw notes in Gradle
You are currently using Java 6. Solution in Android Studio Gradle
Dependency management in Gradle using Maven repository on Amazon S3
Generate a single executable jar with dependent libraries in Gradle 4.9