forked from FabricMC/fabric-loader
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
386 lines (317 loc) · 9.39 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
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 = "iris-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 to come from the fabric maven.
// This ensures that the ASM version has been mirrored for use by the launcher/installer.
excludeGroupByRegex "org.ow2.asm"
}
}
}
}
sourceSets {
main {
java.srcDirs = ['src/main/java', 'src/main/legacyJava']
}
}
configurations {
include
implementation {
extendsFrom include
}
}
dependencies {
// fabric-loader dependencies
api "org.ow2.asm:asm:${project.asm_version}"
api "org.ow2.asm:asm-analysis:${project.asm_version}"
api "org.ow2.asm:asm-commons:${project.asm_version}"
api "org.ow2.asm:asm-tree:${project.asm_version}"
api "org.ow2.asm:asm-util:${project.asm_version}"
api("net.fabricmc:sponge-mixin:${project.mixin_version}") {
exclude module: 'launchwrapper'
exclude module: 'guava'
}
api 'net.fabricmc:tiny-mappings-parser:0.3.0+build.17'
api 'net.fabricmc:tiny-remapper:0.8.2'
api 'net.fabricmc:access-widener:2.1.0'
include 'org.ow2.sat4j:org.ow2.sat4j.core:2.3.6'
include 'org.ow2.sat4j:org.ow2.sat4j.pb:2.3.6'
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')
}
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")
}
task fatJar(type: ShadowJar, dependsOn: getSat4jAbout) {
from sourceSets.main.output
from project(":minecraft").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'
exclude 'about.html'
exclude 'sat4j.version'
exclude 'META-INF/maven/org.ow2.sat4j/*/**'
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(":minecraft").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(":minecraft").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/log4j-api/apidocs/'
)
// 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 {
url ENV.MAVEN_URL
credentials {
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
}
}
}
}
}
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