forked from FabricMC/fabric-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
501 lines (417 loc) · 12.8 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
import net.fabricmc.loom.build.nesting.JarNester
import org.slf4j.LoggerFactory
buildscript {
dependencies {
classpath 'org.kohsuke:github-api:1.135'
classpath 'com.guardsquare:proguard-gradle:' + (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_11) ? '7.4.0-beta02' : '7.1.0')
}
}
plugins {
id 'java'
id 'java-library'
id 'eclipse'
id 'maven-publish'
// id 'checkstyle'
id 'com.diffplug.spotless' version "6.22.0"
id 'fabric-loom' version '1.4-SNAPSHOT' apply false
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'me.modmuss50.remotesign' version "0.4.0"
}
base {
archivesName = "fabric-loader"
}
def ENV = System.getenv()
allprojects {
apply plugin: 'java-library'
apply plugin: 'eclipse'
//apply plugin: 'checkstyle'
apply plugin: "com.diffplug.spotless"
def constantsSource = rootProject.file("src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java").text
version = (constantsSource =~ /\s+VERSION\s*=\s*"(.*)";/)[0][1] + (ENV.GITHUB_ACTIONS ? "" : "+local")
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral() {
content {
// Force ASM and ME to come from the fabric maven.
// This ensures that the version has been mirrored for use by the launcher/installer.
excludeGroupByRegex "org.ow2.asm"
excludeGroupByRegex "io.github.llamalad7"
}
}
}
dependencies {
compileOnly 'org.jetbrains:annotations:23.0.0'
}
}
sourceSets {
main {
java.srcDirs = ['src/main/java', 'src/main/legacyJava']
}
}
configurations {
include {
transitive = false
}
implementation {
extendsFrom include
}
installer {
transitive = false
}
installerLaunchWrapper {
transitive = false
extendsFrom installer
}
development {
transitive = false
}
api {
extendsFrom installer
extendsFrom development
}
}
repositories {
maven {
name = 'Mojang'
url = 'https://libraries.minecraft.net/'
content {
includeGroup "net.minecraft"
}
}
}
dependencies {
// fabric-loader dependencies
installer "org.ow2.asm:asm:${project.asm_version}"
installer "org.ow2.asm:asm-analysis:${project.asm_version}"
installer "org.ow2.asm:asm-commons:${project.asm_version}"
installer "org.ow2.asm:asm-tree:${project.asm_version}"
installer "org.ow2.asm:asm-util:${project.asm_version}"
installer "net.fabricmc:sponge-mixin:${project.mixin_version}"
installerLaunchWrapper "net.minecraft:launchwrapper:1.12"
// impl dependencies
include 'org.ow2.sat4j:org.ow2.sat4j.core:2.3.6'
include 'org.ow2.sat4j:org.ow2.sat4j.pb:2.3.6'
include "net.fabricmc:tiny-remapper:0.10.1"
include "net.fabricmc:access-widener:2.1.0"
include ('net.fabricmc:mapping-io:0.5.0') {
// Mapping-io depends on ASM, dont bundle
transitive = false
}
development "io.github.llamalad7:mixinextras-fabric:$mixin_extras_version"
testCompileOnly 'org.jetbrains:annotations:23.0.0'
// Unit testing for mod metadata
testImplementation('org.junit.jupiter:junit-jupiter:5.9.2')
testRuntimeOnly('org.junit.platform:junit-platform-launcher')
}
apply from: rootProject.file('gradle/installer-json.gradle')
apply from: rootProject.file('gradle/launcher.gradle')
processResources {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
java {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
jar {
enabled = false
// Set the classifier to fix gradle task validation confusion.
archiveClassifier = "disabled"
}
test {
useJUnitPlatform()
}
shadowJar {
// Has stupid defaults, make our own
enabled = false
}
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
// Renaming in the shadow jar task doesnt seem to work, so do it here
task getSat4jAbout(type: Copy) {
dependsOn project.configurations.include
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from {
configurations.include.collect {
zipTree(it).matching {
include 'about.html'
}
}
}
rename 'about.html', 'net/fabricmc/loader/impl/lib/sat4j/about-sat4j.html'
into layout.buildDirectory.dir("sat4j")
}
tasks.getByName("build").dependsOn("distZip")
task copyLibraries(type: Copy){
dependsOn "fatJar"
delete(layout.buildDirectory.dir("packed"))
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
layout.buildDirectory.dir("libs/").collect {
def files = it.get().asFileTree.files
for (final def f in files) {
if (f.name.contains "fat"){
from f.toPath().toAbsolutePath().toString()
}
}
}
configurations.runtimeClasspath.each {
from it.toPath().toAbsolutePath().toString()
}
into layout.buildDirectory.dir("packed/libs")
}
def startBatContent = [
"@echo off",
"@rem Set your velocity jar name into system property fabric.systemLibraryExclusion",
"java \"-Dfabric.systemLibraryExclusion=velocity-3.3.0-SNAPSHOT-371.jar\" \"-Dfabric.debug.disableClassPathIsolation\" -cp \"./libs/*\" net.fabricmc.loader.impl.launch.knot.KnotServer\n",
"pause"
]
def startShContent = [
"#!/bin/sh",
"java \"-Dfabric.systemLibraryExclusion=velocity-3.3.0-SNAPSHOT-371.jar\" \"-Dfabric.debug.disableClassPathIsolation\" -cp \"./libs/*\" net.fabricmc.loader.impl.launch.knot.KnotServer\n"
]
tasks.register("generateStartScript"){
dependsOn "copyLibraries"
doLast {
def startBat = layout.buildDirectory.dir("packed").get().file("start.bat")
def startShellScript = layout.buildDirectory.dir("packed").get().file("start.sh")
startBat.asFile.write(startBatContent.join("\n"))
startShellScript.asFile.write(startShContent.join("\n"))
copy {
from layout.projectDirectory.file("README.md")
into layout.buildDirectory.dir("packed")
}
}
}
task distZip(type: Zip){
dependsOn "generateStartScript"
archiveBaseName = "${project.name}-${project.version}-packed"
destinationDirectory = layout.buildDirectory.dir("dist")
from layout.buildDirectory.dir("packed")
}
task fatJar(type: ShadowJar, dependsOn: getSat4jAbout) {
from sourceSets.main.output
from project(":velocity").sourceSets.main.output
from getSat4jAbout.destinationDir
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}"}
}
manifest {
attributes (
'Main-Class': 'net.fabricmc.loader.impl.launch.server.FabricServerLauncher',
'Fabric-Loom-Remap': 'false',
'Automatic-Module-Name': 'net.fabricmc.loader'
)
}
archiveClassifier = "fat"
configurations = [project.configurations.include]
relocate 'org.sat4j', 'net.fabricmc.loader.impl.lib.sat4j'
relocate 'net.fabricmc.accesswidener', 'net.fabricmc.loader.impl.lib.accesswidener'
relocate 'net.fabricmc.tinyremapper', 'net.fabricmc.loader.impl.lib.tinyremapper'
relocate 'net.fabricmc.mappingio', 'net.fabricmc.loader.impl.lib.mappingio'
exclude 'about.html'
exclude 'sat4j.version'
exclude 'META-INF/maven/org.ow2.sat4j/*/**'
exclude 'META-INF/*.RSA'
exclude 'META-INF/*.SF'
doLast {
JarNester.nestJars(project.configurations.development.files, archiveFile.get().asFile, LoggerFactory.getLogger("JiJ"))
}
outputs.upToDateWhen { false }
}
File proguardFile = file("build/libs/fabric-loader-${version}.jar")
import proguard.gradle.ProGuardTask
task proguardJar(type: ProGuardTask, dependsOn: fatJar) {
def classpath = project(":velocity").configurations.compileClasspath
inputs.files(fatJar, classpath)
outputs.files(proguardFile)
doFirst {
classpath.resolve().forEach {
libraryjars it
}
}
libraryjars JavaVersion.current().java9Compatible ? "${System.getProperty('java.home')}/jmods" : "${System.getProperty('java.home')}/lib/rt.jar"
injars fatJar.archiveFile
outjars proguardFile
configuration file("proguard.conf")
}
build.dependsOn proguardJar
tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
sourcesJar {
from sourceSets.main.allSource
from project(":velocity").sourceSets.main.allSource
}
// useful for creating test mod jar
task testJar(type: Jar) {
archiveClassifier = "test"
from sourceSets.test.output
}
task copyJson() {
def inJson = file('src/main/resources/fabric-installer.json')
def inLwJson = file('src/main/resources/fabric-installer.launchwrapper.json')
def outJson = file("build/libs/${project.base.archivesName.get()}-${version}.json")
def outLwJson = file("build/libs/${project.base.archivesName.get()}-${version}.launchwrapper.json")
inputs.files (inJson, inLwJson)
outputs.files(outJson, outLwJson)
doLast {
outJson.text = inJson.text
outLwJson.text = inLwJson.text
}
}
tasks.build.dependsOn "copyJson"
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used.
// We'll use that if it's available, but otherwise we'll use the older option.
if (JavaVersion.current().isJava9Compatible()) {
it.options.release = 8
}
}
javadoc {
options {
if (file("README.html").exists()) {
overview = "README.html"
}
source = "8"
encoding = 'UTF-8'
charSet = 'UTF-8'
memberLevel = JavadocMemberLevel.PACKAGE
links(
'https://asm.ow2.io/javadoc/',
'https://docs.oracle.com/javase/8/docs/api/',
'https://logging.apache.org/log4j/2.x/javadoc/log4j-api/'
)
// Disable the crazy super-strict doclint tool in Java 8
addStringOption('Xdoclint:none', '-quiet')
}
source sourceSets.main.allJava.srcDirs
classpath = sourceSets.main.compileClasspath + sourceSets.main.output // compile impl stuff for dep as well
include("**/api/**")
// workaround as one of the api stuff use that package
failOnError false
}
task javadocJar(type: Jar) {
dependsOn javadoc
from javadoc.destinationDir
archiveClassifier = 'javadoc'
}
build.dependsOn javadocJar
allprojects {
// checkstyle {
// configFile = project.rootProject.file("checkstyle.xml")
// toolVersion = '8.44'
// }
spotless {
java {
licenseHeaderFile(rootProject.file("HEADER"))
targetExclude '**/lib/gson/*.java'
}
}
}
// Causes more trouble than its worth
tasks.withType(GenerateModuleMetadata) {
enabled = false
}
def signingEnabled = ENV.SIGNING_SERVER
File proguardFileSigned = null
if (signingEnabled) {
proguardFileSigned = file("build/libs/fabric-loader-${version}-signed.jar")
remoteSign {
requestUrl = ENV.SIGNING_SERVER
pgpAuthKey = ENV.SIGNING_PGP_KEY
jarAuthKey = ENV.SIGNING_JAR_KEY
sign(proguardFile, proguardFileSigned, "proguard").configure {
dependsOn proguardJar
}
afterEvaluate {
sign publishing.publications.mavenJava
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(signingEnabled ? proguardFileSigned : proguardFile) {
builtBy(signingEnabled ? signProguard : proguardJar)
classifier = null
}
artifact(sourcesJar)
artifact javadocJar
artifact(file('src/main/resources/fabric-installer.json')) {
builtBy copyJson
}
artifact(file('src/main/resources/fabric-installer.launchwrapper.json')) {
builtBy copyJson
classifier = "launchwrapper"
}
}
}
// select the repositories you want to publish to
repositories {
// if (ENV.MAVEN_URL) {
// maven {
// name "RemoteMaven"
// url ENV.MAVEN_URL
// credentials {
// username ENV.MAVEN_USERNAME
// password ENV.MAVEN_PASSWORD
// }
// }
// }
maven {
name = "NekoMavenRelease"
url = uri("https://maven.takeneko.icu/releases")
credentials {
username = project.findProperty("nekomaven.user") as String ?: System.getenv("NEKO_USERNAME")
password = project.findProperty("nekomaven.password") as String ?: System.getenv("NEKO_TOKEN")
}
}
}
}
def getBranch() {
def ENV = System.getenv()
if (ENV.GITHUB_REF) {
def branch = ENV.GITHUB_REF
return branch.substring(branch.lastIndexOf("/") + 1)
}
return "unknown"
}
import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub
task github(dependsOn: publish) {
onlyIf {
ENV.GITHUB_TOKEN
}
doLast {
def github = GitHub.connectUsingOAuth(ENV.GITHUB_TOKEN as String)
def repository = github.getRepository(ENV.GITHUB_REPOSITORY)
def releaseBuilder = new GHReleaseBuilder(repository, version as String)
releaseBuilder.name("Fabric Loader $version")
releaseBuilder.body(ENV.CHANGELOG ?: "No changelog provided")
releaseBuilder.commitish(getBranch())
releaseBuilder.prerelease(false)
releaseBuilder.create()
}
}
// A task to ensure that the version being released has not already been released.
task checkVersion {
doFirst {
def xml = new URL("https://maven.fabricmc.net/net/fabricmc/fabric-loader/maven-metadata.xml").text
def metadata = new XmlSlurper().parseText(xml)
def versions = metadata.versioning.versions.version*.text();
if (versions.contains(version)) {
throw new RuntimeException("${version} has already been released!")
}
}
}
publish.mustRunAfter checkVersion
github.mustRunAfter checkVersion