diff options
Diffstat (limited to 'runners/gradle-plugin/src/main/kotlin/org/jetbrains')
4 files changed, 71 insertions, 38 deletions
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 673148c1..522f4f64 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,36 +1,35 @@ package org.jetbrains.dokka.gradle import org.gradle.api.DefaultTask +import org.gradle.api.Project import org.gradle.api.artifacts.Configuration import org.gradle.api.attributes.Usage import org.gradle.api.tasks.Classpath import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Internal import org.gradle.api.tasks.TaskAction +import org.gradle.kotlin.dsl.dependencies import org.jetbrains.dokka.DokkaBootstrap import org.jetbrains.dokka.plugability.Configurable + abstract class AbstractDokkaTask : DefaultTask(), Configurable { @Input var outputDirectory: String = defaultDokkaOutputDirectory().absolutePath + @Suppress("unused") + @Deprecated("This setting is a noop and will be removed") + @get:Internal + var outputFormat: String = "" + @Input override val pluginsConfiguration: Map<String, String> = mutableMapOf() @Classpath - val plugins: Configuration = project.configurations.create("${name}Plugin").apply { - defaultDependencies { dependencies -> - dependencies.add(project.dokkaArtifacts.dokkaBase) - } - attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime")) - isCanBeConsumed = false - } + val plugins: Configuration = project.maybeCreateDokkaPluginConfiguration(name) @Classpath - val runtime = project.configurations.create("${name}Runtime").apply { - defaultDependencies { dependencies -> - dependencies.add(project.dokkaArtifacts.dokkaCore) - } - } + val runtime: Configuration = project.maybeCreateDokkaRuntimeConfiguration(name) @TaskAction protected fun run() { diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/dokkaConfigurations.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/dokkaConfigurations.kt new file mode 100644 index 00000000..20f54cc5 --- /dev/null +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/dokkaConfigurations.kt @@ -0,0 +1,41 @@ +package org.jetbrains.dokka.gradle + +import org.gradle.api.Project +import org.gradle.api.artifacts.Configuration +import org.gradle.api.attributes.Usage + +internal fun Project.maybeCreateDokkaDefaultPluginConfiguration(): Configuration { + return configurations.maybeCreate("dokkaPlugin") { + attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime")) + isCanBeConsumed = false + } +} + +internal fun Project.maybeCreateDokkaDefaultRuntimeConfiguration(): Configuration { + return configurations.maybeCreate("dokkaRuntime") { + attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime")) + isCanBeConsumed = false + } +} + +internal fun Project.maybeCreateDokkaPluginConfiguration(dokkaTaskName: String): Configuration { + return project.configurations.maybeCreate("${dokkaTaskName}Plugin") { + extendsFrom(maybeCreateDokkaDefaultPluginConfiguration()) + attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime")) + isCanBeConsumed = false + defaultDependencies { dependencies -> + dependencies.add(project.dokkaArtifacts.dokkaBase) + } + } +} + +internal fun Project.maybeCreateDokkaRuntimeConfiguration(dokkaTaskName: String): Configuration { + return project.configurations.maybeCreate("${dokkaTaskName}Runtime") { + extendsFrom(maybeCreateDokkaDefaultRuntimeConfiguration()) + attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime")) + isCanBeConsumed = false + defaultDependencies { dependencies -> + dependencies.add(project.dokkaArtifacts.dokkaCore) + } + } +} 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 ccb7ae0e..a851ee13 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 @@ -2,29 +2,22 @@ package org.jetbrains.dokka.gradle import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.kotlin.dsl.create +import org.gradle.kotlin.dsl.register open class DokkaPlugin : Plugin<Project> { override fun apply(project: Project) { - project.createDokkaTasks("dokka") { - outputDirectory = defaultDokkaOutputDirectory(project.buildDir, "dokkaKdoc").absolutePath - doFirst { - logger.warn(":dokka task is deprecated in favor of :dokkaHtml") - } - } - - project.createDokkaTasks("dokkaHtml") + project.setupDokkaTasks("dokkaHtml") - project.createDokkaTasks("dokkaJavadoc") { + project.setupDokkaTasks("dokkaJavadoc") { plugins.dependencies.add(project.dokkaArtifacts.javadocPlugin) } - project.createDokkaTasks("dokkaGfm") { + project.setupDokkaTasks("dokkaGfm") { plugins.dependencies.add(project.dokkaArtifacts.gfmPlugin) } - project.createDokkaTasks("dokkaJekyll") { + project.setupDokkaTasks("dokkaJekyll") { plugins.dependencies.add(project.dokkaArtifacts.jekyllPlugin) } } @@ -32,27 +25,23 @@ open class DokkaPlugin : Plugin<Project> { /** * Creates [DokkaTask], [DokkaMultimoduleTask] and [DokkaCollectorTask] for the given * name and configuration. - * - * The tasks are created, not registered to enable gradle's accessor generation like - * ``` - * dependencies { - * dokkaPlugin(":my-group:my-plugin:my-version) - * } - * ``` - * - * There is no heavy processing done during configuration of those tasks (I promise). */ - private fun Project.createDokkaTasks(name: String, configuration: AbstractDokkaTask.() -> Unit = {}) { - project.tasks.create<DokkaTask>(name) { + private fun Project.setupDokkaTasks(name: String, configuration: AbstractDokkaTask.() -> Unit = {}) { + project.maybeCreateDokkaPluginConfiguration(name) + project.maybeCreateDokkaRuntimeConfiguration(name) + project.tasks.register<DokkaTask>(name) { configuration() } - project.tasks.create<DokkaMultimoduleTask>("${name}Multimodule") { + val multimoduleName = "${name}Multimodule" + project.maybeCreateDokkaPluginConfiguration(multimoduleName) + project.maybeCreateDokkaRuntimeConfiguration(multimoduleName) + project.tasks.register<DokkaMultimoduleTask>(multimoduleName) { dokkaTaskNames.add(name) configuration() } - project.tasks.create<DokkaCollectorTask>("${name}Collector") { + project.tasks.register<DokkaCollectorTask>("${name}Collector") { dokkaTaskNames.add(name) } } 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 f613f6a7..3a7bcd0d 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 @@ -1,5 +1,6 @@ package org.jetbrains.dokka.gradle +import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project import org.gradle.api.UnknownDomainObjectException import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension @@ -31,7 +32,6 @@ internal fun Project.isMultiplatformProject() = try { internal fun KotlinTarget.isAndroidTarget() = this.platformType == KotlinPlatformType.androidJvm -// TODO NOW: Test internal fun Project.allDescendentProjects(): Sequence<Project> { return sequence { yieldAll(subprojects) @@ -40,3 +40,7 @@ internal fun Project.allDescendentProjects(): Sequence<Project> { } } } + +internal fun <T : Any> NamedDomainObjectContainer<T>.maybeCreate(name: String, configuration: T.() -> Unit): T { + return findByName(name) ?: create(name, configuration) +} |