From ae59ef6ee2d92cf1fd05993569ecfb8547387e2e Mon Sep 17 00:00:00 2001 From: vince Date: Mon, 22 Jul 2024 18:15:03 +0800 Subject: [PATCH] refactor dokka script --- build.gradle.kts | 24 +-------------- buildSrc/build.gradle.kts | 2 ++ .../src/main/kotlin/ktorm.dokka.gradle.kts | 29 +++++++++++++++++++ .../src/main/kotlin/ktorm.publish.gradle.kts | 5 +++- .../kotlin/ktorm.tuples-codegen.gradle.kts | 4 +++ ktorm-jackson/ktorm-jackson.gradle.kts | 3 ++ 6 files changed, 43 insertions(+), 24 deletions(-) create mode 100644 buildSrc/src/main/kotlin/ktorm.dokka.gradle.kts diff --git a/build.gradle.kts b/build.gradle.kts index 74449124..d9cc9452 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,32 +3,10 @@ group = "org.ktorm" version = file("ktorm.version").readLines()[0] plugins { - id("org.jetbrains.dokka") version "1.9.20" + id("ktorm.dokka") } repositories { mavenCentral() gradlePluginPortal() } - -tasks.dokkaHtmlMultiModule { - val templatesDir = System.getenv("DOKKA_TEMPLATES_DIR") - if (!templatesDir.isNullOrEmpty()) { - pluginsMapConfiguration.set(mapOf("org.jetbrains.dokka.base.DokkaBase" to """{"templatesDir": "$templatesDir"}""")) - } -} - -subprojects { - apply(plugin = "org.jetbrains.dokka") - - tasks.named("dokkaHtmlPartial") { - dokkaSourceSets.named("main") { - suppressGeneratedFiles.set(false) - sourceLink { - localDirectory.set(file("src/main/kotlin")) - remoteUrl.set(java.net.URL("https://github.com/kotlin-orm/ktorm/blob/master/${project.name}/src/main/kotlin")) - remoteLineSuffix.set("#L") - } - } - } -} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 449f27dd..89340f07 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -10,6 +10,8 @@ repositories { dependencies { api("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23") + api("org.jetbrains.dokka:dokka-gradle-plugin:1.9.20") + api("org.jetbrains.dokka:dokka-base:1.9.20") api("org.moditect:moditect:1.0.0.RC1") api("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.6") } diff --git a/buildSrc/src/main/kotlin/ktorm.dokka.gradle.kts b/buildSrc/src/main/kotlin/ktorm.dokka.gradle.kts new file mode 100644 index 00000000..077d00a1 --- /dev/null +++ b/buildSrc/src/main/kotlin/ktorm.dokka.gradle.kts @@ -0,0 +1,29 @@ +import gradle.kotlin.dsl.accessors._f5007bc516eebc049270414be01b92ac.dokkaJavadoc + +plugins { + id("org.jetbrains.dokka") +} + +tasks.named("dokkaHtmlMultiModule") { + val tmplDir = System.getenv("DOKKA_TEMPLATES_DIR") + if (!tmplDir.isNullOrEmpty()) { + pluginConfiguration { + templatesDir = File(tmplDir) + } + } +} + +subprojects { + apply(plugin = "org.jetbrains.dokka") + + tasks.named("dokkaHtmlPartial") { + dokkaSourceSets.named("main") { + suppressGeneratedFiles.set(false) + sourceLink { + localDirectory.set(file("src/main/kotlin")) + remoteUrl.set(java.net.URL("https://github.com/kotlin-orm/ktorm/blob/master/${project.name}/src/main/kotlin")) + remoteLineSuffix.set("#L") + } + } + } +} diff --git a/buildSrc/src/main/kotlin/ktorm.publish.gradle.kts b/buildSrc/src/main/kotlin/ktorm.publish.gradle.kts index 1f40f5e2..ac45f1fc 100644 --- a/buildSrc/src/main/kotlin/ktorm.publish.gradle.kts +++ b/buildSrc/src/main/kotlin/ktorm.publish.gradle.kts @@ -3,14 +3,17 @@ plugins { id("kotlin") id("signing") id("maven-publish") + id("org.jetbrains.dokka") } val jarSources by tasks.registering(Jar::class) { - archiveClassifier.set("sources") from(sourceSets.main.map { it.allSource }) + archiveClassifier.set("sources") } val jarJavadoc by tasks.registering(Jar::class) { + dependsOn(tasks.dokkaJavadoc) + from(tasks.dokkaJavadoc.flatMap { it.outputDirectory }) archiveClassifier.set("javadoc") } diff --git a/buildSrc/src/main/kotlin/ktorm.tuples-codegen.gradle.kts b/buildSrc/src/main/kotlin/ktorm.tuples-codegen.gradle.kts index 0ab69909..ab89460f 100644 --- a/buildSrc/src/main/kotlin/ktorm.tuples-codegen.gradle.kts +++ b/buildSrc/src/main/kotlin/ktorm.tuples-codegen.gradle.kts @@ -1,6 +1,7 @@ plugins { id("kotlin") + id("org.jetbrains.dokka") } val generatedSourceDir = "${project.layout.buildDirectory.asFile.get()}/generated/source/main/kotlin" @@ -354,6 +355,9 @@ tasks { "jarSources" { dependsOn(generateTuples) } + dokkaJavadoc { + dependsOn(generateTuples) + } } sourceSets.main { diff --git a/ktorm-jackson/ktorm-jackson.gradle.kts b/ktorm-jackson/ktorm-jackson.gradle.kts index 7827835c..5c4c36d0 100644 --- a/ktorm-jackson/ktorm-jackson.gradle.kts +++ b/ktorm-jackson/ktorm-jackson.gradle.kts @@ -29,6 +29,9 @@ tasks { "jarSources" { dependsOn(generatePackageVersion) } + dokkaJavadoc { + dependsOn(generatePackageVersion) + } } sourceSets.main {