Skip to content

Commit

Permalink
fix: improve dokka support
Browse files Browse the repository at this point in the history
  • Loading branch information
DanySK committed Dec 19, 2024
1 parent 5ede681 commit 4103812
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 30 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {
api(gradleApi())
api(gradleKotlinDsl())
api(libs.kotlin.gradlePlugin)
api(libs.dokka.gradlePlugin)
api(libs.nexus.publish)
api(libs.maven.central.api)
implementation(libs.kotlinx.coroutines)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ testkit = "0.9.0"

[libraries]
fuel = "com.github.kittinunf.fuel:fuel:2.3.1"
dokka-gradlePlugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
kotest-junit5-jvm = { module = "io.kotest:kotest-runner-junit5-jvm", version.ref = "kotest" }
kotest-assertions-core-jvm = { module = "io.kotest:kotest-assertions-core-jvm", version.ref = "kotest" }
kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
Expand All @@ -25,6 +26,5 @@ gradlePluginPublish = "com.gradle.plugin-publish:1.3.0"
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-qa = "org.danilopianini.gradle-kotlin-qa:0.78.0"
multiJvmTesting = "org.danilopianini.multi-jvm-test-plugin:3.0.1"
nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexus-publish" }
publishOnCentral = "org.danilopianini.publish-on-central:7.0.1"
taskTree = "com.dorongold.task-tree:4.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,26 @@ package org.danilopianini.gradle.mavencentral
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.tasks.TaskCollection

/**
* The full name of the `DokkaTask` class.
*/
private const val DOKKA_TASK_CLASS_NAME = "org.jetbrains.dokka.gradle.DokkaTask"
import org.gradle.kotlin.dsl.withType
import org.jetbrains.dokka.gradle.DokkaTask

/**
* The id of the Dokka plugin.
*/
internal const val DOKKA_PLUGIN_ID = "org.jetbrains.dokka"

/**
* Checks whether a [Task] is actually an instance of the type `DokkaTask`, i.e., an instance of the type
* named after [DOKKA_TASK_CLASS_NAME].
* Checks whether a [Task] is actually an instance of the type [DokkaTask].
*/
internal val Task.isDokkaTask: Boolean get() =
runCatching { Class.forName(DOKKA_TASK_CLASS_NAME).isAssignableFrom(this::class.java) }
.getOrElse { this::class.java.name.startsWith(DOKKA_TASK_CLASS_NAME) }
internal val Task.isDokkaTask: Boolean get() = this is DokkaTask

/**
* Selects the available Dokka tasks supporting the generation of [docStyle]-style documentation.
* There may be no such tasks, if the plugin user did not apply the Dokka plugin.
*/
internal fun Project.dokkaTasksFor(docStyle: DocStyle): TaskCollection<out Task> =
tasks.matching {
it.isDokkaTask && it.name.startsWith("dokka") && it.name.endsWith(docStyle.name, ignoreCase = true)
}

/**
* If a task is of type `DokkaTask` (cf. [isDokkaTask]), then retrieves the value of its `outputDirectory`
* property, if any.
*/
internal val Task.dokkaOutputDirectory: Any get() =
when {
isDokkaTask ->
property("outputDirectory")
?: error("$name has no property 'outputDirectory': Dokka version incompatible with publish-on-central?")
else -> error("$name is not of type $DOKKA_TASK_CLASS_NAME")
}
internal fun Project.dokkaTasksFor(docStyle: DocStyle): TaskCollection<out DokkaTask> =
tasks
.withType<DokkaTask>()
.matching {
it.name.startsWith("dokka") && it.name.endsWith(docStyle.name, ignoreCase = true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ class PublishOnCentral : Plugin<Project> {
project
.dokkaTasksFor(docStyle)
.firstOrNull()
?.also { project.logger.info("Actually $message ${it.name}") }
?.also { project.logger.info("Actually {} {}", message, it.name) }
?: error("Dokka plugin applied but no task exists for style $docStyle!")
}
javadocJar.dependsOn(dokkaTask)
javadocJar.from(dokkaTask.map { it.dokkaOutputDirectory })
javadocJar.from(dokkaTask)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.util.*
plugins {
kotlin("multiplatform")
id("org.danilopianini.publish-on-central")
id("org.jetbrains.dokka") version "1.8.10"
id("org.jetbrains.dokka")
}

group = "org.danilopianini"
Expand Down

0 comments on commit 4103812

Please sign in to comment.