diff options
13 files changed, 66 insertions, 104 deletions
@@ -71,11 +71,6 @@ dokka { outputFormat = 'html' outputDirectory = "$buildDir/javadoc" - // [Deprecated] These tasks will be used to determine source directories and classpath - kotlinTasks { - defaultKotlinTasks() + [':some:otherCompileKotlin', project("another").compileKotlin] - } - // In case of Gradle multiproject build, you can include subprojects here to get merged documentation // Note however, that you have to have the Kotlin plugin available in the root project subProjects = ["subproject1", "subproject2"] @@ -130,6 +125,11 @@ dokka { path = "src" } + // These tasks will be used to determine source directories and classpath + kotlinTasks { + defaultKotlinTasks() + [':some:otherCompileKotlin', project("another").compileKotlin] + } + // Specifies the location of the project source code on the Web. // If provided, Dokka generates "source" links for each declaration. // Repeat for multiple mappings diff --git a/runners/android-gradle-plugin/src/main/kotlin/mainAndroid.kt b/runners/android-gradle-plugin/src/main/kotlin/mainAndroid.kt index 1daa1035..8aa76ef8 100644 --- a/runners/android-gradle-plugin/src/main/kotlin/mainAndroid.kt +++ b/runners/android-gradle-plugin/src/main/kotlin/mainAndroid.kt @@ -2,37 +2,16 @@ package org.jetbrains.dokka.gradle import org.gradle.api.Project import org.gradle.api.tasks.Input -import org.gradle.util.GradleVersion import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink.Builder import org.jetbrains.dokka.DokkaConfiguration.SourceRoot import java.io.File open class DokkaAndroidPlugin : DokkaPlugin() { - override fun apply(project: Project) { - DokkaVersion.loadFrom(javaClass.getResourceAsStream("/META-INF/gradle-plugins/org.jetbrains.dokka.properties")) - - val dokkaRuntimeConfiguration = project.configurations.create("dokkaRuntime") - val defaultDokkaRuntimeConfiguration = project.configurations.create("defaultDokkaRuntime") - val taskName = "dokka" - - defaultDokkaRuntimeConfiguration.defaultDependencies{ dependencies -> dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-fatjar:${DokkaVersion.version}")) } - - if(GradleVersion.current() >= GradleVersion.version("4.10")) { - project.tasks.register(taskName, DokkaAndroidTask::class.java).configure { - it.outputDirectory = File(project.buildDir, taskName).absolutePath - } - } else { - project.tasks.create(taskName, DokkaAndroidTask::class.java).apply { - outputDirectory = File(project.buildDir, taskName).absolutePath - } - } - project.tasks.withType(DokkaAndroidTask::class.java) { task -> - task.multiplatform = project.container(GradlePassConfigurationImpl::class.java) - task.configuration = GradlePassConfigurationImpl() - task.dokkaRuntime = dokkaRuntimeConfiguration - task.defaultDokkaRuntime = defaultDokkaRuntimeConfiguration - } + override fun apply(project: Project) { + loadDokkaVersion() + val dokkaRuntimeConfiguration = addConfiguration(project) + addTasks(project, dokkaRuntimeConfiguration, DokkaAndroidTask::class.java) } } diff --git a/runners/gradle-integration-tests/testData/androidApp/app/build.gradle b/runners/gradle-integration-tests/testData/androidApp/app/build.gradle index 20f22f21..74d65e57 100644 --- a/runners/gradle-integration-tests/testData/androidApp/app/build.gradle +++ b/runners/gradle-integration-tests/testData/androidApp/app/build.gradle @@ -42,10 +42,5 @@ android { dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$test_kotlin_version" - defaultDokkaRuntime files(dokka_fatjar) -} - - -dokka { - dokkaFatJar = dokka_fatjar + dokkaRuntime files(dokka_fatjar) }
\ No newline at end of file diff --git a/runners/gradle-integration-tests/testData/androidAppJavadoc/app/build.gradle b/runners/gradle-integration-tests/testData/androidAppJavadoc/app/build.gradle index 0679ee89..e62b6f3d 100644 --- a/runners/gradle-integration-tests/testData/androidAppJavadoc/app/build.gradle +++ b/runners/gradle-integration-tests/testData/androidAppJavadoc/app/build.gradle @@ -41,11 +41,10 @@ android { dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$test_kotlin_version" - defaultDokkaRuntime files(dokka_fatjar) + dokkaRuntime files(dokka_fatjar) } dokka { outputFormat = "javadoc" - dokkaFatJar = dokka_fatjar }
\ No newline at end of file diff --git a/runners/gradle-integration-tests/testData/androidLibDependsOnJavaLib/lib/build.gradle b/runners/gradle-integration-tests/testData/androidLibDependsOnJavaLib/lib/build.gradle index 8706a076..5f2b0d77 100644 --- a/runners/gradle-integration-tests/testData/androidLibDependsOnJavaLib/lib/build.gradle +++ b/runners/gradle-integration-tests/testData/androidLibDependsOnJavaLib/lib/build.gradle @@ -27,11 +27,10 @@ android { dependencies { api(project(":jlib")) - defaultDokkaRuntime files(dokka_fatjar) + dokkaRuntime files(dokka_fatjar) } dokka { - dokkaFatJar = dokka_fatjar configuration { externalDocumentationLink { url = new URL("https://example.com") diff --git a/runners/gradle-integration-tests/testData/androidMultiFlavourApp/app/build.gradle b/runners/gradle-integration-tests/testData/androidMultiFlavourApp/app/build.gradle index 7d8b1490..1d35b37e 100644 --- a/runners/gradle-integration-tests/testData/androidMultiFlavourApp/app/build.gradle +++ b/runners/gradle-integration-tests/testData/androidMultiFlavourApp/app/build.gradle @@ -57,22 +57,20 @@ android { dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$test_kotlin_version" - defaultDokkaRuntime files(dokka_fatjar) + dokkaRuntime files(dokka_fatjar) } dokka { outputDirectory = "$buildDir/dokka/all" - dokkaFatJar = dokka_fatjar } task dokkaFullFlavourOnly(type: org.jetbrains.dokka.gradle.DokkaAndroidTask) { - kotlinTasks { - ["compileFullReleaseKotlin"] - } - dokkaFatJar = dokka_fatjar outputDirectory = "$buildDir/dokka/fullOnly" configuration { moduleName = "full" + kotlinTasks { + ["compileFullReleaseKotlin"] + } } }
\ No newline at end of file diff --git a/runners/gradle-integration-tests/testData/basic/build.gradle b/runners/gradle-integration-tests/testData/basic/build.gradle index b6f85604..79645204 100644 --- a/runners/gradle-integration-tests/testData/basic/build.gradle +++ b/runners/gradle-integration-tests/testData/basic/build.gradle @@ -29,14 +29,13 @@ repositories { } dependencies { - defaultDokkaRuntime files(dokka_fatjar) + dokkaRuntime files(dokka_fatjar) compile group: 'org.jetbrains.kotlin', name: 'kotlin-runtime', version: test_kotlin_version compile group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: test_kotlin_version } dokka { - dokkaFatJar = dokka_fatjar configuration { classpath += "$projectDir/classDir" } diff --git a/runners/gradle-integration-tests/testData/multiProjectSingleOut/build.gradle b/runners/gradle-integration-tests/testData/multiProjectSingleOut/build.gradle index 3ab2b220..0ea86d4c 100644 --- a/runners/gradle-integration-tests/testData/multiProjectSingleOut/build.gradle +++ b/runners/gradle-integration-tests/testData/multiProjectSingleOut/build.gradle @@ -23,14 +23,15 @@ subprojects { } dependencies { - defaultDokkaRuntime files(dokka_fatjar) + dokkaRuntime files(dokka_fatjar) } apply plugin: 'org.jetbrains.dokka' dokka { - kotlinTasks { - [":subA:compileKotlin", ":subB:compileKotlin"] + configuration { + kotlinTasks { + [":subA:compileKotlin", ":subB:compileKotlin"] + } } - dokkaFatJar = dokka_fatjar }
\ No newline at end of file diff --git a/runners/gradle-integration-tests/testData/sourcesChange/build.gradle b/runners/gradle-integration-tests/testData/sourcesChange/build.gradle index 880de5e5..a6270e23 100644 --- a/runners/gradle-integration-tests/testData/sourcesChange/build.gradle +++ b/runners/gradle-integration-tests/testData/sourcesChange/build.gradle @@ -29,12 +29,7 @@ repositories { } dependencies { - defaultDokkaRuntime files(dokka_fatjar) + dokkaRuntime files(dokka_fatjar) compile group: 'org.jetbrains.kotlin', name: 'kotlin-runtime', version: test_kotlin_version compile group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: test_kotlin_version -} - - -dokka { - dokkaFatJar = dokka_fatjar }
\ No newline at end of file diff --git a/runners/gradle-integration-tests/testData/typeSafeConfiguration/build.gradle b/runners/gradle-integration-tests/testData/typeSafeConfiguration/build.gradle index 8e25aaf1..8688ae41 100644 --- a/runners/gradle-integration-tests/testData/typeSafeConfiguration/build.gradle +++ b/runners/gradle-integration-tests/testData/typeSafeConfiguration/build.gradle @@ -26,16 +26,8 @@ def configureDokkaTypeSafely(DokkaTask dokka) { dokka.with { outputFormat = "some String" outputDirectory = "some String" - dokkaFatJar = "some String" cacheRoot = null as String impliedPlatforms = new ArrayList<String>() - - kotlinTasks(new Callable<List<Object>>() { - @Override - List<Object> call() { - return defaultKotlinTasks() - } - }) } dokka.configuration.with { moduleName = "some String" @@ -67,7 +59,12 @@ def configureDokkaTypeSafely(DokkaTask dokka) { link.packageListUrl = uri("some URI").toURL() } }) - + kotlinTasks(new Callable<List<Object>>() { + @Override + List<Object> call() { + return defaultKotlinTasks() + } + }) } } 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 84bbaf78..6a4fbe4f 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 @@ -21,7 +21,8 @@ import java.util.function.BiConsumer open class DokkaTask : DefaultTask() { - fun defaultKotlinTasks() = with(ReflectDsl) { + @Suppress("MemberVisibilityCanBePrivate") + fun defaultKotlinTasks(): List<Task> = with(ReflectDsl) { val abstractKotlinCompileClz = try { project.buildscript.classLoader.loadClass(ABSTRACT_KOTLIN_COMPILE) } catch (cnfe: ClassNotFoundException) { @@ -48,13 +49,6 @@ open class DokkaTask : DefaultTask() { var dokkaRuntime: Configuration? = null - var defaultDokkaRuntime: Configuration? = null - - @Input - var dokkaFatJar: String = "dokka-fatjar-${DokkaVersion.version}" - - private val defaultDokkaFatJar = "dokka-fatjar-${DokkaVersion.version}" - @Input var impliedPlatforms: MutableList<String> = arrayListOf() @@ -77,26 +71,15 @@ open class DokkaTask : DefaultTask() { protected var externalDocumentationLinks: MutableList<DokkaConfiguration.ExternalDocumentationLink> = mutableListOf() - private var kotlinTasksConfigurator: () -> List<Any?>? = { defaultKotlinTasks() } private val kotlinTasks: List<Task> by lazy { extractKotlinCompileTasks() } - @Deprecated("Use manual configuration of source roots or subProjects{} closure") - fun kotlinTasks(taskSupplier: Callable<List<Any>>) { - kotlinTasksConfigurator = { taskSupplier.call() } - } - - @Deprecated("Use manual configuration of source roots or subProjects{} closure") - fun kotlinTasks(closure: Closure<Any?>) { - kotlinTasksConfigurator = { closure.call() as? List<Any?> } - } - @Input var subProjects: List<String> = emptyList() @Input var disableAutoconfiguration: Boolean = false - fun tryResolveFatJar(configuration: Configuration?): Set<File> { + private fun tryResolveFatJar(configuration: Configuration?): Set<File> { return try { configuration!!.resolve() } catch (e: Exception) { @@ -104,15 +87,17 @@ open class DokkaTask : DefaultTask() { } } - fun loadFatJar() { + private fun loadFatJar() { if (ClassloaderContainer.fatJarClassLoader == null) { - val jars = tryResolveFatJar(dokkaRuntime).toList().union(tryResolveFatJar(defaultDokkaRuntime).toList()).filter { it.name.contains(dokkaFatJar) || it.name.contains(defaultDokkaFatJar) } + val jars = tryResolveFatJar(dokkaRuntime).toList() ClassloaderContainer.fatJarClassLoader = URLClassLoader(jars.map { it.toURI().toURL() }.toTypedArray(), ClassLoader.getSystemClassLoader().parent) } } private fun extractKotlinCompileTasks(): List<Task> { - val inputList = (kotlinTasksConfigurator.invoke() ?: emptyList()).filterNotNull() + val collectTasks = configuration.collectKotlinTasks ?: { defaultKotlinTasks() } + + val inputList = (collectTasks.invoke() ?: emptyList()).filterNotNull() val (paths, other) = inputList.partition { it is String } val taskContainer = project.tasks @@ -200,9 +185,9 @@ open class DokkaTask : DefaultTask() { private fun collectFromSinglePlatform(): List<GradlePassConfigurationImpl> { if (disableAutoconfiguration) return listOf(configuration) - val autoConfig = ConfigurationExtractor.extractFromSinglePlatform(project) - val baseConfig = if (autoConfig != null) - listOf(mergeUserConfigurationAndPlatformData(configuration, autoConfig)) + val extractedConfig = ConfigurationExtractor.extractFromSinglePlatform(project) + val baseConfig = if (extractedConfig != null && configuration.collectKotlinTasks == null) + listOf(mergeUserConfigurationAndPlatformData(configuration, extractedConfig)) else collectFromSinglePlatformOldPlugin() diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt index 0364985d..2c071bf8 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt @@ -11,6 +11,7 @@ import org.jetbrains.dokka.Platform import java.io.File import java.io.Serializable import java.net.URL +import java.util.concurrent.Callable import kotlin.reflect.KMutableProperty import kotlin.reflect.full.memberProperties @@ -48,6 +49,15 @@ open class GradlePassConfigurationImpl(@Transient val name: String = ""): PassCo @Input @Optional var platform: String? = null @Input override var targets: List<String> = emptyList() @Input @Optional override var sinceKotlin: String? = null + @Transient var collectKotlinTasks: (() -> List<Any?>?)? = null + + fun kotlinTasks(taskSupplier: Callable<List<Any>>) { + collectKotlinTasks = { taskSupplier.call() } + } + + fun kotlinTasks(closure: Closure<Any?>) { + collectKotlinTasks = { closure.call() as? List<Any?> } + } fun sourceRoot(c: Closure<Unit>) { val configured = ConfigureUtil.configure(c, GradleSourceRootImpl()) 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 66020c5c..a47c238f 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,6 +2,7 @@ package org.jetbrains.dokka.gradle import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.artifacts.Configuration import org.gradle.util.GradleVersion import java.io.File import java.io.InputStream @@ -11,31 +12,35 @@ internal const val CONFIGURATION_EXTENSION_NAME = "configuration" internal const val MULTIPLATFORM_EXTENSION_NAME = "multiplatform" open class DokkaPlugin : Plugin<Project> { + private val taskName = "dokka" override fun apply(project: Project) { - DokkaVersion.loadFrom(javaClass.getResourceAsStream("/META-INF/gradle-plugins/org.jetbrains.dokka.properties")) + loadDokkaVersion() + val dokkaRuntimeConfiguration = addConfiguration(project) + addTasks(project, dokkaRuntimeConfiguration, DokkaTask::class.java) + } - val dokkaRuntimeConfiguration = project.configurations.create("dokkaRuntime") - val defaultDokkaRuntimeConfiguration = project.configurations.create("defaultDokkaRuntime") - val taskName = "dokka" + protected fun loadDokkaVersion() = DokkaVersion.loadFrom(javaClass.getResourceAsStream("/META-INF/gradle-plugins/org.jetbrains.dokka.properties")) - defaultDokkaRuntimeConfiguration.defaultDependencies{ dependencies -> dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-fatjar:${DokkaVersion.version}")) } + protected fun addConfiguration(project: Project) = + project.configurations.create("dokkaRuntime").apply { + defaultDependencies{ dependencies -> dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-fatjar:${DokkaVersion.version}")) } + } + protected fun addTasks(project: Project, runtimeConfiguration: Configuration, taskClass: Class<out DokkaTask>) { if(GradleVersion.current() >= GradleVersion.version("4.10")) { - project.tasks.register(taskName, DokkaTask::class.java).configure { + project.tasks.register(taskName, taskClass).configure { it.outputDirectory = File(project.buildDir, taskName).absolutePath } } else { - project.tasks.create(taskName, DokkaTask::class.java).apply { + project.tasks.create(taskName, taskClass).apply { outputDirectory = File(project.buildDir, taskName).absolutePath } } - - project.tasks.withType(DokkaTask::class.java) { task -> + project.tasks.withType(taskClass) { task -> task.multiplatform = project.container(GradlePassConfigurationImpl::class.java) task.configuration = GradlePassConfigurationImpl() - task.dokkaRuntime = dokkaRuntimeConfiguration - task.defaultDokkaRuntime = defaultDokkaRuntimeConfiguration + task.dokkaRuntime = runtimeConfiguration } } } |