diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-08-05 22:56:16 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-14 17:51:11 +0200 |
commit | e3c1b2bdbfe20e602fbf570df946edc94266e5ff (patch) | |
tree | ccd210e61209e7540954667a34d8d4126a8a0c70 /runners/gradle-plugin/src/main/kotlin | |
parent | 23827bed7b4877b15633e1924f7ee3864f8ebe2c (diff) | |
download | dokka-e3c1b2bdbfe20e602fbf570df946edc94266e5ff.tar.gz dokka-e3c1b2bdbfe20e602fbf570df946edc94266e5ff.tar.bz2 dokka-e3c1b2bdbfe20e602fbf570df946edc94266e5ff.zip |
API refinement for AbstractDokkaParentTask and DokkaMultiModuleTask
Diffstat (limited to 'runners/gradle-plugin/src/main/kotlin')
13 files changed, 292 insertions, 124 deletions
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTask.kt index bf8308bf..c782197e 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTask.kt @@ -1,73 +1,86 @@ package org.jetbrains.dokka.gradle import org.gradle.api.Project -import org.gradle.api.tasks.Input +import org.gradle.api.Task import org.gradle.api.tasks.Internal import org.gradle.api.tasks.Nested import org.jetbrains.dokka.DokkaBootstrap import org.jetbrains.dokka.DokkaBootstrapImpl import kotlin.reflect.KClass -// TODO NOW: Test UP-TO-DATE behaviour abstract class AbstractDokkaParentTask( bootstrapClass: KClass<out DokkaBootstrap> = DokkaBootstrapImpl::class ) : AbstractDokkaTask(bootstrapClass) { - @Input - open var dokkaTaskNames: Set<String> = setOf() - - @Input - var subprojectPaths: Set<String> = project.subprojects.map { project -> project.path }.toSet() - @get:Internal - val subprojects: List<Project> - get() = subprojectPaths.map { path -> project.project(path) }.distinct() + internal var childDokkaTaskPaths: Set<String> = emptySet() + private set @get:Nested - internal val dokkaTasks: List<AbstractDokkaTask> - get() = dokkaTaskNames.flatMap { dokkaTaskName -> findSubprojectDokkaTasks(dokkaTaskName) } - - - /** - * Will remove a single project from participating in this parent task. - * Note: This will not remove the [project]s subprojects. - * - * @see removeAllProjects - */ - fun removeSubproject(project: Project) { - subprojectPaths = subprojectPaths - project.path + internal val childDokkaTasks: Set<AbstractDokkaTask> + get() = childDokkaTaskPaths + .mapNotNull { path -> project.tasks.findByPath(path) } + .map(::checkIsAbstractDokkaTask) + .toSet() + + /* By task reference */ + fun addChildTask(task: AbstractDokkaTask) { + childDokkaTaskPaths = childDokkaTaskPaths + task.path + } + + fun removeChildTask(task: AbstractDokkaTask) { + childDokkaTaskPaths = childDokkaTaskPaths - task.path + } + + /* By path */ + fun addChildTask(path: String) { + childDokkaTaskPaths = childDokkaTaskPaths + project.absoluteProjectPath(path) } - /** - * Will remove the [project] and all its subprojects from participating in this parent task. - * @see removeSubproject - */ - fun removeAllProjects(project: Project) { - project.allprojects.forEach(::removeSubproject) + fun removeChildTask(path: String) { + childDokkaTaskPaths = childDokkaTaskPaths - project.absoluteProjectPath(path) } - /** - * Includes the [project] to participate in this parent task. - * Note: This will not include any of the [project]s subprojects. - * @see addAllProjects - */ - fun addSubproject(project: Project) { - subprojectPaths = (subprojectPaths + project.path) + /* By project reference and name */ + fun addChildTasks(projects: Iterable<Project>, childTasksName: String) { + projects.forEach { project -> + addChildTask(project.absoluteProjectPath(childTasksName)) + } } - /** - * Includes the [project] and all its subprojects to participate in this parent task. - * @see addSubproject - */ - fun addAllProjects(project: Project) { - project.allprojects.forEach(::addSubproject) + fun removeChildTasks(projects: Iterable<Project>, childTasksName: String) { + projects.forEach { project -> + removeChildTask(project.absoluteProjectPath(childTasksName)) + } } - protected fun findSubprojectDokkaTasks(dokkaTaskNames: Set<String>): List<AbstractDokkaTask> { - return dokkaTaskNames.flatMap { dokkaTaskName -> findSubprojectDokkaTasks(dokkaTaskName) } + fun addSubprojectChildTasks(childTasksName: String) { + addChildTasks(project.subprojects, childTasksName) } - private fun findSubprojectDokkaTasks(dokkaTaskName: String): List<AbstractDokkaTask> { - return subprojects.mapNotNull { subproject -> subproject.tasks.findByName(dokkaTaskName) as? DokkaTask } + fun removeSubprojectChildTasks(childTasksName: String) { + removeChildTasks(project.subprojects, childTasksName) + } + + fun removeChildTasks(project: Project) { + childDokkaTaskPaths = childDokkaTaskPaths.filter { path -> + parsePath(path).parent != parsePath(project.path) + }.toSet() + } + + fun removeChildTasks(projects: Iterable<Project>) { + projects.forEach { project -> removeChildTasks(project) } + } + + private fun checkIsAbstractDokkaTask(task: Task): AbstractDokkaTask { + if (task is AbstractDokkaTask) { + return task + } + throw IllegalArgumentException( + "Only tasks of type ${AbstractDokkaTask::class.java.name} can be added as child for " + + "${AbstractDokkaParentTask::class.java.name} tasks.\n" + + "Found task ${task.path} of type ${task::class.java.name} added to $path" + ) } } + diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt index 6413d788..5deaac49 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt @@ -1,12 +1,20 @@ +@file:Suppress("UnstableApiUsage") + package org.jetbrains.dokka.gradle +import groovy.lang.Closure +import org.gradle.api.Action import org.gradle.api.DefaultTask +import org.gradle.api.Task import org.gradle.api.artifacts.Configuration import org.gradle.api.plugins.JavaBasePlugin +import org.gradle.api.provider.MapProperty +import org.gradle.api.provider.Property import org.gradle.api.tasks.* +import org.gradle.kotlin.dsl.mapProperty import org.jetbrains.dokka.DokkaBootstrap import org.jetbrains.dokka.DokkaConfigurationImpl -import org.jetbrains.dokka.plugability.Configurable +import org.jetbrains.dokka.DokkaDefaults import org.jetbrains.dokka.toJsonString import java.io.File import java.util.function.BiConsumer @@ -14,23 +22,26 @@ import kotlin.reflect.KClass abstract class AbstractDokkaTask( private val bootstrapClass: KClass<out DokkaBootstrap> = DokkaBootstrap::class -) : DefaultTask(), Configurable { +) : DefaultTask() { @OutputDirectory - var outputDirectory: File = defaultDokkaOutputDirectory() + val outputDirectory: Property<File> = project.objects.safeProperty<File>() + .safeConvention(defaultDokkaOutputDirectory()) @Optional @InputDirectory - var cacheRoot: File? = null + val cacheRoot: Property<File?> = project.objects.safeProperty() @Input - var failOnWarning: Boolean = false + val failOnWarning: Property<Boolean> = project.objects.safeProperty<Boolean>() + .safeConvention(DokkaDefaults.failOnWarning) @Input - var offlineMode: Boolean = false + val offlineMode: Property<Boolean> = project.objects.safeProperty<Boolean>() + .safeConvention(DokkaDefaults.offlineMode) @Input - override val pluginsConfiguration: MutableMap<String, String> = mutableMapOf() + val pluginsConfiguration: MapProperty<String, String> = project.objects.mapProperty() @Classpath val plugins: Configuration = project.maybeCreateDokkaPluginConfiguration(name) @@ -38,8 +49,16 @@ abstract class AbstractDokkaTask( @Classpath val runtime: Configuration = project.maybeCreateDokkaRuntimeConfiguration(name) + final override fun doFirst(action: Action<in Task>): Task { + return super.doFirst(action) + } + + final override fun doFirst(action: Closure<*>): Task { + return super.doFirst(action) + } + @TaskAction - protected open fun generateDocumentation() { + internal open fun generateDocumentation() { DokkaBootstrap(runtime, bootstrapClass).apply { configure(buildDokkaConfiguration().toJsonString(), createProxyLogger()) generate() 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 4762c333..37571fc5 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 @@ -4,16 +4,21 @@ import org.jetbrains.dokka.DokkaConfigurationImpl open class DokkaCollectorTask : AbstractDokkaParentTask() { + override fun generateDocumentation() { + checkChildDokkaTasksIsNotEmpty() + super.generateDocumentation() + } + override fun buildDokkaConfiguration(): DokkaConfigurationImpl { val initialDokkaConfiguration = DokkaConfigurationImpl( - outputDir = outputDirectory, - cacheRoot = cacheRoot, - failOnWarning = failOnWarning, - offlineMode = offlineMode, + outputDir = outputDirectory.getSafe(), + cacheRoot = cacheRoot.getSafe(), + failOnWarning = failOnWarning.getSafe(), + offlineMode = offlineMode.getSafe(), pluginsClasspath = plugins.resolve().toSet(), ) - val subprojectDokkaConfigurations = dokkaTasks.map { dokkaTask -> dokkaTask.buildDokkaConfiguration() } + val subprojectDokkaConfigurations = childDokkaTasks.map { dokkaTask -> dokkaTask.buildDokkaConfiguration() } return subprojectDokkaConfigurations.fold(initialDokkaConfiguration) { acc, it: DokkaConfigurationImpl -> acc.copy( sourceSets = acc.sourceSets + it.sourceSets, diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayout.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayout.kt new file mode 100644 index 00000000..8cca98d5 --- /dev/null +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayout.kt @@ -0,0 +1,52 @@ +package org.jetbrains.dokka.gradle + +import java.io.File + +interface DokkaMultiModuleFileLayout { + fun targetChildOutputDirectory(parent: AbstractDokkaParentTask, child: AbstractDokkaTask): File + + object NoCopy : DokkaMultiModuleFileLayout { + override fun targetChildOutputDirectory(parent: AbstractDokkaParentTask, child: AbstractDokkaTask): File { + return child.outputDirectory.getSafe() + } + } + + object CompactInParent : DokkaMultiModuleFileLayout { + override fun targetChildOutputDirectory(parent: AbstractDokkaParentTask, child: AbstractDokkaTask): File { + val relativeProjectPath = parent.project.relativeProjectPath(child.project.path) + val relativeFilePath = relativeProjectPath.replace(":", File.separator) + check(!File(relativeFilePath).isAbsolute) { "Unexpected absolute path $relativeFilePath" } + return parent.outputDirectory.getSafe().resolve(relativeFilePath) + } + } +} + +internal fun DokkaMultiModuleTask.targetChildOutputDirectory( + child: AbstractDokkaTask +): File { + return fileLayout.targetChildOutputDirectory(this, child) +} + +internal fun DokkaMultiModuleTask.copyChildOutputDirectories() { + childDokkaTasks.forEach { child -> + fileLayout.copyChildOutputDirectory(this, child) + } +} + +internal fun DokkaMultiModuleFileLayout.copyChildOutputDirectory( + parent: AbstractDokkaParentTask, child: AbstractDokkaTask +) { + val targetChildOutputDirectory = parent.project.file(targetChildOutputDirectory(parent, child)) + val sourceChildOutputDirectory = child.outputDirectory.getSafe() + + if (!sourceChildOutputDirectory.exists()) { + return + } + + if (sourceChildOutputDirectory.absoluteFile == targetChildOutputDirectory.absoluteFile) { + return + } + + sourceChildOutputDirectory.copyRecursively(targetChildOutputDirectory, overwrite = false) +} + 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 new file mode 100644 index 00000000..29e0d76e --- /dev/null +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTask.kt @@ -0,0 +1,69 @@ +package org.jetbrains.dokka.gradle + +import org.gradle.api.internal.tasks.TaskDependencyInternal +import org.gradle.api.tasks.* +import org.jetbrains.dokka.DokkaConfigurationImpl +import org.jetbrains.dokka.DokkaModuleDescriptionImpl +import org.jetbrains.dokka.DokkaMultimoduleBootstrapImpl +import java.io.File + +@Suppress("unused") // Shall provide source compatibility if possible +@Deprecated("Use 'DokkaMultimoduleTask' instead", ReplaceWith("DokkaMultimoduleTask")) +typealias DokkaMultimoduleTask = DokkaMultiModuleTask + + +open class DokkaMultiModuleTask : AbstractDokkaParentTask(DokkaMultimoduleBootstrapImpl::class) { + + /** + * Name of the file containing all necessary module information. + * This file has to be placed inside the subproject root directory. + */ + @Internal + var documentationFileName: String = "README.md" + + @Internal + var fileLayout: DokkaMultiModuleFileLayout = DokkaMultiModuleFileLayout.CompactInParent + + @get:InputFiles + internal val childDocumentationFiles: Iterable<File> + get() = childDokkaTasks.map { task -> task.project.projectDir.resolve(documentationFileName) } + + @get:InputFiles + internal val sourceChildOutputDirectories: Iterable<File> + get() = childDokkaTasks.map { task -> task.outputDirectory.getSafe() } + + @get:OutputDirectories + internal val targetChildOutputDirectories: Iterable<File> + get() = childDokkaTasks.map { task -> targetChildOutputDirectory(task) } + + @Internal + override fun getTaskDependencies(): TaskDependencyInternal { + return super.getTaskDependencies() + childDokkaTasks + } + + override fun generateDocumentation() { + checkChildDokkaTasksIsNotEmpty() + copyChildOutputDirectories() + super.generateDocumentation() + } + + override fun buildDokkaConfiguration(): DokkaConfigurationImpl { + return DokkaConfigurationImpl( + outputDir = outputDirectory.getSafe(), + cacheRoot = cacheRoot.getSafe(), + pluginsConfiguration = pluginsConfiguration.getSafe(), + failOnWarning = failOnWarning.getSafe(), + offlineMode = offlineMode.getSafe(), + pluginsClasspath = plugins.resolve().toSet(), + modules = childDokkaTasks.map { dokkaTask -> + DokkaModuleDescriptionImpl( + name = dokkaTask.project.name, + path = targetChildOutputDirectory(dokkaTask).relativeTo(outputDirectory.getSafe()), + docFile = dokkaTask.project.projectDir.resolve(documentationFileName).absoluteFile + ) + } + ) + } +} + + 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 deleted file mode 100644 index 48a9721f..00000000 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultimoduleTask.kt +++ /dev/null @@ -1,42 +0,0 @@ -package org.jetbrains.dokka.gradle - -import org.gradle.api.internal.tasks.TaskDependencyInternal -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.Internal -import org.jetbrains.dokka.DokkaConfigurationImpl -import org.jetbrains.dokka.DokkaModuleDescriptionImpl -import org.jetbrains.dokka.DokkaMultimoduleBootstrapImpl -import org.jetbrains.dokka.plugability.Configurable - -open class DokkaMultimoduleTask : AbstractDokkaParentTask(DokkaMultimoduleBootstrapImpl::class), Configurable { - - /** - * Name of the file containing all necessary module information. - * This file has to be placed inside the subrpojects root directory. - */ - @Input - var documentationFileName: String = "README.md" - - @Internal - override fun getTaskDependencies(): TaskDependencyInternal { - return super.getTaskDependencies() + dokkaTasks - } - - override fun buildDokkaConfiguration(): DokkaConfigurationImpl { - return DokkaConfigurationImpl( - outputDir = outputDirectory, - cacheRoot = cacheRoot, - pluginsConfiguration = pluginsConfiguration, - failOnWarning = failOnWarning, - offlineMode = offlineMode, - pluginsClasspath = plugins.resolve().toSet(), - modules = dokkaTasks.map { dokkaTask -> - DokkaModuleDescriptionImpl( - name = dokkaTask.project.name, - path = dokkaTask.outputDirectory.relativeTo(outputDirectory), - docFile = dokkaTask.project.projectDir.resolve(documentationFileName).absoluteFile - ) - } - ) - } -} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt index c5713d16..6f92abdf 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt @@ -26,12 +26,12 @@ open class DokkaTask : AbstractDokkaTask(DokkaBootstrapImpl::class) { override fun buildDokkaConfiguration(): DokkaConfigurationImpl { return DokkaConfigurationImpl( - outputDir = outputDirectory, - cacheRoot = cacheRoot, - offlineMode = offlineMode, - failOnWarning = failOnWarning, + outputDir = outputDirectory.getSafe(), + cacheRoot = cacheRoot.getSafe(), + offlineMode = offlineMode.getSafe(), + failOnWarning = failOnWarning.getSafe(), sourceSets = dokkaSourceSets.build(), - pluginsConfiguration = pluginsConfiguration, + pluginsConfiguration = pluginsConfiguration.getSafe(), pluginsClasspath = plugins.resolve() ) } diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/TaskDependencyInternalWithAdditions.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/TaskDependencyInternalWithAdditions.kt index fb648c02..969b1aa1 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/TaskDependencyInternalWithAdditions.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/TaskDependencyInternalWithAdditions.kt @@ -5,7 +5,7 @@ import org.gradle.api.internal.tasks.AbstractTaskDependency import org.gradle.api.internal.tasks.TaskDependencyInternal import org.gradle.api.internal.tasks.TaskDependencyResolveContext -operator fun TaskDependencyInternal.plus(tasks: Iterable<Task>): TaskDependencyInternal { +internal operator fun TaskDependencyInternal.plus(tasks: Iterable<Task>): TaskDependencyInternal { return TaskDependencyInternalWithAdditions(this, tasks.toSet()) } diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/checkChildDokkaTasksIsNotEmpty.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/checkChildDokkaTasksIsNotEmpty.kt new file mode 100644 index 00000000..a47ea4cd --- /dev/null +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/checkChildDokkaTasksIsNotEmpty.kt @@ -0,0 +1,43 @@ +package org.jetbrains.dokka.gradle + +import org.jetbrains.dokka.DokkaException + +fun AbstractDokkaParentTask.checkChildDokkaTasksIsNotEmpty() { + if (childDokkaTaskPaths.isEmpty()) { + throw DokkaException( + """ + The ${this::class.java.simpleName} $path has no configured child tasks. + Add some dokka tasks like e.g.: + + tasks.named<AbstractDokkaParentTask>("$name") { + addChildTask(..) + addChildTasks(subprojects, "...") + //... + } + """.trimIndent() + ) + } + + if (childDokkaTasks.isEmpty()) { + throw DokkaException( + """ + The ${this::class.java.simpleName} $path could not find any registered child task. + child tasks: $childDokkaTaskPaths + + Please make sure to apply the dokka plugin to all included (sub)-projects individually e.g.: + + // subproject build.gradle.kts + plugins { + id("org.jetbrains.dokka") + } + + or + + // parent build.gradle.kts + subprojects { + plugins.apply("org.jetbrains.dokka") + } + """ + ) + } +} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/dokka.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/dokka.kt deleted file mode 100644 index 2625f64c..00000000 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/dokka.kt +++ /dev/null @@ -1,7 +0,0 @@ -import org.gradle.api.Project -import org.gradle.kotlin.dsl.withType -import org.jetbrains.dokka.gradle.DokkaTask - -fun Project.dokka(configuration: DokkaTask.() -> Unit) { - tasks.withType<DokkaTask>().configureEach(configuration) -} 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 71fad405..8ba28e83 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 @@ -1,5 +1,6 @@ package org.jetbrains.dokka.gradle +import org.gradle.api.DefaultTask import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.register @@ -11,7 +12,7 @@ open class DokkaPlugin : Plugin<Project> { project.setupDokkaTasks( name = "dokkaJavadoc", - multimoduleTaskSupported = false + multiModuleTaskSupported = false ) { plugins.dependencies.add(project.dokkaArtifacts.javadocPlugin) } @@ -26,12 +27,12 @@ open class DokkaPlugin : Plugin<Project> { } /** - * Creates [DokkaTask], [DokkaMultimoduleTask] for the given + * Creates [DokkaTask], [DokkaMultiModuleTask] for the given * name and configuration. */ private fun Project.setupDokkaTasks( name: String, - multimoduleTaskSupported: Boolean = true, + multiModuleTaskSupported: Boolean = true, collectorTaskSupported: Boolean = true, configuration: AbstractDokkaTask.() -> Unit = {} ) { @@ -42,18 +43,24 @@ open class DokkaPlugin : Plugin<Project> { } if (project.subprojects.isNotEmpty()) { - if (multimoduleTaskSupported) { - val multimoduleName = "${name}Multimodule" - project.maybeCreateDokkaPluginConfiguration(multimoduleName) - project.maybeCreateDokkaRuntimeConfiguration(multimoduleName) - project.tasks.register<DokkaMultimoduleTask>(multimoduleName) { - dokkaTaskNames = dokkaTaskNames + name + if (multiModuleTaskSupported) { + val multiModuleName = "${name}MultiModule" + project.maybeCreateDokkaPluginConfiguration(multiModuleName) + project.maybeCreateDokkaRuntimeConfiguration(multiModuleName) + project.tasks.register<DokkaMultiModuleTask>(multiModuleName) { + addSubprojectChildTasks(name) configuration() } + project.tasks.register<DefaultTask>("${name}Multimodule") { + dependsOn(multiModuleName) + doLast { + logger.warn("'Multimodule' is deprecated. Use 'MultiModule' instead") + } + } } if (collectorTaskSupported) { project.tasks.register<DokkaCollectorTask>("${name}Collector") { - dokkaTaskNames = dokkaTaskNames + name + addSubprojectChildTasks(name) } } } diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/toDokkaSourceSetImpl.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/toDokkaSourceSetImpl.kt index 64d44157..c815a8a3 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/toDokkaSourceSetImpl.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/toDokkaSourceSetImpl.kt @@ -63,7 +63,6 @@ private fun GradleDokkaSourceSetBuilder.externalDocumentationLinksWithDefaults() .toSet() } - private fun GradleDokkaSourceSetBuilder.suppressedFilesWithDefaults(): Set<File> { val suppressedFilesForAndroid = if (project.isAndroidProject()) { val generatedRoot = project.buildDir.resolve("generated").absoluteFile diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt index 28c16a2a..7a69c409 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt @@ -3,8 +3,10 @@ package org.jetbrains.dokka.gradle import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project import org.gradle.api.UnknownDomainObjectException +import org.gradle.api.provider.HasMultipleValues import org.gradle.api.provider.Property import org.gradle.api.provider.Provider +import org.gradle.util.Path import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType @@ -18,6 +20,14 @@ internal infix fun <T> Property<T>.by(value: Provider<T>) { this.set(value) } +internal infix fun <T> HasMultipleValues<in T>.by(values: Iterable<T>) { + this.set(values) +} + +internal fun parsePath(path: String): Path { + return Path.path(path) +} + internal val Project.kotlinOrNull: KotlinProjectExtension? get() = try { project.extensions.findByType(KotlinProjectExtension::class.java) |