-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
177 lines (147 loc) · 3.59 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
import com.charleskorn.kaml.Yaml
import com.charleskorn.kaml.decodeFromStream
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import java.lang.System.getProperty
import java.lang.System.getenv
import java.net.URI
group = "net.eratiem"
version = "0.1-SNAPSHOT"
plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.kapt) apply false
alias(libs.plugins.shadow) apply false
idea
`maven-publish`
}
// ###############
// # Subprojects #
// ###############
subprojects {
group = rootProject.group
version = rootProject.version
apply {
plugin(rootProject.libs.plugins.kotlin.jvm.get().pluginId)
plugin(rootProject.libs.plugins.shadow.get().pluginId)
plugin("maven-publish")
}
tasks {
named<ShadowJar>("shadowJar") {
archiveBaseName = rootProject.name
archiveClassifier = [email protected] { it != "util" } ?: ""
dependencies {
exclude(dependency(rootProject.libs.kotlin.stdlib.get()))
}
}
}
}
// ###############
// # Maven Repos #
// ###############
buildscript {
dependencies {
classpath(libs.kotlinx.serialization.core)
classpath(libs.kaml)
}
repositories.mavenCentral()
}
val repoList = File("maven-repos.yml").takeIf(File::exists)?.inputStream()?.use { stream ->
Yaml.default.decodeFromStream<List<Map<String, String?>>>(stream).map {
MavenRepo(
it["name"]!!,
URI(it["url"]!!),
it["username"],
it["password"],
it["publish"]?.toBooleanStrictOrNull() ?: false
)
}
}
// ##############
// # Publishing #
// ##############
publishing {
repositories {
val isSnapshot = version.toString().contains("SNAPSHOT", true)
repoList?.filter { it.publish }
?.filter {
if (isSnapshot)
it.name.contains("SNAPSHOT", true)
else
!it.name.contains("SNAPSHOT", true)
}
?.forEach { createRepository(it) }
}
}
// ################
// # All Projects #
// ################
allprojects {
apply {
plugin("org.gradle.idea")
}
repositories {
repoList?.forEach { createRepository(it) }
}
tasks {
idea {
module {
isDownloadSources = true
isDownloadJavadoc = true
}
}
jar {
enabled = false
}
}
kotlin {
jvmToolchain(21)
}
}
// ###############
// # Source-Sets #
// ###############
sourceSets {
main {
java.setSrcDirs(listOf<String>())
kotlin.setSrcDirs(emptyList<String>())
resources.setSrcDirs(emptyList<String>())
}
test {
java.setSrcDirs(listOf<String>())
kotlin.setSrcDirs(emptyList<String>())
resources.setSrcDirs(emptyList<String>())
}
}
fun <T> getPropertyOrNull(key: String, castFun: String.() -> T) = try {
getProperty(key).castFun()
} catch (ex: Exception) {
println(ex)
null
}
fun <T> T.applyIf(condition: Boolean, block: T.() -> Unit) =
if (condition) {
apply { block() }
} else {
this
}
fun RepositoryHandler.createRepository(repo: MavenRepo) {
maven {
name = repo.name.replace(Regex("[^A-Za-z0-9_\\-. ]"), "").replace(Regex("\\s+"), "_")
url = repo.url
val envName = name.replace(Regex("\\."), "").uppercase()
val user = repo.username ?: getenv("${envName}_USERNAME")
val pass = repo.password ?: getenv("${envName}_PASSWORD")
if (!user.isNullOrBlank() || !pass.isNullOrBlank()) {
credentials {
if (!user.isNullOrBlank()) username = user
if (!pass.isNullOrBlank()) password = pass
}
}
}
}
data class MavenRepo(
val name: String,
val url: URI,
val username: String? = null,
val password: String? = null,
val publish: Boolean = false
)