forked from Virtuoel/Pehkui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
508 lines (416 loc) · 13.9 KB
/
build.gradle
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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
plugins {
id "fabric-loom" version "1.0.+"
id "eclipse"
id "maven-publish"
id "com.github.breadmoirai.github-release" version "2.4.1"
id "io.github.juuxel.loom-quiltflower" version "1.8.0"
id "com.matthewprenger.cursegradle" version "1.4.0"
id "com.modrinth.minotaur" version "2.+"
}
repositories {
mavenLocal()
maven {
name = "Fabric"
url = "https://maven.fabricmc.net/"
}
maven {
name = "TerraformersMC"
url = "https://maven.terraformersmc.com/"
}
maven {
name = "CurseForge"
url = "https://minecraft.curseforge.com/api/maven"
}
maven {
name = "JitPack"
url = "https://jitpack.io"
content {
includeGroup "com.github.Virtuoel"
}
}
maven {
name = "GitHub"
url = "https://maven.pkg.github.com"
}
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
def ENV = System.getenv()
TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
group = project.maven_group
archivesBaseName = project.archives_base_name
version = project.mod_version + "+" + (ENV.BUILD_NUMBER ? "build.${ENV.BUILD_NUMBER}-" : "") + (project.hasProperty("metadata_minecraft_versions") ? project.metadata_minecraft_versions : project.minecraft_version)
if(project.hasProperty("forge_version")) {
version += "-forge"
loom {
forge {
mixinConfig "${archives_base_name.replaceAll( /([A-Z])/, /_$1/ ).toLowerCase().replaceAll( /^_/, '' )}.mixins.json"
}
}
}
else {
loom {
def access_widener_file = file("src/main/resources/${archives_base_name.replaceAll( /([A-Z])/, /_$1/ ).toLowerCase().replaceAll( /^_/, '' )}.accesswidener");
if (access_widener_file.exists()) {
accessWidenerPath = access_widener_file
}
}
}
loom {
mixin {
defaultRefmapName = "${archives_base_name}-refmap.json"
}
}
quiltflower {
addToRuntimeClasspath = !project.hasProperty("forge_version")
preferences {
ind = "\t"
}
}
if(project.hasProperty("loader_version")) {
ext.fabric_loader_version = project.loader_version
}
if(project.hasProperty("fabric_version")) {
ext.fabric_api_version = project.fabric_version
}
dependencies {
minecraft "com.mojang:minecraft:${minecraft_version}"
if(!project.yarn_mappings.contains(", ")) {
mappings "net.fabricmc:yarn:${yarn_mappings}:v2"
}
else {
mappings loom.layered {
project.yarn_mappings.split(", ").each { String mapping ->
mappings "net.fabricmc:yarn:${mapping}:v2"
}
}
}
if(project.hasProperty("forge_version")) {
forge "net.minecraftforge:forge:${forge_version}"
}
else if(project.hasProperty("fabric_loader_version")) {
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
def excludeLoader = { exclude group: "net.fabricmc", module: "fabric-loader" }
def excludeApi = { exclude group: "net.fabricmc.fabric-api" }
def excludeFabric = {
exclude group: "net.fabricmc", module: "fabric-loader"
exclude group: "net.fabricmc.fabric-api"
}
if(project.hasProperty("fabric_api_version")) {
if(!project.hasProperty("fabric_modules") && !project.hasProperty("api_fabric_modules") && !project.hasProperty("impl_fabric_modules")) {
modCompileOnly "net.fabricmc.fabric-api:fabric-api:${fabric_api_version}", excludeLoader
modLocalRuntime "net.fabricmc.fabric-api:fabric-api:${fabric_api_version}", excludeLoader
}
if(project.hasProperty("fabric_modules")) {
project.fabric_modules.split(", ").each { String module ->
modCompileOnly fabricApi.module(module, project.fabric_api_version), excludeLoader
modLocalRuntime fabricApi.module(module, project.fabric_api_version), excludeLoader
}
}
if(project.hasProperty("api_fabric_modules")) {
project.api_fabric_modules.split(", ").each { String module ->
modApi fabricApi.module(module, project.fabric_api_version), excludeLoader
}
}
if(project.hasProperty("impl_fabric_modules")) {
project.impl_fabric_modules.split(", ").each { String module ->
modImplementation fabricApi.module(module, project.fabric_api_version), excludeLoader
}
}
if(project.hasProperty("included_fabric_modules")) {
project.included_fabric_modules.split(", ").each { String module ->
include fabricApi.module(module, project.fabric_api_version)
}
}
}
if(project.hasProperty("modmenu_version")) {
modCompileOnly "com.terraformersmc:modmenu:${modmenu_version}", excludeFabric
modLocalRuntime "com.terraformersmc:modmenu:${modmenu_version}", excludeFabric
}
if(project.hasProperty("kanos_config_tag")) {
include modApi("com.github.Virtuoel:KanosConfig:${kanos_config_tag}", excludeFabric)
}
}
}
processResources {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
filesMatching("META-INF/mods.toml") {
expand "file": [ jarVersion: project.version ]
}
}
def proj = project
eclipse {
project {
name = archives_base_name
buildCommand "org.eclipse.buildship.core.gradleprojectbuilder"
natures "org.eclipse.buildship.core.gradleprojectnature"
}
if(!proj.hasProperty("forge_version")) {
jdt {
javaRuntimeName = "JavaSE-17"
}
}
else {
def minor = (minecraft_version.split(/\./, -1)[1] as Integer);
jdt {
javaRuntimeName = "JavaSE-${minor >= 18 ? 17 : minor >= 17 ? 16 : 1.8}"
}
}
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
java {
withSourcesJar()
}
jar {
from "LICENSE"
manifest
{
attributes "Implementation-Title": project.archivesBaseName
attributes "Implementation-Version": project.version
attributes "Maven-Artifact": "${project.group}:${project.archivesBaseName}:${project.version}"
attributes "Built-On-Minecraft": "${project.minecraft_version}"
attributes "Built-On-Java": "${System.getProperty("java.vm.version")} (${System.getProperty("java.vm.vendor")})"
}
}
tasks.named("sourcesJar") {
exclude "fabric.mod.json"
exclude "META-INF/mods.toml"
manifest
{
attributes "Implementation-Title": project.archivesBaseName + "-sources"
attributes "Implementation-Version": project.version
attributes "Maven-Artifact": "${project.group}:${project.archivesBaseName}:${project.version}:sources"
attributes "Built-On-Minecraft": "${project.minecraft_version}"
attributes "Built-On-Java": "${System.getProperty("java.vm.version")} (${System.getProperty("java.vm.vendor")})"
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
mavenLocal()
if(project.hasProperty("maven_repo") && project.hasProperty("maven_username") && project.hasProperty("maven_password")) {
maven {
url = project.maven_repo
credentials {
username project.maven_username
password project.maven_password
}
}
}
}
}
if(project.hasProperty("fabric_api_version")) {
ext.changelog_fabric_api_version = project.fabric_api_version
}
String generateHTMLChangelog() {
String changelog_text = ""
File file = file("changelog.txt")
if(file.exists())
{
file.eachLine { String line ->
if(!line.isAllWhitespace())
{
changelog_text += "<p>${line.stripIndent()}</p>\n"
}
}
changelog_text += "<p> </p>\n"
}
changelog_text += "<p>Last successfully tested on:</p>\n"
changelog_text += "<p>Minecraft version <code>${minecraft_version}</code></p>\n"
if(project.hasProperty("forge_version")) {
changelog_text += "<p>Forge <code>${forge_version}</code></p>\n"
}
if(project.hasProperty("fabric_loader_version")) {
changelog_text += "<p>Fabric Loader <code>${fabric_loader_version}</code></p>\n"
}
changelog_text += "<p>Yarn mappings <code>${yarn_mappings}</code></p>\n"
if(project.hasProperty("changelog_fabric_api_version")) {
changelog_text += "<p><a href=\"https://www.curseforge.com/minecraft/mc-mods/fabric-api/files/all\" rel=\"nofollow\">Fabric API <code>${changelog_fabric_api_version}</code></a></p>\n"
}
return changelog_text
}
String generateMarkdownChangelog() {
String changelog_text = ""
File file = file("changelog.txt")
if(file.exists())
{
file.eachLine { String line ->
if(!line.isAllWhitespace())
{
changelog_text += "${line.stripIndent()} \n"
}
}
changelog_text += " \n"
}
changelog_text += "Last successfully tested on: \n"
changelog_text += "Minecraft version " + '`' + "${minecraft_version}" + '`' + " \n"
if(project.hasProperty("forge_version")) {
changelog_text += "Forge " + '`' + "${forge_version}" + '`' + " \n"
}
if(project.hasProperty("fabric_loader_version")) {
changelog_text += "Fabric Loader " + '`' + "${fabric_loader_version}" + '`' + " \n"
}
changelog_text += "Yarn mappings " + '`' + "${yarn_mappings}" + '`' + " \n"
if(project.hasProperty("changelog_fabric_api_version")) {
changelog_text += "[Fabric API " + '`' + "${changelog_fabric_api_version}" + '`' + "](https://modrinth.com/mod/fabric-api/versions) \n"
}
return changelog_text
}
githubRelease {
token project.hasProperty("github_releases_token") ? project.github_releases_token : ""
if(project.hasProperty("github_repository_owner")) {
owner project.github_repository_owner
}
if(project.hasProperty("github_repository")) {
repo project.github_repository
}
if(project.hasProperty("forge_version")) {
tagName "${project.mod_version}-${project.minecraft_version}-forge"
}
if(project.hasProperty("fabric_loader_version")) {
tagName project.mod_version
}
if(project.hasProperty("github_branch")) {
targetCommitish project.github_branch
}
body generateMarkdownChangelog()
overwrite true
releaseName project.version
releaseAssets = files("${project.buildDir}/libs/${archivesBaseName}-${version}.jar", "${project.buildDir}/libs/${archivesBaseName}-${version}-sources.jar").files
}
tasks.named("githubRelease") {
dependsOn remapJar
dependsOn remapSourcesJar
}
curseforge {
if(project.hasProperty("curseforge_api_key")) {
apiKey = project.properties.curseforge_api_key
}
if(project.hasProperty("curseforge_id")) {
project {
id = project.curseforge_id
releaseType = project.curseforge_release_type
if(project.hasProperty("curseforge_mod_loaders")) {
project.curseforge_mod_loaders.split(", ").each { String loader ->
addGameVersion loader
}
}
def display_name_prefix = ""
if(project.hasProperty("curseforge_release_versions")) {
def game_versions = project.curseforge_release_versions.split(", ")
display_name_prefix = "[${game_versions[0]} - ${game_versions[-1].split("-")[0]}] "
if(game_versions[0] == game_versions[-1].split("-")[0]) {
display_name_prefix = "[${game_versions[0]}] "
}
game_versions.each { String gameVersion ->
addGameVersion gameVersion
}
}
if(project.hasProperty("forge_version")) {
display_name_prefix += "[Forge] "
}
mainArtifact(remapJar) {
displayName = "${display_name_prefix}${archives_base_name} ${project.mod_version}"
if(project.hasProperty("curseforge_required_dep_slugs") || project.hasProperty("curseforge_embedded_lib_slugs") || project.hasProperty("curseforge_optional_dep_slugs") || project.hasProperty("curseforge_compatible_tool_slugs") || project.hasProperty("curseforge_incompatible_slugs")) {
relations {
if(project.hasProperty("curseforge_required_dep_slugs")) {
project.curseforge_required_dep_slugs.split(", ").each { String slug ->
requiredDependency slug
}
}
if(project.hasProperty("curseforge_embedded_lib_slugs")) {
project.curseforge_embedded_lib_slugs.split(", ").each { String slug ->
embeddedLibrary slug
}
}
if(project.hasProperty("curseforge_optional_dep_slugs")) {
project.curseforge_optional_dep_slugs.split(", ").each { String slug ->
optionalDependency slug
}
}
if(project.hasProperty("curseforge_compatible_tool_slugs")) {
project.curseforge_compatible_tool_slugs.split(", ").each { String slug ->
tool slug
}
}
if(project.hasProperty("curseforge_incompatible_slugs")) {
project.curseforge_incompatible_slugs.split(", ").each { String slug ->
incompatible slug
}
}
}
}
changelogType = "html"
changelog = project.generateHTMLChangelog()
}
addArtifact(sourcesJar) {
displayName = "${archives_base_name} ${project.mod_version} Source Code"
}
}
options {
forgeGradleIntegration = false
}
}
}
if(project.hasProperty("curseforge_id")) {
afterEvaluate {
tasks.named("curseforge${project.curseforge_id}") {
dependsOn remapJar
dependsOn remapSourcesJar
}
}
}
import com.modrinth.minotaur.dependencies.ModDependency
modrinth {
if(project.hasProperty("modrinth_token")) {
token = project.properties.modrinth_token
}
if(project.hasProperty("modrinth_id")) {
projectId = project.modrinth_id
versionType = project.modrinth_version_type
if(project.hasProperty("modrinth_mod_loaders")) {
loaders = project.modrinth_mod_loaders.split(", ") as List
}
if(project.hasProperty("modrinth_release_versions")) {
gameVersions = project.modrinth_release_versions.split(", ") as List
}
def deps = []
if(project.hasProperty("modrinth_required_dep_ids")) {
project.modrinth_required_dep_ids.split(", ").each { String slug ->
deps << new ModDependency(slug, "required")
}
}
if(project.hasProperty("modrinth_optional_dep_ids")) {
project.modrinth_optional_dep_ids.split(", ").each { String slug ->
deps << new ModDependency(slug, "optional")
}
}
if(project.hasProperty("modrinth_incompatible_dep_ids")) {
project.modrinth_incompatible_dep_ids.split(", ").each { String slug ->
deps << new ModDependency(slug, "incompatible")
}
}
dependencies = deps
versionName = "${archives_base_name} ${project.mod_version}"
versionNumber = project.version
changelog = generateMarkdownChangelog()
uploadFile = remapJar
}
}
tasks.named("modrinth") {
dependsOn remapJar
dependsOn remapSourcesJar
}