David Herman
01/02/2025, 11:11 PMDavid Herman
01/02/2025, 11:12 PMtasks.dokkaHtml
and tasks.dokkaJavadoc
are stuff we should migrate away from, correct?)David Herman
01/03/2025, 7:26 AM// Part 0
dependencies {
implementation("org.jetbrains.dokka:org.jetbrains.dokka.gradle.plugin:2.0.0")
}
// Part 1
private const val DOKKA_HTML_JAR_TASK_NAME = "dokkaHtmlJar"
@Suppress("UNCHECKED_CAST")
val TaskContainer.dokkaHtmlJar: Provider<Jar>
get() = named(DOKKA_HTML_JAR_TASK_NAME) as Provider<Jar>
class ExamplePlugin : Plugin<Project> {
override fun apply(project: Project) {
project.pluginManager.apply {
apply("org.jetbrains.dokka")
}
@Suppress("UNCHECKED_CAST")
val dokkaHtmlTask = project.tasks.named("dokkaGeneratePublicationHtml") as Provider<DokkaGenerateTask>
project.tasks.register<Jar>(DOKKA_HTML_JAR_TASK_NAME) {
dependsOn(dokkaHtmlTask)
from(dokkaHtmlTask.flatMap { it.outputDirectory })
archiveClassifier.set("javadoc")
}
// Workaround for <https://youtrack.jetbrains.com/issue/KT-61858>
tasks.withType<AbstractPublishToMaven>().configureEach {
val signingTasks = tasks.withType<Sign>()
mustRunAfter(signingTasks)
}
...
}
}
// Part 2
publications.withType<MavenPublication>().configureEach {
artifact(project.tasks.dokkaHtmlJar)
}
The relevant parts are that 1) the task name has changed (it is now dokkaGeneratePublicationHtml
) and 2) you should reference that task inside the maven publication. You should also 3) make it so all publishing tasks run after all signing tasks, or else Gradle complains about implicit ordering.
I hope someone will update the docs. Thanks!Adam Semenenko
01/09/2025, 2:01 PMAdam Semenenko
01/09/2025, 2:06 PMAdam Semenenko
01/09/2025, 2:10 PM@Suppress("UNCHECKED_CAST")
by replacing
named(DOKKA_HTML_JAR_TASK_NAME)
with
tasks.named(DOKKA_HTML_JAR_TASK_NAME, Jar::class.java)
Gradle will do the same casting underneath, so it works the same, but I think it's neater to hide the suppressions and casting. One small difference is that named()
returns a TaskProvider
instead of a Provider
, which is better because Gradle will be able to automatically determine the task dependencies, so manually defining the task dependency with dependsOn(dokkaHtmlTask)
isn't necessary.CLOVIS
01/09/2025, 2:33 PMtasks.named(DOKKA_HTML_JAR_TASK_NAME, Jar::class.java)Gradle should automatically generate that accessor as
tasks.dokkaHtmlJar
, no?Adam Semenenko
01/09/2025, 2:45 PMDavid Herman
01/09/2025, 8:06 PMbuildSrc
so yeah I think I have to generate the accessor manually? But thanks, I agree about removing the unchecked cast.Adam Semenenko
01/09/2025, 8:59 PMmy-foo-convention.gradle.kts
) then the accessors should be generated automatically so you shouldn't need them, but if you're in a 'binary plugin' (a .kt file with a class like class MyFooConvention : Plugin <Project>
then you won't have the generated accessors)David Herman
01/09/2025, 9:00 PM