From 0f4fa802b43000d06b3ee6ca93c01139f7cac508 Mon Sep 17 00:00:00 2001 From: Jared Rummler Date: Sat, 20 Apr 2024 10:54:26 -0700 Subject: [PATCH] Move dokka task from root build script to core/build.gradle.kts --- build.gradle.kts | 39 +++++-------------------- buildSrc/src/main/kotlin/BuildConfig.kt | 11 +++++-- core/build.gradle.kts | 23 +++++++++++++++ 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index f323bfa..5828a8c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -24,7 +24,6 @@ plugins { alias(libs.plugins.android.library).apply(false) alias(libs.plugins.kotlin.multiplatform).apply(false) alias(libs.plugins.detekt) - alias(libs.plugins.dokka) } allprojects { @@ -38,10 +37,15 @@ dependencies { detekt { buildUponDefaultConfig = true - config.setFrom(BuildConfig.DETEKT_CONFIG) + config.setFrom(BuildConfig.Detekt.CONFIG) +} + +tasks.withType().configureEach { + jvmTarget = BuildConfig.Detekt.jvmTarget } tasks.withType().configureEach { + jvmTarget = BuildConfig.Detekt.jvmTarget reports { html.required.set(true) md.required.set(true) @@ -51,41 +55,12 @@ tasks.withType().configureEach { } } -tasks.withType().configureEach { - jvmTarget = BuildConfig.Dokka.jvmTarget -} - -tasks.withType().configureEach { - jvmTarget = BuildConfig.Dokka.jvmTarget -} - val detektAll by tasks.registering(Detekt::class) { description = "Run detekt analysis on entire project" parallel = true buildUponDefaultConfig = true - config.setFrom(BuildConfig.DETEKT_CONFIG) + config.setFrom(BuildConfig.Detekt.CONFIG) setSource(files(projectDir)) include("**/*.kt", "**/*.kts") exclude("resources/", "*/build/*") } - -tasks.dokkaHtml { - outputDirectory.set(BuildConfig.Dokka.outputDirectory) - dokkaSourceSets { - configureEach { - noStdlibLink.set(false) - noJdkLink.set(false) - externalDocumentationLink { - url.set(java.net.URL(BuildConfig.Dokka.DOC_LINK)) - packageListUrl.set(java.net.URL(BuildConfig.Dokka.PKG_LIST)) - } - displayName.set( - when (val name = displayName.get() ?: name) { - "jvm" -> "JVM" - "js" -> "JavaScript" - else -> name.capitalize() - } - ) - } - } -} diff --git a/buildSrc/src/main/kotlin/BuildConfig.kt b/buildSrc/src/main/kotlin/BuildConfig.kt index 06f1e79..6c232dc 100644 --- a/buildSrc/src/main/kotlin/BuildConfig.kt +++ b/buildSrc/src/main/kotlin/BuildConfig.kt @@ -33,8 +33,6 @@ object BuildConfig { const val GROUP = "io.goatbytes.kmmify" val VERSION by lazy { Version.get(project) } - val DETEKT_CONFIG by lazy { "${project.rootDir}/detekt.yml" } - /** * Version Update Instructions: * @@ -104,6 +102,14 @@ object BuildConfig { const val FRAMEWORK_NAME = NAME } + /** + * Contains configuration for Detekt static analysis plugin. + */ + object Detekt { + val CONFIG by lazy { "${project.rootDir}/detekt.yml" } + val jvmTarget = JavaVersion.VERSION_1_8.toString() + } + /** * Contains constants for Dokka */ @@ -111,7 +117,6 @@ object BuildConfig { const val DOC_LINK = "https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/" const val PKG_LIST = "https://kotlin.github.io/kotlinx.coroutines/package-list" val outputDirectory: File get() = project.file("${project.rootDir}/docs/docs") - val jvmTarget = JavaVersion.VERSION_1_8.toString() } /** diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 5756b88..9048881 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -17,10 +17,12 @@ import build.Os import org.jetbrains.kotlin.gradle.dsl.JsModuleKind +import java.net.URL plugins { alias(libs.plugins.kotlin.multiplatform) alias(libs.plugins.android.library) + alias(libs.plugins.dokka) id("publication.gh-packages") } @@ -122,3 +124,24 @@ android { minSdk = BuildConfig.Android.MIN_SDK } } + +tasks.dokkaHtml { + outputDirectory.set(BuildConfig.Dokka.outputDirectory) + dokkaSourceSets { + configureEach { + noStdlibLink.set(false) + noJdkLink.set(false) + externalDocumentationLink { + url.set(URL(BuildConfig.Dokka.DOC_LINK)) + packageListUrl.set(URL(BuildConfig.Dokka.PKG_LIST)) + } + displayName.set( + when (val name = displayName.get() ?: name) { + "jvm" -> "JVM" + "js" -> "JavaScript" + else -> name.capitalize() + } + ) + } + } +}