From dfe9b83c57f21d8f9f2bda74a02bc042bd329271 Mon Sep 17 00:00:00 2001 From: KrystianUjma Date: Fri, 31 May 2019 16:59:32 +0200 Subject: 462 - make dokkaRuntime support for multiple dokka tasks --- .../kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 22 +++++++++------------- .../main/kotlin/org/jetbrains/dokka/gradle/main.kt | 8 +++++++- 2 files changed, 16 insertions(+), 14 deletions(-) (limited to 'runners/gradle-plugin') 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 d4eee4b2..c16c041f 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 @@ -54,6 +54,8 @@ open class DokkaTask : DefaultTask() { var dokkaRuntime: Configuration? = null + var defaultDokkaRuntime: Configuration? = null + @InputFiles var classpath: Iterable = arrayListOf() @@ -64,7 +66,9 @@ open class DokkaTask : DefaultTask() { var sourceRoots: MutableList = arrayListOf() @Input - var dokkaFatJar: Any = "org.jetbrains.dokka:dokka-fatjar:${DokkaVersion.version}" + var dokkaFatJar: String = "dokka-fatjar-${DokkaVersion.version}" + + private val defaultDokkaFatJar = "dokka-fatjar-${DokkaVersion.version}" @Input var impliedPlatforms: MutableList = arrayListOf() @@ -93,20 +97,17 @@ open class DokkaTask : DefaultTask() { } - fun tryResolveFatJar(project: Project): Set { + fun tryResolveFatJar(configuration: Configuration?): Set { return try { - dokkaRuntime!!.resolve() + configuration!!.resolve() } catch (e: Exception) { - project.parent?.let { tryResolveFatJar(it) } ?: throw e + project.parent?.let { tryResolveFatJar(configuration) } ?: throw e } } fun loadFatJar() { if (ClassloaderContainer.fatJarClassLoader == null) { - val jars = if (dokkaFatJar is File) - setOf(dokkaFatJar as File) - else - tryResolveFatJar(project) + val jars = tryResolveFatJar(dokkaRuntime).toList().union(tryResolveFatJar(defaultDokkaRuntime).toList()).filter { it.name.contains(dokkaFatJar) || it.name.contains(defaultDokkaFatJar) } ClassloaderContainer.fatJarClassLoader = URLClassLoader(jars.map { it.toURI().toURL() }.toTypedArray(), ClassLoader.getSystemClassLoader().parent) } } @@ -172,11 +173,6 @@ open class DokkaTask : DefaultTask() { @TaskAction fun generate() { - if (dokkaRuntime == null){ - dokkaRuntime = project.configurations.getByName("dokkaRuntime") - } - - dokkaRuntime?.defaultDependencies{ dependencies -> dependencies.add(project.dependencies.create(dokkaFatJar)) } val kotlinColorsEnabledBefore = System.getProperty(COLORS_ENABLED_PROPERTY) ?: "false" System.setProperty(COLORS_ENABLED_PROPERTY, "false") try { 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 d04ed5f0..fa82d42d 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 @@ -22,8 +22,14 @@ open class DokkaPlugin : Plugin { 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") + + defaultDokkaRuntimeConfiguration.defaultDependencies{ dependencies -> dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-fatjar:${DokkaVersion.version}")) } + project.tasks.create("dokka", DokkaTask::class.java).apply { - dokkaRuntime = project.configurations.create("dokkaRuntime") + dokkaRuntime = dokkaRuntimeConfiguration + defaultDokkaRuntime = defaultDokkaRuntimeConfiguration moduleName = project.name outputDirectory = File(project.buildDir, "dokka").absolutePath } -- cgit