LoginSignup
2
1

More than 1 year has passed since last update.

Gradle で SchemaSpy を使用して DB のドキュメントを生成

Last updated at Posted at 2019-01-18

SchemaSpy を使用して DB のドキュメントを生成するための Gradle のタスクのサンプルです。
※ 以下は MySQL 使用時の例

build.gradle.kts
//-----------------------------------------------------------------------------
//    Plugins
//-----------------------------------------------------------------------------
plugins {
    java
    id("de.undercouch.download") version "5.1.0"
}

//-----------------------------------------------------------------------------
//    Dependency Management
//-----------------------------------------------------------------------------
// コンフィギュレーションの設定
// JDBC ドライバのためのコンフィギュレーション
val jdbc by configurations.creating

// ライブラリ取得先リポジトリ
repositories {
    // Maven セントラルリポジトリ
    mavenCentral()
}

// 依存関係の設定
dependencies {
    // JDBC ドライバのライブラリ
    jdbc("org.mariadb.jdbc:mariadb-java-client:3.0.4")
}

//-----------------------------------------------------------------------------
//    Tasks
//-----------------------------------------------------------------------------
// SchemaSpy のタスク
val schemaSpy by tasks.registering(JavaExec::class) {
    dependsOn(schemaSpyDownload)

    description = "Generates database documents."
    group = name

    val outputDir by extra(layout.buildDirectory.dir(name).get())
    val driverFile = jdbc.files.first()

    classpath = layout.files(schemaSpyDownload.get().outputFiles)

    args("-t", "mariadb")
    args("-dp", driverFile)
    args("-host", "localhost")
    args("-port", "3306")
    args("-u", "user")
    args("-p", "password")
    args("-db", "sample")
    args("-s", "sample")
    args("-o", outputDir)

    doFirst {
        delete(outputDir)
    }
}

// SchemaSpy のヘルプを表示するタスク
val schemaSpyHelp by tasks.registering(JavaExec::class) {
    dependsOn(schemaSpyDownload)

    description = "Displays the help about SchemaSpy."
    group = schemaSpy.get().group

    classpath = layout.files(schemaSpyDownload.get().outputFiles)

    args("-h")
}

// SchemaSpy のデータベースに関するヘルプを表示するタスク
val schemaSpyDatabaseHelp by tasks.registering(JavaExec::class) {
    dependsOn(schemaSpyDownload)

    description = "Displays the help about databases of SchemaSpy."
    group = schemaSpy.get().group

    classpath = layout.files(schemaSpyDownload.get().outputFiles)

    args("-dbHelp")
}

// SchemaSpy のファイルをダウンロードするタスク
val schemaSpyDownload by tasks.registering(Download::class) {
    description = "Downloads SchemaSpy file."

    src(uri("https://github.com/schemaspy/schemaspy/releases/download/v6.1.0/schemaspy-6.1.0.jar").toURL())
    dest(layout.projectDirectory.dir("${downloadTaskDir}/${name}"))
    overwrite(false)
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1