forked from Thorfusion/Mekanism-Community-Edition
-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.gradle
488 lines (425 loc) · 17 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
/**
* It is advised that you do not edit anything in the build.gradle; unless you are sure of what you are doing
*/
import com.gtnewhorizons.retrofuturagradle.mcp.InjectTagsTask
import org.jetbrains.changelog.Changelog
import org.jetbrains.gradle.ext.Gradle
plugins {
id 'java'
id 'java-library'
id 'maven-publish'
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.7'
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.35'
id 'com.matthewprenger.cursegradle' version '1.4.0' apply false
id 'com.modrinth.minotaur' version '2.+' apply false
id 'org.jetbrains.changelog' version '2.2.0'
id 'eclipse'
id 'idea'
}
apply from: 'gradle/scripts/helpers.gradle'
// Early Assertions
assertProperty 'mod_version'
assertProperty 'root_package'
assertProperty 'mod_id'
assertProperty 'mod_name'
assertSubProperties 'use_tags', 'tag_class_name'
assertSubProperties 'use_access_transformer', 'access_transformer_locations'
assertSubProperties 'use_mixins', 'mixin_booter_version', 'mixin_refmap'
assertSubProperties 'is_coremod', 'coremod_includes_mod', 'coremod_plugin_class_name'
assertSubProperties 'use_asset_mover', 'asset_mover_version'
setDefaultProperty 'use_modern_java_syntax', false, false
setDefaultProperty 'generate_sources_jar', true, false
setDefaultProperty 'generate_javadocs_jar', true, false
setDefaultProperty 'mapping_channel', true, 'stable'
setDefaultProperty 'mapping_version', true, '39'
setDefaultProperty 'use_dependency_at_files', true, true
setDefaultProperty 'minecraft_username', true, 'Developer'
setDefaultProperty 'extra_jvm_args', false, ''
setDefaultProperty 'extra_tweak_classes', false, ''
setDefaultProperty 'change_minecraft_sources', false, false
version = propertyString('mod_version')
group = propertyString('root_package')
base {
archivesName.set(propertyString('mod_name') + "-All")
}
tasks.decompressDecompiledSources.enabled !propertyBool('change_minecraft_sources')
defaultTasks 'fullBuild'
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(propertyBool('use_modern_java_syntax') ? 17 : 8))
// Azul covers the most platforms for Java 8 toolchains, crucially including MacOS arm64
vendor.set(JvmVendorSpec.AZUL)
}
if (propertyBool('generate_sources_jar')) {
withSourcesJar()
}
if (propertyBool('generate_javadocs_jar')) {
withJavadocJar()
}
}
configurations {
embed
implementation.extendsFrom(embed)
}
minecraft {
mcVersion.set('1.12.2')
mcpMappingChannel.set(propertyString('mapping_channel'))
mcpMappingVersion.set(propertyString('mapping_version'))
useDependencyAccessTransformers.set(propertyBool('use_dependency_at_files'))
username.set(propertyString('minecraft_username'))
// Add any additional tweaker classes here
extraTweakClasses.addAll(propertyStringList('extra_tweak_classes'))
// Add various JVM arguments here for runtime
def args = ['-ea:' + group]
if (propertyBool('use_mixins')) {
args << '-Dmixin.hotSwap=true'
args << '-Dmixin.checks.interfaces=true'
args << '-Dmixin.debug.export=true'
}
extraRunJvmArguments.addAll(args)
extraRunJvmArguments.addAll(propertyStringList('extra_jvm_args'))
if (propertyBool('use_tags')) {
if (file('tags.properties').exists()) {
Properties props = new Properties().tap { it.load(file('tags.properties').newInputStream()); it }
if (!props.isEmpty()) {
injectedTags.set(props.collectEntries { k, v -> [(k): interpolate(v)] })
}
}
}
}
repositories {
maven {
name 'CleanroomMC Maven'
url 'https://maven.cleanroommc.com'
}
}
dependencies {
if (propertyBool('use_modern_java_syntax')) {
annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0'
// Workaround for https://github.com/bsideup/jabel/issues/174
annotationProcessor 'net.java.dev.jna:jna-platform:5.13.0'
compileOnly('com.github.bsideup.jabel:jabel-javac-plugin:1.0.0') {
transitive = false
}
// Allow jdk.unsupported classes like sun.misc.Unsafe, workaround for JDK-8206937 and fixes crashes in tests
patchedMinecraft 'me.eigenraven.java8unsupported:java-8-unsupported-shim:1.0.0'
// Include for tests
testAnnotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0'
testCompileOnly('com.github.bsideup.jabel:jabel-javac-plugin:1.0.0') {
transitive = false // We only care about the 1 annotation class
}
}
if (propertyBool('use_asset_mover')) {
implementation "com.cleanroommc:assetmover:${propertyString('asset_mover_version')}"
}
if (propertyBool('use_mixins')) {
String mixin = modUtils.enableMixins("zone.rong:mixinbooter:${propertyString('mixin_booter_version')}", propertyString('mixin_refmap'))
api(mixin) {
transitive = false
}
annotationProcessor 'org.ow2.asm:asm-debug-all:5.2'
annotationProcessor 'com.google.guava:guava:24.1.1-jre'
annotationProcessor 'com.google.code.gson:gson:2.8.6'
annotationProcessor(mixin) {
transitive = false
}
}
if (propertyBool('enable_junit_testing')) {
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.1'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
}
apply from: 'gradle/scripts/dependencies.gradle'
// Adds Access Transformer files to tasks
if (propertyBool('use_access_transformer')) {
for (def location : propertyStringList('access_transformer_locations')) {
def fileLocation = file("${projectDir}/src/main/resources/${location}")
if (fileLocation.exists()) {
tasks.deobfuscateMergedJarToSrg.accessTransformerFiles.from(fileLocation)
tasks.srgifyBinpatchedJar.accessTransformerFiles.from(fileLocation)
} else {
throw new GradleException("Access Transformer file [$fileLocation] does not exist!")
}
}
}
processResources {
def filterList = ['mcmod.info', 'pack.mcmeta']
filterList.addAll(propertyStringList('mixin_configs').collect(config -> "mixins.${config}.json" as String))
filesMatching(filterList) { fcd ->
fcd.expand(
'mod_id': propertyString('mod_id'),
'mod_name': propertyString('mod_name'),
'mod_version': propertyString('mod_version'),
'mod_description': propertyString('mod_description'),
'mod_authors': "[${propertyStringList('mod_authors', ',').join(', ')}]",
'mod_credits': propertyString('mod_credits'),
'mod_url': propertyString('mod_url'),
'mod_update_json': propertyString('mod_update_json'),
'mod_logo_path': propertyString('mod_logo_path'),
'mixin_refmap': propertyString('mixin_refmap'),
'mixin_package': propertyString('mixin_package')
)
}
if (propertyBool('use_access_transformer')) {
rename '(.+_at.cfg)', 'META-INF/$1'
}
}
jar {
manifest {
def attribute_map = [:]
if (propertyBool('is_coremod')) {
attribute_map['FMLCorePlugin'] = propertyString('coremod_plugin_class_name')
if (propertyBool('coremod_includes_mod')) {
attribute_map['FMLCorePluginContainsFMLMod'] = true
def currentTasks = gradle.startParameter.taskNames
if (currentTasks[0] == 'build' || currentTasks[0] == 'prepareObfModsFolder' || currentTasks[0] == 'runObfClient') {
attribute_map['ForceLoadAsMod'] = true
}
}
}
if (propertyBool('use_access_transformer')) {
attribute_map['FMLAT'] = propertyString('access_transformer_locations')
}
attributes(attribute_map)
}
// Add all embedded dependencies into the jar
from(provider { configurations.embed.collect { it.isDirectory() ? it : zipTree(it) } })
}
idea {
module {
inheritOutputDirs = true
}
project {
settings {
runConfigurations {
"1. Run Client"(Gradle) {
taskNames = ["runClient"]
}
"2. Run Server"(Gradle) {
taskNames = ["runServer"]
}
"3. Run Obfuscated Client"(Gradle) {
taskNames = ["runObfClient"]
}
"4. Run Obfuscated Server"(Gradle) {
taskNames = ["runObfServer"]
}
"5. Build"(Gradle) {
taskNames = ["build --info"]
}
}
compiler.javac {
afterEvaluate {
javacAdditionalOptions = "-encoding utf8"
moduleJavacAdditionalOptions = [
(project.name + ".main"): tasks.compileJava.options.compilerArgs.collect { '"' + it + '"' }.join(' ')
]
}
}
}
}
}
compileTestJava {
sourceCompatibility = targetCompatibility = 8
}
test {
useJUnitPlatform()
javaLauncher.set(javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(8)
})
if (propertyBool('show_testing_output')) {
testLogging {
showStandardStreams = true
}
}
}
String parserChangelog() {
if (!file('CHANGELOG.md').exists()) {
throw new GradleException('publish_with_changelog is true, but CHANGELOG.md does not exist in the workspace!')
}
String parsedChangelog = changelog.renderItem(
changelog.get(propertyString('mod_version')).withHeader(false).withEmptySections(false),
Changelog.OutputType.MARKDOWN)
if (parsedChangelog.isEmpty()) {
throw new GradleException('publish_with_changelog is true, but the changelog for the latest version is empty!')
}
return parsedChangelog
}
tasks.register('generateMixinJson') {
group 'cleanroom helpers'
def missingConfig = propertyStringList('mixin_configs').findAll(config -> !file("src/main/resources/mixins.${config}.json").exists())
onlyIf {
if (propertyBool('use_mixins') && propertyBool('generate_mixins_json')) {
return !missingConfig.empty
}
return false
}
doLast {
for (String mixinConfig : missingConfig) {
def file = file("src/main/resources/mixins.${mixinConfig}.json")
file << """{\n\t"package": "",\n\t"required": true,\n\t"refmap": "${mixin_refmap}",\n\t"target": "@env(DEFAULT)",\n\t"minVersion": "0.8.5",\n\t"compatibilityLevel": "JAVA_8",\n\t"mixins": [],\n\t"server": [],\n\t"client": []\n}"""
}
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
if (propertyBool('use_modern_java_syntax')) {
if (it.name in ['compileMcLauncherJava', 'compilePatchedMcJava']) {
return
}
sourceCompatibility = 17
options.release.set(8)
javaCompiler.set(javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(17))
vendor.set(JvmVendorSpec.AZUL)
})
}
}
tasks.register('cleanroomAfterSync') {
group 'cleanroom helpers'
dependsOn 'injectTags', 'generateMixinJson'
}
if (propertyBool('use_modern_java_syntax')) {
tasks.withType(Javadoc).configureEach {
sourceCompatibility = 17
}
}
tasks.named('injectTags', InjectTagsTask).configure {
onlyIf {
return propertyBool('use_tags') && !it.getTags().get().isEmpty()
}
it.outputClassName.set(propertyString('tag_class_name'))
}
tasks.named('prepareObfModsFolder').configure {
finalizedBy 'prioritizeCoremods'
}
tasks.register('prioritizeCoremods') {
dependsOn 'prepareObfModsFolder'
doLast {
fileTree('run/obfuscated').forEach {
if (it.isFile() && it.name =~ '(mixinbooter|configanytime)(-)([0-9])+\\.+([0-9])+(.jar)') {
it.renameTo(new File(it.parentFile, "!${it.name}"))
}
}
}
}
idea.project.settings {
taskTriggers {
afterSync 'cleanroomAfterSync'
}
}
apply from: 'gradle/scripts/publishing.gradle'
apply from: 'gradle/scripts/extra.gradle'
tasks.register('coreJar', Jar) {
archiveFileName = "Mekanism-CE-Unofficial-${project.version}.jar"
dependsOn 'reobfJar'
archiveClassifier = "core"
manifest {
def attribute_map = [:]
if (propertyBool('is_coremod')) {
attribute_map['FMLCorePlugin'] = propertyString('coremod_plugin_class_name')
if (propertyBool('coremod_includes_mod')) {
attribute_map['FMLCorePluginContainsFMLMod'] = true
}
}
if (propertyBool('use_access_transformer')) {
attribute_map['FMLAT'] = propertyString('access_transformer_locations')
}
attributes(attribute_map)
}
from('etc/core') {
include '*.info'
expand 'mod_id': project.property('mod_id'),
'mod_name': project.property('mod_name'),
'mod_version': project.property('mod_version'),
'mod_description': project.property('mod_description'),
'mod_authors': project.property('mod_authors'),
'mod_credits': project.property('mod_credits'),
'mod_url': project.property('mod_url'),
'mod_update_json': project.property('mod_update_json'),
'mod_logo_path': project.property('mod_logo_path')
}
from zipTree(reobfJar.outputs.getFiles().getSingleFile()).matching {
exclude 'mekanism/tools/**', 'mekanism/generators/**', 'mekanism/multiblockmachine/**', 'assets/mekanismtools/**', 'assets/mekanismmultiblockmachine/**', 'assets/mekanismgenerators/**','mcmod.info'
}
}
tasks.register('toolsJar', Jar) {
archiveFileName = "Mekanism-CE-Unofficial-Tools-${project.version}.jar"
dependsOn 'reobfJar'
archiveClassifier = "tools"
from('etc/tools') {
include '*.info'
expand 'mod_id': project.property('mod_id'),
'mod_name': project.property('mod_name'),
'mod_version': project.property('mod_version'),
'mod_description': project.property('mod_description'),
'mod_authors': project.property('mod_authors'),
'mod_credits': project.property('mod_credits'),
'mod_url': project.property('mod_url'),
'mod_update_json': project.property('mod_update_json'),
'mod_logo_path': project.property('mod_logo_path')
}
from zipTree(reobfJar.outputs.getFiles().getSingleFile()).matching {
include 'mekanism/tools/**', 'assets/mekanismtools/**'
}
}
tasks.register('generatorsJar', Jar) {
archiveFileName = "Mekanism-CE-Unofficial-Generators-${project.version}.jar"
dependsOn 'reobfJar'
archiveClassifier = "generators"
from('etc/generators') {
include '*.info'
expand 'mod_id': project.property('mod_id'),
'mod_name': project.property('mod_name'),
'mod_version': project.property('mod_version'),
'mod_description': project.property('mod_description'),
'mod_authors': project.property('mod_authors'),
'mod_credits': project.property('mod_credits'),
'mod_url': project.property('mod_url'),
'mod_update_json': project.property('mod_update_json'),
'mod_logo_path': project.property('mod_logo_path')
}
from zipTree(reobfJar.outputs.getFiles().getSingleFile()).matching {
include 'mekanism/generators/**', 'assets/mekanismgenerators/**'
}
}
tasks.register('apiJar', Jar) {
archiveClassifier = "api"
archiveBaseName = "Mekanism-CE-Unofficial"
dependsOn "sourcesJar"
include 'mekanism/api/**'
from sourceSets.main.java.srcDirs
from sourceSets.main.output
}
tasks.register('multiblockmachineJar', Jar) {
archiveFileName = "Mekanism-CE-Unofficial-Multiblock-Machine-${project.version}.jar"
dependsOn 'reobfJar'
archiveClassifier = "multiblockmachine"
from('etc/multiblockmachine') {
include '*.info'
expand 'mod_id': project.property('mod_id'),
'mod_name': project.property('mod_name'),
'mod_version': project.property('mod_version'),
'mod_description': project.property('mod_description'),
'mod_authors': project.property('mod_authors'),
'mod_credits': project.property('mod_credits'),
'mod_url': project.property('mod_url'),
'mod_update_json': project.property('mod_update_json'),
'mod_logo_path': project.property('mod_logo_path')
}
from zipTree(reobfJar.outputs.getFiles().getSingleFile()).matching {
include 'mekanism/multiblockmachine/**', 'assets/mekanismmultiblockmachine/**'
}
}
tasks.register('fullBuild', Delete) {
delete jar
dependsOn("build")
}
artifacts {
archives jar
archives apiJar
archives coreJar
archives toolsJar
archives generatorsJar
archives multiblockmachineJar
}