This repository has been archived by the owner on Jul 20, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.gradle.kts
66 lines (57 loc) · 2.14 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
import org.jetbrains.kotlin.gradle.internal.ensureParentDirsCreated
import scanner.ScannerTask
import tasks.AddLibTask
plugins {
`javiersc-versioning`
`javiersc-all-projects`
`javiersc-changelog`
`javiersc-code-analysis`
`javiersc-docs`
id("org.jetbrains.kotlinx.binary-compatibility-validator")
`javiersc-nexus`
`javiersc-readme-badges-generator`
}
tasks {
withType<Test> {
maxParallelForks = Runtime.getRuntime().availableProcessors()
useJUnitPlatform()
useTestNG()
}
register<AddLibTask>("addLib")
register<ScannerTask>("mavenScan")
register("generateKotlinCatalog") {
doLast {
fun String.dotOrDashToCamelCase(): String =
replace("-", ".")
.fold("") { a, b -> a + if (a.lastOrNull() == '.') b.toUpperCase() else b }
.replace(".", "")
val libsTXTs: List<File> =
file("$buildDir/catalogs/").listFiles()?.toList().orEmpty().filter { file ->
file.isFile && file.extension == "txt"
}
val libs: List<String> = libsTXTs.flatMap { file -> file.readLines() }
val tomlLibs =
@OptIn(ExperimentalStdlibApi::class)
buildList {
add("[libraries]")
for (lib in libs) {
val first = lib.substringBefore(".")
val second =
lib.substringAfter(".").substringBefore(":").replace(".", "-")
val third =
lib.substringAfter(":")
.substringBeforeLast(":")
.dotOrDashToCamelCase()
val alias = "$first-$second-$third"
add("""$alias = "$lib"""")
}
}
.joinToString("\n")
file("$rootDir/kotlin-catalog/build/generated-catalog/libs.versions.toml").apply {
ensureParentDirsCreated()
createNewFile()
writeText(tomlLibs)
}
}
}
}