diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts index 3a68b63b..cf121cf8 100644 --- a/build-logic/convention/build.gradle.kts +++ b/build-logic/convention/build.gradle.kts @@ -28,6 +28,7 @@ dependencies { compileOnly(libs.detekt.gradlePlugin) compileOnly(libs.ktlint.gradlePlugin) compileOnly(libs.spotless.gradle) + compileOnly(libs.dokka.gradlePlugin) implementation(libs.truth) compileOnly(libs.androidx.room.gradle.plugin) compileOnly(libs.firebase.crashlytics.gradlePlugin) @@ -125,5 +126,11 @@ gradlePlugin { description = "Configures Room for the project" } + // Dokka for documentation + register("dokkaConvention") { + id = "org.convention.dokka.plugin" + implementationClass = "DokkaConventionPlugin" + description = "Configures Dokka for the project" + } } } diff --git a/build-logic/convention/src/main/kotlin/CMPFeatureConventionPlugin.kt b/build-logic/convention/src/main/kotlin/CMPFeatureConventionPlugin.kt index c2531dce..0e8541e1 100644 --- a/build-logic/convention/src/main/kotlin/CMPFeatureConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/CMPFeatureConventionPlugin.kt @@ -24,6 +24,7 @@ class CMPFeatureConventionPlugin : Plugin { apply("org.jetbrains.compose") apply("org.convention.detekt.plugin") apply("org.convention.spotless.plugin") + apply("org.convention.dokka.plugin") } dependencies { diff --git a/build-logic/convention/src/main/kotlin/DokkaConventionPlugin.kt b/build-logic/convention/src/main/kotlin/DokkaConventionPlugin.kt new file mode 100644 index 00000000..1f3b8014 --- /dev/null +++ b/build-logic/convention/src/main/kotlin/DokkaConventionPlugin.kt @@ -0,0 +1,23 @@ + +import org.convention.dokkaGradle +import org.gradle.api.Plugin +import org.convention.configureDokka +import org.gradle.api.Project + +class DokkaConventionPlugin : Plugin { + override fun apply(target: Project) { + with(target) { + applyPlugins() + + dokkaGradle { + configureDokka(this) + } + } + } + + private fun Project.applyPlugins() { + pluginManager.apply { + apply("org.jetbrains.dokka") + } + } +} \ No newline at end of file diff --git a/build-logic/convention/src/main/kotlin/KMPLibraryConventionPlugin.kt b/build-logic/convention/src/main/kotlin/KMPLibraryConventionPlugin.kt index 8131dead..40db84d9 100644 --- a/build-logic/convention/src/main/kotlin/KMPLibraryConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/KMPLibraryConventionPlugin.kt @@ -23,6 +23,7 @@ class KMPLibraryConventionPlugin: Plugin { apply("org.convention.spotless.plugin") apply("org.jetbrains.kotlin.plugin.serialization") apply("org.jetbrains.kotlin.plugin.parcelize") + apply("org.convention.dokka.plugin") } configureKotlinMultiplatform() diff --git a/build-logic/convention/src/main/kotlin/org/convention/Dokka.kt b/build-logic/convention/src/main/kotlin/org/convention/Dokka.kt new file mode 100644 index 00000000..191efa84 --- /dev/null +++ b/build-logic/convention/src/main/kotlin/org/convention/Dokka.kt @@ -0,0 +1,30 @@ +package org.convention + +import org.gradle.api.Project +import org.jetbrains.dokka.gradle.DokkaExtension + +/** + * Configures Dokka and suppresses non-allowed modules. + * Sets moduleName only for modules inside :core and :core-base. + * + * e.g., ":core-base:designsystem" -> "core-base-designsystem" + * "core:designsystem" -> "core-designsystem" +*/ +internal fun Project.configureDokka(extension: DokkaExtension) = extension.apply { + val isUnderCoreTrees = project.path.matches(Regex("^:(core|core-base):.+$")) + if (isUnderCoreTrees) { + val moduleId = project.path + .trimStart(':') + .replace(':', '-') + .ifBlank { project.name } + moduleName.set(moduleId) + } + + // Allow only :cmp-*, :core, :core-base, :feature and any of their submodules + val allowed = project.path.matches(Regex("^:(cmp-[^:]+|core(?:-base)?|feature)(?::.*)?$")) + if (!allowed) { + dokkaSourceSets.configureEach { + suppress.set(true) + } + } +} \ No newline at end of file diff --git a/build-logic/convention/src/main/kotlin/org/convention/ProjectExtensions.kt b/build-logic/convention/src/main/kotlin/org/convention/ProjectExtensions.kt index 8b05d6ee..ec8a23cb 100644 --- a/build-logic/convention/src/main/kotlin/org/convention/ProjectExtensions.kt +++ b/build-logic/convention/src/main/kotlin/org/convention/ProjectExtensions.kt @@ -7,8 +7,10 @@ import org.gradle.api.artifacts.VersionCatalog import org.gradle.api.artifacts.VersionCatalogsExtension import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.getByType +import org.jetbrains.dokka.gradle.DokkaExtension import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.plugin.KotlinHierarchyBuilder +import org.jetbrains.dokka.gradle.DokkaTask /** * Get the `libs` version catalog. @@ -36,4 +38,12 @@ inline fun Project.detektGradle(crossinline configure: DetektExtension.() -> Uni inline fun Project.spotlessGradle(crossinline configure: SpotlessExtension.() -> Unit) = extensions.configure { configure() + } + +/** + * Configures the `dokka` plugin with the [configure] lambda for all DokkaTasks. + */ +inline fun Project.dokkaGradle(crossinline configure: DokkaExtension.() -> Unit) = + extensions.configure { + configure() } \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 1d219ee8..7a6fb4b2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -44,6 +44,46 @@ plugins { alias(libs.plugins.ktrofit) apply false alias(libs.plugins.room) apply false + alias(libs.plugins.dokka) +} + +dokka { + dokkaPublications.html { + outputDirectory.set(layout.buildDirectory.dir("$rootDir/docs/docs-api/")) + } +} + +// Currently cmp-web throws some unresolved symbol errors +// So it is not included in the dokka task + +dependencies { + dokka(project(":cmp-shared")) + dokka(project(":cmp-desktop")) + dokka(project(":cmp-android")) +// dokka(project(":cmp-web")) + dokka(project(":cmp-navigation")) + dokka(project(":core:data")) + dokka(project(":core:domain")) + dokka(project(":core:datastore")) + dokka(project(":core:designsystem")) + dokka(project(":core:ui")) + dokka(project(":core:common")) + dokka(project(":core:network")) + dokka(project(":core:model")) + dokka(project(":core:analytics")) + dokka(project(":core:database")) + + dokka(project(":feature:home")) + dokka(project(":feature:profile")) + dokka(project(":feature:settings")) + + dokka(project(":core-base:common")) + dokka(project(":core-base:database")) + dokka(project(":core-base:network")) + dokka(project(":core-base:designsystem")) + dokka(project(":core-base:platform")) + dokka(project(":core-base:ui")) + dokka(project(":core-base:analytics")) } object DynamicVersion { diff --git a/cmp-android/build.gradle.kts b/cmp-android/build.gradle.kts index eed1f90d..80dcc19a 100644 --- a/cmp-android/build.gradle.kts +++ b/cmp-android/build.gradle.kts @@ -19,6 +19,7 @@ plugins { alias(libs.plugins.roborazzi) alias(libs.plugins.aboutLibraries) alias(libs.plugins.ksp) + alias(libs.plugins.dokka) } val packageNameSpace: String = libs.versions.androidPackageNamespace.get() @@ -159,4 +160,8 @@ baselineProfile { // Make use of Dex Layout Optimizations via Startup Profiles dexLayoutOptimization = true +} + +dokka { + moduleName.set("cmp-android") } \ No newline at end of file diff --git a/cmp-desktop/build.gradle.kts b/cmp-desktop/build.gradle.kts index 1dd0cc5b..b02a0a67 100644 --- a/cmp-desktop/build.gradle.kts +++ b/cmp-desktop/build.gradle.kts @@ -14,6 +14,7 @@ plugins { alias(libs.plugins.compose.compiler) alias(libs.plugins.jetbrainsCompose) alias(libs.plugins.kotlin.serialization) + alias(libs.plugins.dokka) } kotlin { @@ -84,3 +85,7 @@ compose.desktop { } } } + +dokka { + moduleName.set("cmp-desktop") +} \ No newline at end of file diff --git a/cmp-web/build.gradle.kts b/cmp-web/build.gradle.kts index f07ed52b..68ee7297 100644 --- a/cmp-web/build.gradle.kts +++ b/cmp-web/build.gradle.kts @@ -4,6 +4,7 @@ plugins { alias(libs.plugins.kotlinMultiplatform) alias(libs.plugins.jetbrainsCompose) alias(libs.plugins.compose.compiler) + alias(libs.plugins.dokka) } kotlin { diff --git a/core-base/common/build.gradle.kts b/core-base/common/build.gradle.kts index e21d2eb5..806ef91e 100644 --- a/core-base/common/build.gradle.kts +++ b/core-base/common/build.gradle.kts @@ -9,6 +9,7 @@ */ plugins { alias(libs.plugins.kmp.core.base.library.convention) + alias(libs.plugins.dokka) } android { @@ -44,3 +45,7 @@ kotlin { } } } + +dokka { + moduleName.set("core-base-common") +} \ No newline at end of file diff --git a/core-base/database/build.gradle.kts b/core-base/database/build.gradle.kts index a4c45363..782f3e95 100644 --- a/core-base/database/build.gradle.kts +++ b/core-base/database/build.gradle.kts @@ -20,6 +20,7 @@ import org.jetbrains.compose.compose */ plugins { alias(libs.plugins.kmp.core.base.library.convention) + alias(libs.plugins.dokka) } android { @@ -45,3 +46,7 @@ kotlin { } } } + +dokka { + moduleName.set("core-base-database") +} \ No newline at end of file diff --git a/core-base/datastore/build.gradle.kts b/core-base/datastore/build.gradle.kts new file mode 100644 index 00000000..e69de29b diff --git a/core-base/designsystem/build.gradle.kts b/core-base/designsystem/build.gradle.kts index e2e08020..c13e045d 100644 --- a/core-base/designsystem/build.gradle.kts +++ b/core-base/designsystem/build.gradle.kts @@ -46,4 +46,4 @@ compose.resources { publicResClass = true generateResClass = always packageOfResClass = "template.core.base.designsystem.generated.resources" -} +} \ No newline at end of file diff --git a/core-base/network/build.gradle.kts b/core-base/network/build.gradle.kts index 84d6f298..136a3275 100644 --- a/core-base/network/build.gradle.kts +++ b/core-base/network/build.gradle.kts @@ -9,6 +9,7 @@ */ plugins { alias(libs.plugins.kmp.core.base.library.convention) + alias(libs.plugins.dokka) } android { @@ -49,3 +50,7 @@ kotlin { } } } + +dokka { + moduleName.set("core-base-network") +} \ No newline at end of file diff --git a/core-base/platform/build.gradle.kts b/core-base/platform/build.gradle.kts index 2c49f22c..7fa39046 100644 --- a/core-base/platform/build.gradle.kts +++ b/core-base/platform/build.gradle.kts @@ -22,6 +22,7 @@ plugins { alias(libs.plugins.kmp.core.base.library.convention) alias(libs.plugins.jetbrainsCompose) alias(libs.plugins.compose.compiler) + alias(libs.plugins.dokka) } android { @@ -58,3 +59,7 @@ kotlin { } } } + +dokka { + moduleName.set("core-base-platform") +} \ No newline at end of file diff --git a/core-base/ui/build.gradle.kts b/core-base/ui/build.gradle.kts index ef39c5ea..89a90b82 100644 --- a/core-base/ui/build.gradle.kts +++ b/core-base/ui/build.gradle.kts @@ -79,4 +79,4 @@ compose.resources { publicResClass = true generateResClass = always packageOfResClass = "template.core.base.ui.generated.resources" -} +} \ No newline at end of file diff --git a/core/ui/build.gradle.kts b/core/ui/build.gradle.kts index 84bbb40a..f5f7bb04 100644 --- a/core/ui/build.gradle.kts +++ b/core/ui/build.gradle.kts @@ -55,4 +55,4 @@ compose.resources { publicResClass = true generateResClass = always packageOfResClass = "org.mifos.core.ui.generated.resources" -} \ No newline at end of file +} diff --git a/gradle.properties b/gradle.properties index ddfc61e6..74a72db4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -59,4 +59,4 @@ kotlin.apple.xcodeCompatibility.nowarn=true # Config minSdk=21 targetSdk=36 -compileSdk=36 +compileSdk=36 \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b2db3143..2c95e0c4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -54,6 +54,7 @@ spotlessVersion = "7.0.2" turbine = "1.2.1" twitter-detekt-compose = "0.0.26" moduleGraph = "2.9.0" +dokka = "2.1.0" # Kotlin KMP Dependencies kotlin = "2.2.21" @@ -179,6 +180,7 @@ okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" } platform-junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junitPlatformLauncherVersion" } spotless-gradle = { group = "com.diffplug.spotless", name = "spotless-plugin-gradle", version.ref = "spotlessVersion" } detekt-gradlePlugin = { group = "io.gitlab.arturbosch.detekt", name = "detekt-gradle-plugin", version.ref = "detekt" } +dokka-gradlePlugin = { group = "org.jetbrains.dokka", name = "dokka-gradle-plugin", version.ref = "dokka" } turbine = { module = "app.cash.turbine:turbine", version.ref = "turbine" } twitter-detekt-compose = { group = "com.twitter.compose.rules", name = "detekt", version.ref = "twitter-detekt-compose" } @@ -378,12 +380,14 @@ git-hooks-convention = { id = "org.convention.git.hooks", version = "unspecified ktlint-convention = { id = "org.convention.ktlint.plugin", version = "unspecified" } spotless-convention = { id = "org.convention.spotless.plugin", version = "unspecified" } keystore-management = { id = "org.convention.keystore.management", version = "unspecified" } +dokka-convention = { id = "org.convention.dokka.plugin", version = "unspecified"} dependencyGuard = { id = "com.dropbox.dependency-guard", version.ref = "dependencyGuard" } moduleGraph = { id = "com.jraska.module.graph.assertion", version.ref = "moduleGraph" } detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" } spotless = { id = "com.diffplug.spotless", version.ref = "spotlessVersion" } +dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } #Room Plugin room = { id = "androidx.room", version.ref = "room" }