blob: 1daa10351d02809e203e953eb1522db20f063c2c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
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
}
}
}
private val ANDROID_REFERENCE_URL = Builder("https://developer.android.com/reference/").build()
open class DokkaAndroidTask : DokkaTask() {
@Input var noAndroidSdkLink: Boolean = false
override fun collectSuppressedFiles(sourceRoots: List<SourceRoot>): List<String> {
val generatedRoot = project.buildDir.resolve("generated").absoluteFile
return sourceRoots
.map { File(it.path) }
.filter { it.startsWith(generatedRoot) }
.flatMap { it.walk().toList() }
.map { it.absolutePath }
}
init {
project.afterEvaluate {
if (!noAndroidSdkLink) externalDocumentationLinks.add(ANDROID_REFERENCE_URL)
}
}
}
|