diff --git a/dokka-runners/dokka-gradle-plugin/src/classicMain/kotlin/DokkaClassicPlugin.kt b/dokka-runners/dokka-gradle-plugin/src/classicMain/kotlin/DokkaClassicPlugin.kt index cd79c029c0..305c500135 100644 --- a/dokka-runners/dokka-gradle-plugin/src/classicMain/kotlin/DokkaClassicPlugin.kt +++ b/dokka-runners/dokka-gradle-plugin/src/classicMain/kotlin/DokkaClassicPlugin.kt @@ -113,10 +113,13 @@ open class DokkaClassicPlugin : Plugin { } private fun Project.configureEachAbstractDokkaTask() { - tasks.withType().configureEach { + tasks.withType().configureEach task@{ val formatClassifier = name.removePrefix("dokka").decapitalize() outputDirectory.convention(project.layout.buildDirectory.dir("dokka/$formatClassifier")) cacheRoot.convention(project.layout.dir(providers.provider { DokkaDefaults.cacheRoot })) + + pluginsClasspath.from(this@task.plugins) + runtimeClasspath.from(this@task.runtime) } } diff --git a/dokka-runners/dokka-gradle-plugin/src/classicMain/kotlin/dokkaBootstrapFactory.kt b/dokka-runners/dokka-gradle-plugin/src/classicMain/kotlin/dokkaBootstrapFactory.kt index 8462dd9dd1..e2a944cd7e 100644 --- a/dokka-runners/dokka-gradle-plugin/src/classicMain/kotlin/dokkaBootstrapFactory.kt +++ b/dokka-runners/dokka-gradle-plugin/src/classicMain/kotlin/dokkaBootstrapFactory.kt @@ -6,13 +6,13 @@ package org.jetbrains.dokka.gradle import org.gradle.api.artifacts.Configuration import org.jetbrains.dokka.DokkaBootstrap +import java.io.File import java.net.URLClassLoader import kotlin.reflect.KClass -fun DokkaBootstrap(configuration: Configuration, bootstrapClass: KClass): DokkaBootstrap { - val runtimeJars = configuration.resolve() +internal fun DokkaBootstrap(classpath: Set, bootstrapClass: KClass): DokkaBootstrap { val runtimeClassLoader = URLClassLoader( - runtimeJars.map { it.toURI().toURL() }.toTypedArray(), + classpath.map { it.toURI().toURL() }.toTypedArray(), ClassLoader.getSystemClassLoader().parent ) @@ -20,3 +20,11 @@ fun DokkaBootstrap(configuration: Configuration, bootstrapClass: KClass): DokkaBootstrap { + return DokkaBootstrap( + classpath = configuration.resolve(), + bootstrapClass = bootstrapClass, + ) +} diff --git a/dokka-runners/dokka-gradle-plugin/src/classicMain/kotlin/tasks/AbstractDokkaTask.kt b/dokka-runners/dokka-gradle-plugin/src/classicMain/kotlin/tasks/AbstractDokkaTask.kt index cfa64a64c0..ed8f30ef01 100644 --- a/dokka-runners/dokka-gradle-plugin/src/classicMain/kotlin/tasks/AbstractDokkaTask.kt +++ b/dokka-runners/dokka-gradle-plugin/src/classicMain/kotlin/tasks/AbstractDokkaTask.kt @@ -11,6 +11,7 @@ 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.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty import org.gradle.api.logging.LogLevel import org.gradle.api.logging.LogLevel.* @@ -23,6 +24,7 @@ import org.gradle.kotlin.dsl.property import org.gradle.util.GradleVersion import org.gradle.work.DisableCachingByDefault import org.jetbrains.dokka.* +import org.jetbrains.dokka.gradle.internal.InternalDokkaGradlePluginApi import org.jetbrains.dokka.plugability.ConfigurableBlock import org.jetbrains.dokka.plugability.DokkaPlugin import java.util.concurrent.atomic.AtomicReference @@ -195,12 +197,22 @@ abstract class AbstractDokkaTask : DefaultTask() { pluginsConfiguration.add(pluginConfiguration) } - @Classpath + @Internal val plugins: Configuration = project.maybeCreateDokkaPluginConfiguration(name) - @Classpath + /** Resolve the dependencies from [plugins]. */ + @get:Classpath + @InternalDokkaGradlePluginApi + abstract val pluginsClasspath: ConfigurableFileCollection + + @Internal val runtime: Configuration = project.maybeCreateDokkaRuntimeConfiguration(name) + /** Resolve the dependencies from [runtime]. */ + @get:Classpath + @InternalDokkaGradlePluginApi + abstract val runtimeClasspath: ConfigurableFileCollection + private val providers: ProviderFactory = project.providers /** @@ -222,7 +234,7 @@ abstract class AbstractDokkaTask : DefaultTask() { @TaskAction internal open fun generateDocumentation() { - DokkaBootstrap(runtime, DokkaBootstrapImpl::class).apply { + DokkaBootstrap(runtimeClasspath.files, DokkaBootstrapImpl::class).apply { configure(buildDokkaConfiguration().toCompactJsonString(), createProxyLogger()) val uncaughtExceptionHolder = AtomicReference() /** diff --git a/dokka-runners/dokka-gradle-plugin/src/testFunctional/kotlin/DokkaV1TaskDisabledTest.kt b/dokka-runners/dokka-gradle-plugin/src/testFunctional/kotlin/DokkaV1TaskDisabledTest.kt new file mode 100644 index 0000000000..23b322cbf1 --- /dev/null +++ b/dokka-runners/dokka-gradle-plugin/src/testFunctional/kotlin/DokkaV1TaskDisabledTest.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ +package org.jetbrains.dokka.gradle + +import io.kotest.core.spec.style.FunSpec +import org.gradle.testkit.runner.TaskOutcome.SKIPPED +import org.jetbrains.dokka.gradle.utils.addArguments +import org.jetbrains.dokka.gradle.utils.build +import org.jetbrains.dokka.gradle.utils.projects.initNoConfigMultiModuleProject +import org.jetbrains.dokka.gradle.utils.shouldHaveRunTask + +class DokkaV1TaskDisabledTest : FunSpec({ + context("given multi-module project") { + + val project = initNoConfigMultiModuleProject { + gradleProperties { + dokka { + pluginMode = "V2EnabledWithHelpers" + } + } + } + + test("v1 tasks should be skipped when v2 is enabled") { + project.runner + .addArguments("dokkaHtml") + .build { + shouldHaveRunTask(":subproject-one:dokkaHtml", SKIPPED) + shouldHaveRunTask(":subproject-two:dokkaHtml", SKIPPED) + } + } + } +})