diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2016-06-30 19:28:19 +0200 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2016-06-30 19:28:19 +0200 |
commit | f03e31ece73774e2ab1df9c55bcb0b65e68f0ddb (patch) | |
tree | c2184ad7859bd6ebeaf00ef2327f989b0fa9cdb1 | |
parent | b1a26bfe44f251f8d8af075cfd5a4180cd4e1ba4 (diff) | |
download | dokka-f03e31ece73774e2ab1df9c55bcb0b65e68f0ddb.tar.gz dokka-f03e31ece73774e2ab1df9c55bcb0b65e68f0ddb.tar.bz2 dokka-f03e31ece73774e2ab1df9c55bcb0b65e68f0ddb.zip |
Correctly include dependencies in classpath of Dokka Android build. Resolves #78
-rw-r--r-- | dokka-android-gradle-plugin/src/main/kotlin/main.kt | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/dokka-android-gradle-plugin/src/main/kotlin/main.kt b/dokka-android-gradle-plugin/src/main/kotlin/main.kt index 29e0b371..054ed358 100644 --- a/dokka-android-gradle-plugin/src/main/kotlin/main.kt +++ b/dokka-android-gradle-plugin/src/main/kotlin/main.kt @@ -2,17 +2,38 @@ package org.jetbrains.dokka.gradle import com.android.build.gradle.AppExtension import com.android.build.gradle.LibraryExtension +import com.android.build.gradle.api.BaseVariant import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.tasks.SourceSet import java.io.File open class DokkaAndroidPlugin : Plugin<Project> { + val allVariantsClassPath = mutableSetOf<File>() + override fun apply(project: Project) { project.tasks.create("dokka", DokkaAndroidTask::class.java).apply { moduleName = project.name outputDirectory = File(project.buildDir, "dokka").absolutePath } + + if (project.hasAndroidPlugin()) { + project.afterEvaluate { + collectClasspath(project) + } + } + else { + project.plugins.whenPluginAdded { + if (project.hasAndroidPlugin()) { + collectClasspath(project) + } + } + } + } + + private fun collectClasspath(project: Project) { + val variants = project.collectAllVariants() + variants.flatMapTo(allVariantsClassPath) { it.javaCompiler.classpath.files } } } @@ -20,6 +41,20 @@ open class DokkaAndroidTask : DokkaTask() { override val sdkProvider: SdkProvider? = AndroidSdkProvider(project) } +private fun Project.hasAndroidPlugin() = plugins.hasPlugin("com.android.library") || plugins.hasPlugin("com.android.application") + +private fun Project.findDokkaAndroidPlugin() = plugins.findPlugin(DokkaAndroidPlugin::class.java) + +private fun Project.collectAllVariants(): Collection<BaseVariant> { + extensions.findByType(LibraryExtension::class.java)?.let { + return it.libraryVariants + } + extensions.findByType(AppExtension::class.java)?.let { + return it.applicationVariants + } + return emptyList() +} + private class AndroidSdkProvider(private val project: Project) : SdkProvider { private val ext by lazy { project.extensions.findByType(LibraryExtension::class.java) ?: project.extensions.findByType(AppExtension::class.java) @@ -28,10 +63,10 @@ private class AndroidSdkProvider(private val project: Project) : SdkProvider { override val name: String = "android" override val isValid: Boolean - get() = project.plugins.hasPlugin("com.android.library") || project.plugins.hasPlugin("com.android.application") + get() = project.hasAndroidPlugin() override val classpath: List<File> - get() = ext.bootClasspath + get() = ext.bootClasspath + (project.findDokkaAndroidPlugin()?.allVariantsClassPath ?: emptyList<File>()) override val sourceDirs: Set<File>? get() { |