-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
187 lines (158 loc) · 6.25 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
187 lines (158 loc) · 6.25 KB
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
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.authentication.http.BasicAuthentication
plugins {
id("java")
id("java-library")
alias(libs.plugins.shadow)
alias(libs.plugins.sonatype.central.portal.publisher)
`maven-publish`
`signing`
}
val baseVersion = "0.1.0-platform.58"
val commitHash = System.getenv("COMMIT_HASH")
val isSnapshot = commitHash != null
// Kept for the Central Portal publisher, which still reads Gradle's removed
// archivesBaseName convention when running on Gradle 9.
extra["archivesBaseName"] = rootProject.name
fun devBuildId(): String {
val githubRunNumber = System.getenv("GITHUB_RUN_NUMBER")
val githubRunAttempt = System.getenv("GITHUB_RUN_ATTEMPT")
if (!githubRunNumber.isNullOrBlank()) {
return listOfNotNull(
githubRunNumber,
githubRunAttempt?.takeIf { it.isNotBlank() }
).joinToString(".")
}
return System.getenv("BUILD_NUMBER")
?: System.getenv("CI_PIPELINE_ID")
?: System.currentTimeMillis().toString()
}
val buildVersion = if (isSnapshot) "${baseVersion}-dev.${devBuildId()}-${commitHash}" else baseVersion
val modrinthVersion = baseVersion
require(modrinthVersion.length <= 32) {
"Modrinth version '$modrinthVersion' exceeds the 32-character limit"
}
extra["modrinthVersion"] = modrinthVersion
allprojects {
group = "app.simplecloud.api"
version = buildVersion
repositories {
mavenCentral()
mavenLocal()
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
maven("https://repo.papermc.io/repository/maven-public")
maven("https://repo.simplecloud.app/snapshots")
maven("https://buf.build/gen/maven")
}
}
tasks.named<ShadowJar>("shadowJar") {
enabled = false
}
subprojects {
apply(plugin = "java")
apply(plugin = "java-library")
apply(plugin = "maven-publish")
apply(plugin = "com.gradleup.shadow")
apply(plugin = "org.gradle.signing")
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}
if (project.path.startsWith(":platform:") && project.path != ":platform:shared") {
tasks.named<ShadowJar>("shadowJar") {
dependsOn(":api:shadowJar")
mergeServiceFiles()
// Relocate to match api module's shading (so references match at runtime)
relocate("io.nats", "app.simplecloud.api.shaded.nats")
relocate("com.google", "app.simplecloud.api.shaded.google") {
exclude("com.google.inject.**")
}
relocate("build.buf", "app.simplecloud.api.shaded.buf")
relocate("okhttp3", "app.simplecloud.api.shaded.okhttp3")
relocate("okio", "app.simplecloud.api.shaded.okio")
relocate("io.gsonfire", "app.simplecloud.api.shaded.gsonfire")
relocate("org.bouncycastle", "app.simplecloud.api.shaded.bouncycastle")
relocate("org.intellij", "app.simplecloud.api.shaded.intellij")
relocate("org.jetbrains", "app.simplecloud.api.shaded.jetbrains")
relocate("kotlin", "app.simplecloud.api.shaded.kotlin")
relocate("com.github.benmanes.caffeine", "app.simplecloud.api.shaded.caffeine")
relocate("google", "app.simplecloud.api.shaded.google")
relocate("native", "app.simplecloud.api.shaded.native")
relocate("core", "app.simplecloud.api.shaded.core")
exclude("META-INF/*.kotlin_module")
exclude("META-INF/proguard/**")
exclude("META-INF/versions/**")
archiveFileName.set("${rootProject.name}-${project.name}.jar")
}
}
publishing {
repositories {
maven {
name = "simplecloud"
url = uri("https://repo.simplecloud.app/snapshots/")
credentials {
username = System.getenv("SIMPLECLOUD_USERNAME")
password = System.getenv("SIMPLECLOUD_PASSWORD")
}
authentication {
create<BasicAuthentication>("basic")
}
}
}
// publications {
// create<MavenPublication>("maven") {
// from(components["java"])
// }
// }
}
// signing {
// if (!isSnapshot) {
// sign(publishing.publications["maven"])
// useGpgCmd()
// }
// }
}
tasks.register("buildTemplates") {
group = "build"
description = "Builds all platform JARs and copies them to run/templates structure"
val platformProjects = linkedMapOf(
"paper" to "plugins",
"folia" to "plugins",
"spigot" to "plugins",
"spigot-legacy" to "plugins",
"bungeecord" to "plugins",
"velocity" to "plugins",
"fabric" to "mods",
"neoforge" to "mods"
)
platformProjects.keys.forEach { platform ->
dependsOn(":platform:$platform:shadowJar")
}
doLast {
platformProjects.forEach { (platform, installDirectory) ->
val shadowJarTask = project(":platform:$platform").tasks.named<ShadowJar>("shadowJar").get()
val jarFile = shadowJarTask.archiveFile.get().asFile
val folderName = platform.removeSuffix("-legacy")
val templateDir = file("run/templates/_every/every_$folderName/$installDirectory")
templateDir.mkdirs()
val targetName = if (platform.endsWith("-legacy")) {
"${rootProject.name}-${platform}.jar.legacy"
} else {
"${rootProject.name}-${platform}.jar"
}
jarFile.copyTo(File(templateDir, targetName), overwrite = true)
println("Copied $jarFile to ${File(templateDir, targetName)}")
}
val waterfallDir = file("run/templates/_every/every_waterfall")
waterfallDir.deleteRecursively()
file("run/templates/_every/every_bungeecord").copyRecursively(waterfallDir)
println("Copied every_bungeecord to every_waterfall")
}
}
tasks.register<Zip>("zipTemplates") {
group = "build"
description = "Builds templates and creates a zip archive"
dependsOn("buildTemplates")
from("run/templates")
archiveFileName.set("templates.zip")
destinationDirectory.set(file("build"))
}