Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid configuration resolution error for v2 migration helper task #3950

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,13 @@ open class DokkaClassicPlugin : Plugin<Project> {
}

private fun Project.configureEachAbstractDokkaTask() {
tasks.withType<AbstractDokkaTask>().configureEach {
tasks.withType<AbstractDokkaTask>().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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@ 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<out DokkaBootstrap>): DokkaBootstrap {
val runtimeJars = configuration.resolve()
internal fun DokkaBootstrap(classpath: Set<File>, bootstrapClass: KClass<out DokkaBootstrap>): DokkaBootstrap {
val runtimeClassLoader = URLClassLoader(
runtimeJars.map { it.toURI().toURL() }.toTypedArray(),
classpath.map { it.toURI().toURL() }.toTypedArray(),
ClassLoader.getSystemClassLoader().parent
)

val runtimeClassloaderBootstrapClass = runtimeClassLoader.loadClass(bootstrapClass.qualifiedName)
val runtimeClassloaderBootstrapInstance = runtimeClassloaderBootstrapClass.constructors.first().newInstance()
return automagicTypedProxy(DokkaClassicPlugin::class.java.classLoader, runtimeClassloaderBootstrapInstance)
}

@Deprecated("Internal Dokka API.")
fun DokkaBootstrap(configuration: Configuration, bootstrapClass: KClass<out DokkaBootstrap>): DokkaBootstrap {
return DokkaBootstrap(
classpath = configuration.resolve(),
bootstrapClass = bootstrapClass,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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
Expand Down Expand Up @@ -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

/**
Expand All @@ -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<Throwable?>()
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
})
Loading