aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt37
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt34
2 files changed, 44 insertions, 27 deletions
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 37952ea8..6a07d9c1 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
@@ -5,6 +5,7 @@ import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaBasePlugin.DOCUMENTATION_GROUP
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
+import org.gradle.api.tasks.TaskDependency
import java.lang.IllegalStateException
open class DokkaCollectorTask : DefaultTask() {
@@ -15,44 +16,48 @@ open class DokkaCollectorTask : DefaultTask() {
@Input
var outputDirectory: String = defaultDokkaOutputDirectory().absolutePath
- private lateinit var configuration: GradleDokkaConfigurationImpl
-
@Input
var dokkaTaskNames: Set<String> = setOf()
+ override fun getFinalizedBy(): TaskDependency {
+ val dokkaTasks = getSubprojectDokkaTasks(dokkaTaskNames)
+ dokkaTasks.forEach { dokkaTask -> finalizedBy(dokkaTask) }
+ dokkaTasks.zipWithNext().forEach { (first, second) -> first.mustRunAfter(second) }
+ return super.getFinalizedBy()
+ }
+
@TaskAction
fun collect() {
- val configurations = project.subprojects
- .filter { subProject -> subProject.name in modules }
- .flatMap { subProject -> dokkaTaskNames.mapNotNull(subProject.tasks::findByName) }
- .filterIsInstance<DokkaTask>()
+ val configurations = getSubprojectDokkaTasks(dokkaTaskNames)
.mapNotNull { dokkaTask -> dokkaTask.getConfigurationOrNull() }
-
val initial = GradleDokkaConfigurationImpl().apply {
outputDir = outputDirectory
cacheRoot = configurations.first().cacheRoot
}
// TODO this certainly not the ideal solution
- configuration = configurations.fold(initial) { acc, it: GradleDokkaConfigurationImpl ->
+ val configuration = configurations.fold(initial) { acc, it: GradleDokkaConfigurationImpl ->
if (acc.cacheRoot != it.cacheRoot)
throw IllegalStateException("Dokka task configurations differ on core argument cacheRoot")
acc.sourceSets = acc.sourceSets + it.sourceSets
acc.pluginsClasspath = (acc.pluginsClasspath + it.pluginsClasspath).distinct()
acc
}
- project.tasks.withType(DokkaTask::class.java).configureEach { it.enforcedConfiguration = configuration }
+ getSubprojectDokkaTasks(dokkaTaskNames).forEach { it.enforcedConfiguration = configuration }
}
- init {
- // TODO: This this certainly not the ideal solution
- dokkaTaskNames.forEach { dokkaTaskName ->
- finalizedBy(dokkaTaskName)
- }
-
- group = DOCUMENTATION_GROUP
+ private fun getSubprojectDokkaTasks(dokkaTaskName: String): List<DokkaTask> {
+ return project.subprojects
+ .filter { subproject -> subproject.name in modules }
+ .mapNotNull { subproject -> subproject.tasks.findByName(dokkaTaskName) as? DokkaTask }
}
+ private fun getSubprojectDokkaTasks(dokkaTaskNames: Set<String>): List<DokkaTask> {
+ return dokkaTaskNames.flatMap { dokkaTaskName -> getSubprojectDokkaTasks(dokkaTaskName) }
+ }
+ init {
+ group = DOCUMENTATION_GROUP
+ }
}
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 d70448f1..e6ed363a 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
@@ -9,7 +9,11 @@ open class DokkaPlugin : Plugin<Project> {
project.setupDokkaTasks("dokkaHtml")
- project.setupDokkaTasks("dokkaJavadoc") {
+ project.setupDokkaTasks(
+ name = "dokkaJavadoc",
+ multimoduleTaskSupported = false,
+ collectorTaskSupported = false
+ ) {
plugins.dependencies.add(project.dokkaArtifacts.javadocPlugin)
}
@@ -26,7 +30,12 @@ open class DokkaPlugin : Plugin<Project> {
* Creates [DokkaTask], [DokkaMultimoduleTask] and [DokkaCollectorTask] for the given
* name and configuration.
*/
- private fun Project.setupDokkaTasks(name: String, configuration: AbstractDokkaTask.() -> Unit = {}) {
+ private fun Project.setupDokkaTasks(
+ name: String,
+ multimoduleTaskSupported: Boolean = true,
+ collectorTaskSupported: Boolean = true,
+ configuration: AbstractDokkaTask.() -> Unit = {}
+ ) {
project.maybeCreateDokkaPluginConfiguration(name)
project.maybeCreateDokkaRuntimeConfiguration(name)
project.tasks.register<DokkaTask>(name) {
@@ -34,16 +43,19 @@ open class DokkaPlugin : Plugin<Project> {
}
if (project.subprojects.isNotEmpty()) {
- val multimoduleName = "${name}Multimodule"
- project.maybeCreateDokkaPluginConfiguration(multimoduleName)
- project.maybeCreateDokkaRuntimeConfiguration(multimoduleName)
- project.tasks.register<DokkaMultimoduleTask>(multimoduleName) {
- dokkaTaskNames = dokkaTaskNames + name
- configuration()
+ if (multimoduleTaskSupported) {
+ val multimoduleName = "${name}Multimodule"
+ project.maybeCreateDokkaPluginConfiguration(multimoduleName)
+ project.maybeCreateDokkaRuntimeConfiguration(multimoduleName)
+ project.tasks.register<DokkaMultimoduleTask>(multimoduleName) {
+ dokkaTaskNames = dokkaTaskNames + name
+ configuration()
+ }
}
-
- project.tasks.register<DokkaCollectorTask>("${name}Collector") {
- dokkaTaskNames = dokkaTaskNames + name
+ if (collectorTaskSupported) {
+ project.tasks.register<DokkaCollectorTask>("${name}Collector") {
+ dokkaTaskNames = dokkaTaskNames + name
+ }
}
}
}