-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
build.gradle.kts
420 lines (349 loc) · 17.7 KB
/
build.gradle.kts
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.gradle.*
import java.net.URL
plugins {
base
id("org.jetbrains.dokka")
}
val isTeamcityBuild = project.hasProperty("teamcity.version")
// kotlin/libraries/tools/kotlin-stdlib-docs -> kotlin
val kotlin_root = rootProject.file("../../../").absoluteFile.invariantSeparatorsPath
val kotlin_libs by extra("$buildDir/libs")
val rootProperties = java.util.Properties().apply {
file(kotlin_root).resolve("gradle.properties").inputStream().use { stream -> load(stream) }
}
val defaultSnapshotVersion: String by rootProperties
val githubRevision = if (isTeamcityBuild) project.property("githubRevision") else "master"
val artifactsVersion by extra(if (isTeamcityBuild) project.property("deployVersion") as String else defaultSnapshotVersion)
val artifactsRepo by extra(if (isTeamcityBuild) project.property("kotlinLibsRepo") as String else "$kotlin_root/build/repo")
val dokka_version: String by project
println("# Parameters summary:")
println(" isTeamcityBuild: $isTeamcityBuild")
println(" dokka version: $dokka_version")
println(" githubRevision: $githubRevision")
println(" artifacts version: $artifactsVersion")
println(" artifacts repo: $artifactsRepo")
val outputDir = file(findProperty("docsBuildDir") as String? ?: "$buildDir/doc")
val inputDirPrevious = file(findProperty("docsPreviousVersionsDir") as String? ?: "$outputDir/previous")
val outputDirPartial = outputDir.resolve("partial")
val kotlin_native_root = file("$kotlin_root/kotlin-native").absolutePath
val templatesDir = file(findProperty("templatesDir") as String? ?: "$projectDir/templates").invariantSeparatorsPath
val cleanDocs by tasks.registering(Delete::class) {
delete(outputDir)
}
tasks.clean {
dependsOn(cleanDocs)
}
val prepare by tasks.registering {
dependsOn(":kotlin_big:extractLibs")
}
repositories {
mavenCentral()
maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev")
}
dependencies {
dokkaPlugin(project(":plugins:dokka-samples-transformer-plugin"))
dokkaPlugin(project(":plugins:dokka-stdlib-configuration-plugin"))
dokkaPlugin(project(":plugins:dokka-version-filter-plugin"))
dokkaPlugin("org.jetbrains.dokka:versioning-plugin:$dokka_version")
}
fun createStdLibVersionedDocTask(version: String, isLatest: Boolean) =
tasks.register<DokkaTaskPartial>("kotlin-stdlib_" + version + (if (isLatest) "_latest" else "")) {
dependsOn(prepare)
val kotlin_stdlib_dir = file("$kotlin_root/libraries/stdlib")
val stdlibIncludeMd = file("$kotlin_root/libraries/stdlib/src/Module.md")
val stdlibSamples = file("$kotlin_root/libraries/stdlib/samples/test")
val suppressedPackages = listOf(
"kotlin.internal",
"kotlin.jvm.internal",
"kotlin.js.internal",
"kotlin.native.internal",
"kotlin.jvm.functions",
"kotlin.coroutines.jvm.internal",
)
val kotlinLanguageVersion = version
moduleName.set("kotlin-stdlib")
val moduleDirName = "kotlin-stdlib"
with(pluginsMapConfiguration) {
put("org.jetbrains.dokka.base.DokkaBase" , """{ "mergeImplicitExpectActualDeclarations": "true", "templatesDir": "$templatesDir" }""")
put("org.jetbrains.dokka.kotlinlang.StdLibConfigurationPlugin", """{ "ignoreCommonBuiltIns": "true" }""")
put("org.jetbrains.dokka.versioning.VersioningPlugin" , """{ "version": "$version" }" }""")
}
if (isLatest) {
outputDirectory.set(file("$outputDirPartial/latest").resolve(moduleDirName))
} else {
outputDirectory.set(file("$outputDirPartial/previous").resolve(moduleDirName).resolve(version))
pluginsMapConfiguration
.put("org.jetbrains.dokka.kotlinlang.VersionFilterPlugin" , """{ "targetVersion": "$version" }""")
}
dokkaSourceSets {
register("common") {
jdkVersion.set(8)
platform.set(Platform.common)
noJdkLink.set(true)
displayName.set("Common")
sourceRoots.from("$kotlin_root/core/builtins/native")
sourceRoots.from("$kotlin_root/core/builtins/src/")
sourceRoots.from("$kotlin_stdlib_dir/common/src")
sourceRoots.from("$kotlin_stdlib_dir/src")
sourceRoots.from("$kotlin_stdlib_dir/unsigned/src")
}
register("jvm") {
jdkVersion.set(8)
platform.set(Platform.jvm)
displayName.set("JVM")
dependsOn("common")
sourceRoots.from("$kotlin_stdlib_dir/jvm/src")
sourceRoots.from("$kotlin_stdlib_dir/jvm/runtime/kotlin/jvm/annotations")
sourceRoots.from("$kotlin_stdlib_dir/jvm/runtime/kotlin/jvm/JvmClassMapping.kt")
sourceRoots.from("$kotlin_stdlib_dir/jvm/runtime/kotlin/jvm/PurelyImplements.kt")
sourceRoots.from("$kotlin_stdlib_dir/jvm/runtime/kotlin/Metadata.kt")
sourceRoots.from("$kotlin_stdlib_dir/jvm/runtime/kotlin/Throws.kt")
sourceRoots.from("$kotlin_stdlib_dir/jvm/runtime/kotlin/TypeAliases.kt")
sourceRoots.from("$kotlin_stdlib_dir/jvm/runtime/kotlin/text/TypeAliases.kt")
sourceRoots.from("$kotlin_stdlib_dir/jdk7/src")
sourceRoots.from("$kotlin_stdlib_dir/jdk8/src")
}
register("js") {
jdkVersion.set(8)
platform.set(Platform.js)
noJdkLink.set(true)
displayName.set("JS")
dependsOn("common")
sourceRoots.from("$kotlin_stdlib_dir/js/src")
sourceRoots.from("$kotlin_stdlib_dir/js-v1/src")
perPackageOption("org.w3c") {
reportUndocumented.set(false)
}
perPackageOption("org.khronos") {
reportUndocumented.set(false)
}
}
register("native") {
jdkVersion.set(8)
platform.set(Platform.native)
noJdkLink.set(true)
displayName.set("Native")
dependsOn("common")
sourceRoots.from("$kotlin_native_root/Interop/Runtime/src/main/kotlin")
sourceRoots.from("$kotlin_native_root/Interop/Runtime/src/native/kotlin")
sourceRoots.from("$kotlin_native_root/Interop/JsRuntime/src/main/kotlin")
sourceRoots.from("$kotlin_native_root/runtime/src/main/kotlin")
sourceRoots.from("$kotlin_stdlib_dir/native-wasm/src")
perPackageOption("kotlin.test") {
suppress.set(true)
}
}
configureEach {
documentedVisibilities.set(setOf(DokkaConfiguration.Visibility.PUBLIC, DokkaConfiguration.Visibility.PROTECTED))
skipDeprecated.set(false)
includes.from(stdlibIncludeMd)
noStdlibLink.set(true)
languageVersion.set(kotlinLanguageVersion)
samples.from(stdlibSamples.toString())
suppressedPackages.forEach { packageName ->
perPackageOption(packageName) {
suppress.set(true)
}
}
sourceLinksFromRoot()
}
}
}
fun createKotlinReflectVersionedDocTask(version: String, isLatest: Boolean) =
tasks.register<DokkaTaskPartial>("kotlin-reflect_" + version + (if (isLatest) "_latest" else "")) {
dependsOn(prepare)
val kotlinReflectIncludeMd = file("$kotlin_root/libraries/reflect/Module.md")
val kotlinReflectClasspath = fileTree("$kotlin_libs/kotlin-reflect")
val kotlinLanguageVersion = version
moduleName.set("kotlin-reflect")
val moduleDirName = "kotlin-reflect"
with(pluginsMapConfiguration) {
put("org.jetbrains.dokka.base.DokkaBase", """{ "templatesDir": "$templatesDir" }""")
put("org.jetbrains.dokka.versioning.VersioningPlugin", """{ "version": "$version" }""")
}
if (isLatest) {
outputDirectory.set(file("$outputDirPartial/latest").resolve(moduleDirName))
} else {
outputDirectory.set(file("$outputDirPartial/previous").resolve(moduleDirName).resolve(version))
pluginsMapConfiguration.put("org.jetbrains.dokka.kotlinlang.VersionFilterPlugin", """{ "targetVersion": "$version" }""")
}
dokkaSourceSets {
register("jvm") {
jdkVersion.set(8)
platform.set(Platform.jvm)
classpath.setFrom(kotlinReflectClasspath)
displayName.set("JVM")
sourceRoots.from("$kotlin_root/core/reflection.jvm/src")
skipDeprecated.set(false)
includes.from(kotlinReflectIncludeMd)
languageVersion.set(kotlinLanguageVersion)
noStdlibLink.set(true)
perPackageOption("kotlin.reflect.jvm.internal") {
suppress.set(true)
}
sourceLinksFromRoot()
}
}
}
fun createKotlinTestVersionedDocTask(version: String, isLatest: Boolean) =
tasks.register<DokkaTaskPartial>("kotlin-test_" + version + (if (isLatest) "_latest" else "")) {
dependsOn(prepare)
val kotlinTestIncludeMd = file("$kotlin_root/libraries/kotlin.test/Module.md")
val kotlinTestCommonClasspath = fileTree("$kotlin_libs/kotlin-test-common")
val kotlinTestJunitClasspath = fileTree("$kotlin_libs/kotlin-test-junit")
val kotlinTestJunit5Classpath = fileTree("$kotlin_libs/kotlin-test-junit5")
val kotlinTestTestngClasspath = fileTree("$kotlin_libs/kotlin-test-testng")
val kotlinTestJsClasspath = fileTree("$kotlin_libs/kotlin-test-js")
val kotlinTestJvmClasspath = fileTree("$kotlin_libs/kotlin-test")
val kotlinLanguageVersion = version
moduleName.set("kotlin-test")
val moduleDirName = "kotlin-test"
with(pluginsMapConfiguration) {
put("org.jetbrains.dokka.base.DokkaBase", """{ "templatesDir": "$templatesDir" }""")
put("org.jetbrains.dokka.versioning.VersioningPlugin", """{ "version": "$version" }""")
}
if (isLatest) {
outputDirectory.set(file("$outputDirPartial/latest").resolve(moduleDirName))
} else {
outputDirectory.set(file("$outputDirPartial/previous").resolve(moduleDirName).resolve(version))
pluginsMapConfiguration.put("org.jetbrains.dokka.kotlinlang.VersionFilterPlugin", """{ "targetVersion": "$version" }""")
}
dokkaSourceSets {
register("common") {
jdkVersion.set(8)
platform.set(Platform.common)
classpath.setFrom(kotlinTestCommonClasspath)
noJdkLink.set(true)
displayName.set("Common")
sourceRoots.from("$kotlin_root/libraries/kotlin.test/common/src/main/kotlin")
sourceRoots.from("$kotlin_root/libraries/kotlin.test/annotations-common/src/main/kotlin")
}
register("jvm") {
jdkVersion.set(8)
platform.set(Platform.jvm)
classpath.setFrom(kotlinTestJvmClasspath)
displayName.set("JVM")
dependsOn("common")
sourceRoots.from("$kotlin_root/libraries/kotlin.test/jvm/src/main/kotlin")
}
register("jvm-JUnit") {
jdkVersion.set(8)
platform.set(Platform.jvm)
classpath.setFrom(kotlinTestJunitClasspath)
displayName.set("JUnit")
dependsOn("common")
dependsOn("jvm")
sourceRoots.from("$kotlin_root/libraries/kotlin.test/junit/src/main/kotlin")
externalDocumentationLink {
url.set(URL("http://junit.org/junit4/javadoc/latest/"))
packageListUrl.set(URL("http://junit.org/junit4/javadoc/latest/package-list"))
}
}
register("jvm-JUnit5") {
jdkVersion.set(8)
platform.set(Platform.jvm)
classpath.setFrom(kotlinTestJunit5Classpath)
displayName.set("JUnit5")
dependsOn("common")
dependsOn("jvm")
sourceRoots.from("$kotlin_root/libraries/kotlin.test/junit5/src/main/kotlin")
externalDocumentationLink {
url.set(URL("https://junit.org/junit5/docs/current/api/"))
packageListUrl.set(URL("https://junit.org/junit5/docs/current/api/element-list"))
}
}
register("jvm-TestNG") {
jdkVersion.set(8)
platform.set(Platform.jvm)
classpath.setFrom(kotlinTestTestngClasspath)
displayName.set("TestNG")
dependsOn("common")
dependsOn("jvm")
sourceRoots.from("$kotlin_root/libraries/kotlin.test/testng/src/main/kotlin")
// externalDocumentationLink {
// url.set(new URL("https://jitpack.io/com/github/cbeust/testng/master/javadoc/"))
// packageListUrl.set(new URL("https://jitpack.io/com/github/cbeust/testng/master/javadoc/package-list"))
// }
}
register("js") {
platform.set(Platform.js)
classpath.setFrom(kotlinTestJsClasspath)
noJdkLink.set(true)
displayName.set("JS")
dependsOn("common")
sourceRoots.from("$kotlin_root/libraries/kotlin.test/js/src/main/kotlin")
}
register("native") {
platform.set(Platform.native)
noJdkLink.set(true)
displayName.set("Native")
dependsOn("common")
sourceRoots.from("$kotlin_native_root/runtime/src/main/kotlin/kotlin/test")
}
configureEach {
skipDeprecated.set(false)
includes.from(kotlinTestIncludeMd)
languageVersion.set(kotlinLanguageVersion)
noStdlibLink.set(true)
sourceLinksFromRoot()
}
}
}
fun createAllLibsVersionedDocTask(version: String, isLatest: Boolean, vararg libTasks: TaskProvider<DokkaTaskPartial>) =
tasks.register<DokkaMultiModuleTask>("all-libs_" + version + (if (isLatest) "_latest" else "")) {
moduleName.set("Kotlin libraries")
plugins.extendsFrom(configurations.dokkaHtmlMultiModulePlugin.get())
runtime.extendsFrom(configurations.dokkaHtmlMultiModuleRuntime.get())
libTasks.forEach { addChildTask(it.name) }
fileLayout.set(DokkaMultiModuleFileLayout { parent, child ->
parent.outputDirectory.get().resolve(child.moduleName.get())
})
val moduleDirName = "all-libs"
val outputDirLatest = file("$outputDir/latest")
val outputDirPrevious = file("$outputDir/previous")
pluginsMapConfiguration.put("org.jetbrains.dokka.base.DokkaBase", """{ "templatesDir": "$templatesDir" }""")
if (isLatest) {
outputDirectory.set(outputDirLatest.resolve(moduleDirName))
pluginsMapConfiguration.put("org.jetbrains.dokka.versioning.VersioningPlugin", """{ "version": "$version", "olderVersionsDir": "${inputDirPrevious.resolve(moduleDirName).invariantSeparatorsPath}" }""")
} else {
outputDirectory.set(outputDirPrevious.resolve(moduleDirName).resolve(version))
pluginsMapConfiguration.put("org.jetbrains.dokka.versioning.VersioningPlugin", """{ "version": "$version" }""")
}
}
fun GradleDokkaSourceSetBuilder.perPackageOption(packageNamePrefix: String, action: Action<in GradlePackageOptionsBuilder>) =
perPackageOption {
matchingRegex.set(Regex.escape(packageNamePrefix) + "(\$|\\..*)")
action(this)
}
fun GradleDokkaSourceSetBuilder.sourceLinksFromRoot() {
sourceLink {
localDirectory.set(file(kotlin_root))
remoteUrl.set(URL("https://github.com/JetBrains/kotlin/tree/$githubRevision"))
remoteLineSuffix.set("#L")
}
}
run {
val versions = listOf(/*"1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7",*/ "1.8")
val latestVersion = versions.last()
// builds this version/all versions as historical for the next versions builds
val buildAllVersions by tasks.registering
// builds the latest version incorporating all previous historical versions docs
val buildLatestVersion by tasks.registering
val latestStdlib = createStdLibVersionedDocTask(latestVersion, true)
val latestReflect = createKotlinReflectVersionedDocTask(latestVersion, true)
val latestTest = createKotlinTestVersionedDocTask(latestVersion, true)
val latestAll = createAllLibsVersionedDocTask(latestVersion, true, latestStdlib, latestReflect, latestTest)
buildLatestVersion.configure { dependsOn(latestStdlib, latestTest, latestReflect, latestAll) }
versions.forEach { version ->
val versionStdlib = createStdLibVersionedDocTask(version, false)
val versionReflect = createKotlinReflectVersionedDocTask(version, false)
val versionTest = createKotlinTestVersionedDocTask(version, false)
val versionAll = createAllLibsVersionedDocTask(version, isLatest = false, versionStdlib, versionReflect, versionTest)
if (version != latestVersion) {
latestAll.configure { dependsOn(versionAll) }
}
buildAllVersions.configure { dependsOn(versionStdlib, versionTest, versionAll) }
}
}