aboutsummaryrefslogtreecommitdiff
path: root/dokka-runners/dokkatoo/buildSrc/src/main/kotlin/buildsrc/conventions/dokka-source-downloader.gradle.kts
blob: 69e384e1094b46982de86bda513f61b60fc256b5 (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
60
61
62
63
64
65
66
67
68
package buildsrc.conventions

import buildsrc.settings.DokkaSourceDownloaderSettings
import buildsrc.utils.asConsumer
import buildsrc.utils.asProvider
import buildsrc.utils.dropDirectories
import org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE
import org.gradle.kotlin.dsl.support.serviceOf

plugins {
  id("buildsrc.conventions.base")
}

val dsdExt: DokkaSourceDownloaderSettings = extensions.create<DokkaSourceDownloaderSettings>(
  DokkaSourceDownloaderSettings.EXTENSION_NAME
)

val kotlinDokkaSource by configurations.creating<Configuration> {
  asConsumer()
  attributes {
    attribute(USAGE_ATTRIBUTE, objects.named("externals-dokka-src"))
  }
}

val kotlinDokkaSourceElements by configurations.registering {
  asProvider()
  attributes {
    attribute(USAGE_ATTRIBUTE, objects.named("externals-dokka-src"))
  }
}

dependencies {
  kotlinDokkaSource(dsdExt.dokkaVersion.map { "kotlin:dokka:$it@zip" })
}

val prepareDokkaSource by tasks.registering(Sync::class) {
  group = "dokka setup"
  description = "Download & unpack Kotlin Dokka source code"

  inputs.property("dokkaVersion", dsdExt.dokkaVersion).optional(false)

  val archives = serviceOf<ArchiveOperations>()

  from(
    kotlinDokkaSource.incoming
      .artifacts
      .resolvedArtifacts
      .map { artifacts ->
        artifacts.map { archives.zipTree(it.file) }
      }
  ) {
    // drop the first dir (dokka-$version)
    eachFile {
      relativePath = relativePath.dropDirectories(1)
    }
  }

  into(temporaryDir)

  exclude(
    "*.github",
    "*.gradle",
    "**/gradlew",
    "**/gradlew.bat",
    "**/gradle/wrapper/gradle-wrapper.jar",
    "**/gradle/wrapper/gradle-wrapper.properties",
  )
}