-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
243 lines (221 loc) · 8.51 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
243 lines (221 loc) · 8.51 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
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
import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub
import java.nio.file.Files
buildscript {
dependencies {
classpath("org.kohsuke:github-api:1.135")
}
repositories {
mavenCentral()
}
}
plugins {
alias(libs.plugins.loom)
alias(libs.plugins.minotaur)
java
`maven-publish`
}
val lwjglNatives = resolveLwjglNatives()
val modVersion: String = "${providers.gradleProperty("mod_version").get()}+${libs.versions.bta.get()}"
val modGroup: Provider<String> = providers.gradleProperty("mod_group")
val modName: Provider<String> = providers.gradleProperty("mod_name")
val javaVersion: Provider<Int> = libs.versions.java.map { it.toInt() }
base.archivesName = modName
group = modGroup.get()
version = modVersion
loom {
val btaChannel = libs.versions.btaChannel.get()
val btaVersion = (if (btaChannel == "nightly") "" else "v") + libs.versions.bta.get()
customMinecraftMetadata.set("https://downloads.betterthanadventure.net/bta-client/${btaChannel}/${btaVersion}/manifest.json")
}
repositories {
mavenCentral()
maven("https://maven.fabricmc.net/") { name = "Fabric" }
maven("https://maven.thesignalumproject.net/infrastructure") { name = "SignalumMavenInfrastructure" }
maven("https://maven.thesignalumproject.net/nightly") { name = "signalumMavenNightly" }
maven("https://maven.thesignalumproject.net/releases") { name = "SignalumMavenReleases" }
ivy("https://piston-data.mojang.com") {
patternLayout { artifact("v1/[organisation]/[revision]/[module].jar") }
metadataSources { artifact() }
}
}
dependencies {
minecraft("::${libs.versions.bta.get()}")
// Required at compilation & runtime
// included in builds as a runtime dependency
implementation(libs.loader)
// Only required at compilation
// provides documentation, can be removed if that isn't needed
compileOnly(libs.bundles.btaLwjgl)
compileOnly(libs.joml)
compileOnly(libs.joml.primitives)
compileOnly(libs.slf4jApi)
compileOnly(libs.jspecify)
compileOnly(libs.errorprone)
// Only required for development/launch at runtime, won't be part of any builds
runtimeClasspath(libs.clientJar)
localRuntime(libs.modMenu) // Optional, can be removed
val lwjglVer = libs.versions.lwjgl.get()
localRuntime(platform("org.lwjgl:lwjgl-bom:${lwjglVer}"))
localRuntime("org.lwjgl:lwjgl::$lwjglNatives")
localRuntime("org.lwjgl:lwjgl-glfw::$lwjglNatives")
localRuntime("org.lwjgl:lwjgl-openal::$lwjglNatives")
localRuntime("org.lwjgl:lwjgl-opengl::$lwjglNatives")
localRuntime("org.lwjgl:lwjgl-stb::$lwjglNatives")
}
java {
toolchain {
languageVersion = javaVersion.map { JavaLanguageVersion.of(it) }
vendor = JvmVendorSpec.ADOPTIUM
}
sourceCompatibility = JavaVersion.toVersion(javaVersion.get())
targetCompatibility = JavaVersion.toVersion(javaVersion.get())
withSourcesJar()
}
val licenseFile = run {
val rootLicense = layout.projectDirectory.file("LICENSE")
val parentLicense = layout.projectDirectory.file("../LICENSE")
when {
rootLicense.asFile.exists() -> {
logger.lifecycle("Using LICENSE from project root: {}", rootLicense.asFile)
rootLicense
}
parentLicense.asFile.exists() -> {
logger.lifecycle("Using LICENSE from parent directory: {}", parentLicense.asFile)
parentLicense
}
else -> {
logger.warn("No LICENSE file found in project or parent directory.")
null
}
}
}
tasks {
withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
sourceCompatibility = javaVersion.get().toString()
targetCompatibility = javaVersion.get().toString()
if (javaVersion.get() > 8) options.release = javaVersion
}
withType<UpdateDaemonJvm>().configureEach {
languageVersion = libs.versions.gradleJava.map { JavaLanguageVersion.of(it.toInt()) }
vendor = JvmVendorSpec.ADOPTIUM
}
withType<JavaExec>().configureEach { defaultCharacterEncoding = "UTF-8" }
withType<Javadoc>().configureEach { options.encoding = "UTF-8" }
withType<Test>().configureEach { defaultCharacterEncoding = "UTF-8" }
withType<Jar>().configureEach {
licenseFile?.let {
from(it) {
rename { original -> "${original}_${archiveBaseName.get()}" }
}
}
}
processResources {
val resourceMap = mapOf(
"version" to modVersion,
"fabricloader" to libs.versions.loader.get(),
"java" to libs.versions.java.get(),
"modmenu" to libs.versions.modMenu.get()
)
// This is needed for gradle to recognize changes
// made to expanded files
inputs.properties(resourceMap)
duplicatesStrategy = DuplicatesStrategy.INCLUDE
with(copySpec {
from("src/main/resources/") {
include("fabric.mod.json")
include("*.mixins.json")
expand(resourceMap)
}
})
}
}
// Removes all outdated manifest.json dependencies
configurations.configureEach {
exclude(group = "org.lwjgl.lwjgl")
exclude(group = "net.java.jutils")
exclude(group = "net.java.jinput")
exclude(group = "net.sf.jopt-simple")
exclude(group = "net.minecraft", module = "launchwrapper")
}
publishing {
repositories {
maven("https://maven.thesignalumproject.net/releases") {
name = "signalumMaven"
credentials(PasswordCredentials::class)
authentication {
create<BasicAuthentication>("basic")
}
}
}
publications {
create<MavenPublication>("maven") {
groupId = modGroup.get()
artifactId = modName.get()
version = modVersion
from(components["java"])
}
}
}
val modrinthToken: Provider<String> = providers.gradleProperty("modrinthToken")
val githubToken: Provider<String> = providers.gradleProperty("turnipLabsGithubToken")
if (modrinthToken.isPresent) {
modrinth {
token = modrinthToken
projectId = "halplibe"
versionName = "HalpLibe $modVersion"
versionNumber = modVersion
versionType = "release"
uploadFile.set(tasks.jar)
additionalFiles = listOf(tasks.named("sourcesJar"))
gameVersions.add("b1.7.3")
loaders.add("bta-babric")
changelog = Files.readString(rootProject.projectDir.toPath().resolve("CHANGELOG.md"))
}
}
fun resolveLwjglNatives(): String { // Sourced from https://www.lwjgl.org/
return Pair(
System.getProperty("os.name")!!,
System.getProperty("os.arch")!!
).let { (name, arch) ->
when {
arrayOf("Linux", "SunOS", "Unit").any { name.startsWith(it) } ->
if (arrayOf("arm", "aarch64").any { arch.startsWith(it) })
"natives-linux${if (arch.contains("64") || arch.startsWith("armv8")) "-arm64" else "-arm32"}"
else
"natives-linux"
arrayOf("Mac OS X", "Darwin").any { name.startsWith(it) } ->
"natives-macos${if (arch.startsWith("aarch64")) "-arm64" else ""}"
arrayOf("Windows").any { name.startsWith(it) } ->
if (arch.contains("64"))
"natives-windows${if (arch.startsWith("aarch64")) "-arm64" else ""}"
else
"natives-windows-x86"
else ->
throw Error("Unrecognized or unsupported platform. Please set \"lwjglNatives\" manually")
}
}
}
if(githubToken.isPresent){
tasks.register("github") {
doLast {
val v = providers.gradleProperty("mod_version").get()
val github = GitHub.connectUsingOAuth(githubToken.get())
val repository = github.getRepository("Turnip-Labs/bta-halplibe")
val releaseBuilder = GHReleaseBuilder(repository, "v$v")
releaseBuilder.name("HalpLibe $v")
releaseBuilder.body(Files.readString(rootProject.projectDir.toPath().resolve("CHANGELOG.md")))
releaseBuilder.commitish("8.0")
val release = releaseBuilder.create()
release.uploadAsset(
project.file(tasks.named("jar").get().outputs.files.singleFile),
"application/java-archive"
)
release.uploadAsset(
project.file(tasks.named("sourcesJar").get().outputs.files.singleFile),
"application/java-archive"
)
}
}
}