From 62e208137f8058e075d1d38a5b167c8241871ce0 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Tue, 14 Jul 2020 12:14:51 +0200 Subject: DokkaMultimoduleTask: Automatically declare dependencies to sub dokka tasks --- .../jetbrains/dokka/gradle/DokkaCollectorTask.kt | 2 +- .../jetbrains/dokka/gradle/DokkaMultimoduleTask.kt | 33 ++++++++++++++-------- .../main/kotlin/org/jetbrains/dokka/gradle/main.kt | 4 +-- 3 files changed, 25 insertions(+), 14 deletions(-) (limited to 'runners/gradle-plugin/src/main') diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt index 0270dbe2..38da9631 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt @@ -16,7 +16,7 @@ open class DokkaCollectorTask : DefaultTask() { private lateinit var configuration: GradleDokkaConfigurationImpl @Input - val dokkaTaskNames: MutableSet = mutableSetOf() + var dokkaTaskNames: Set = setOf() @TaskAction fun collect() { diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultimoduleTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultimoduleTask.kt index affab485..cc7b8d86 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultimoduleTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultimoduleTask.kt @@ -12,7 +12,12 @@ open class DokkaMultimoduleTask : AbstractDokkaTask(), Configurable { @Input - val dokkaTaskNames: MutableSet = mutableSetOf() + var dokkaTaskNames: Set = setOf() + set(value) { + field = value.toSet() + setDependsOn(getSubprojectDokkaTasks(value)) + } + override fun generate() { val bootstrap = DokkaBootstrap("org.jetbrains.dokka.DokkaMultimoduleBootstrapImpl") @@ -36,16 +41,22 @@ open class DokkaMultimoduleTask : AbstractDokkaTask(), Configurable { outputDir = project.file(outputDirectory).absolutePath pluginsClasspath = plugins.resolve().toList() pluginsConfiguration = this@DokkaMultimoduleTask.pluginsConfiguration - modules = project.subprojects - .flatMap { subProject -> dokkaTaskNames.mapNotNull(subProject.tasks::findByName) } - .filterIsInstance() - .map { dokkaTask -> - GradleDokkaModuleDescription().apply { - name = dokkaTask.project.name - path = dokkaTask.project.projectDir.resolve(dokkaTask.outputDirectory) - .toRelativeString(project.file(outputDirectory)) - docFile = dokkaTask.project.projectDir.resolve(documentationFileName).absolutePath - } + modules = getSubprojectDokkaTasks(dokkaTaskNames).map { dokkaTask -> + GradleDokkaModuleDescription().apply { + name = dokkaTask.project.name + path = dokkaTask.project.projectDir.resolve(dokkaTask.outputDirectory) + .toRelativeString(project.file(outputDirectory)) + docFile = dokkaTask.project.projectDir.resolve(documentationFileName).absolutePath } + } } + + private fun getSubprojectDokkaTasks(dokkaTaskName: String): List { + return project.subprojects + .mapNotNull { subproject -> subproject.tasks.findByName(dokkaTaskName) as? DokkaTask } + } + + private fun getSubprojectDokkaTasks(dokkaTaskNames: Set): List { + return dokkaTaskNames.flatMap { dokkaTaskName -> getSubprojectDokkaTasks(dokkaTaskName) } + } } diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt index a851ee13..5bf76880 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt @@ -37,12 +37,12 @@ open class DokkaPlugin : Plugin { project.maybeCreateDokkaPluginConfiguration(multimoduleName) project.maybeCreateDokkaRuntimeConfiguration(multimoduleName) project.tasks.register(multimoduleName) { - dokkaTaskNames.add(name) + dokkaTaskNames = dokkaTaskNames + name configuration() } project.tasks.register("${name}Collector") { - dokkaTaskNames.add(name) + dokkaTaskNames = dokkaTaskNames + name } } } -- cgit