Skip to content

Commit bf783a8

Browse files
committed
feat: create dokka convention plugin
1 parent 6b89f27 commit bf783a8

File tree

32 files changed

+61
-97
lines changed

32 files changed

+61
-97
lines changed

build-logic/convention/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies {
2828
compileOnly(libs.detekt.gradlePlugin)
2929
compileOnly(libs.ktlint.gradlePlugin)
3030
compileOnly(libs.spotless.gradle)
31+
compileOnly(libs.dokka.gradlePlugin)
3132
implementation(libs.truth)
3233
compileOnly(libs.androidx.room.gradle.plugin)
3334
compileOnly(libs.firebase.crashlytics.gradlePlugin)
@@ -142,5 +143,11 @@ gradlePlugin {
142143
description = "Configures keystore management tasks for the project"
143144
}
144145

146+
// Dokka for documentation
147+
register("dokkaConvention") {
148+
id = "org.convention.dokka.plugin"
149+
implementationClass = "DokkaConventionPlugin"
150+
description = "Configures Dokka for the project."
151+
}
145152
}
146153
}

build-logic/convention/src/main/kotlin/CMPFeatureConventionPlugin.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class CMPFeatureConventionPlugin : Plugin<Project> {
2424
apply("org.jetbrains.compose")
2525
apply("org.convention.detekt.plugin")
2626
apply("org.convention.spotless.plugin")
27+
apply("org.convention.dokka.plugin")
2728
}
2829

2930
dependencies {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import org.convention.configureDokkaConvention
2+
import org.gradle.api.Plugin
3+
import org.gradle.api.Project
4+
5+
class DokkaConventionPlugin : Plugin<Project> {
6+
override fun apply(target: Project) {
7+
target.configureDokkaConvention()
8+
}
9+
10+
private fun Project.applyPlugins() {
11+
pluginManager.apply {
12+
apply("org.jetbrains.dokka")
13+
}
14+
}
15+
}

build-logic/convention/src/main/kotlin/KMPLibraryConventionPlugin.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class KMPLibraryConventionPlugin: Plugin<Project> {
2323
apply("org.convention.spotless.plugin")
2424
apply("org.jetbrains.kotlin.plugin.serialization")
2525
apply("org.jetbrains.kotlin.plugin.parcelize")
26+
apply("org.convention.dokka.plugin")
2627
}
2728

2829
configureKotlinMultiplatform()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.convention
2+
3+
import org.gradle.api.Project
4+
5+
/**
6+
* Configures the Dokka plugin with automatic moduleName generation based on the project hierarchy.
7+
*/
8+
internal fun Project.configureDokkaConvention() = dokkaGradle {
9+
val defaultModuleName = project.path
10+
.trimStart(':')
11+
.replace(':', '-')
12+
.ifBlank { project.name }
13+
14+
println(defaultModuleName)
15+
if (moduleName.orNull.isNullOrBlank()) {
16+
moduleName.set(defaultModuleName)
17+
}
18+
}

build-logic/convention/src/main/kotlin/org/convention/ProjectExtensions.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.gradle.kotlin.dsl.configure
99
import org.gradle.kotlin.dsl.getByType
1010
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
1111
import org.jetbrains.kotlin.gradle.plugin.KotlinHierarchyBuilder
12+
import org.jetbrains.dokka.gradle.DokkaTask
1213

1314
/**
1415
* Get the `libs` version catalog.
@@ -36,4 +37,11 @@ inline fun Project.detektGradle(crossinline configure: DetektExtension.() -> Uni
3637
inline fun Project.spotlessGradle(crossinline configure: SpotlessExtension.() -> Unit) =
3738
extensions.configure<SpotlessExtension> {
3839
configure()
39-
}
40+
}
41+
42+
/**
43+
* Configures the `dokka` plugin with the [configure] lambda for all DokkaTasks.
44+
*/
45+
fun Project.dokkaGradle(configure: DokkaTask.() -> Unit) {
46+
tasks.withType(DokkaTask::class.java).configureEach(configure)
47+
}

cmp-android/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,8 @@ baselineProfile {
167167

168168
// Make use of Dex Layout Optimizations via Startup Profiles
169169
dexLayoutOptimization = true
170+
}
171+
172+
dokka {
173+
moduleName.set("cmp-android")
170174
}

cmp-desktop/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,7 @@ compose.desktop {
8585
}
8686
}
8787
}
88+
89+
dokka {
90+
moduleName.set("cmp-desktop")
91+
}

cmp-navigation/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ plugins {
1212
alias(libs.plugins.kmp.library.convention)
1313
alias(libs.plugins.cmp.feature.convention)
1414
alias(libs.plugins.kmp.koin.convention)
15-
alias(libs.plugins.dokka)
1615
}
1716

1817
kotlin {

cmp-shared/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ plugins {
1212
alias(libs.plugins.kmp.library.convention)
1313
alias(libs.plugins.cmp.feature.convention)
1414
alias(libs.plugins.kotlinCocoapods)
15-
alias(libs.plugins.dokka)
1615
}
1716

1817
kotlin {

0 commit comments

Comments
 (0)