Skip to content

Commit

Permalink
Move dokka task from root build script to core/build.gradle.kts
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredrummler committed Apr 20, 2024
1 parent f40abbf commit 0f4fa80
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 35 deletions.
39 changes: 7 additions & 32 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -38,10 +37,15 @@ dependencies {

detekt {
buildUponDefaultConfig = true
config.setFrom(BuildConfig.DETEKT_CONFIG)
config.setFrom(BuildConfig.Detekt.CONFIG)
}

tasks.withType<DetektCreateBaselineTask>().configureEach {
jvmTarget = BuildConfig.Detekt.jvmTarget
}

tasks.withType<Detekt>().configureEach {
jvmTarget = BuildConfig.Detekt.jvmTarget
reports {
html.required.set(true)
md.required.set(true)
Expand All @@ -51,41 +55,12 @@ tasks.withType<Detekt>().configureEach {
}
}

tasks.withType<Detekt>().configureEach {
jvmTarget = BuildConfig.Dokka.jvmTarget
}

tasks.withType<DetektCreateBaselineTask>().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()
}
)
}
}
}
11 changes: 8 additions & 3 deletions buildSrc/src/main/kotlin/BuildConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down Expand Up @@ -104,14 +102,21 @@ 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
*/
object Dokka {
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()
}

/**
Expand Down
23 changes: 23 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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()
}
)
}
}
}

0 comments on commit 0f4fa80

Please sign in to comment.