This repository has been archived by the owner on Dec 23, 2023. It is now read-only.
generated from CleanroomMC/TemplateDevEnv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
368 lines (322 loc) · 12.7 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
/**
* 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.gradle.ext.Gradle
import java.time.LocalDate
plugins {
id 'java'
id 'java-library'
id 'maven-publish'
id 'com.diffplug.spotless' version '6.19.0' apply false
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.7'
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.24'
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'
}
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 'spotless', 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_id'))
}
tasks.decompressDecompiledSources.enabled !propertyBool('change_minecraft_sources')
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(propertyBool('use_modern_java_syntax') ? 16 : 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('is_coremod')) {
args << '-Dfml.coreMods.load=' + propertyString('coremod_plugin_class_name')
}
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'
}
maven {
name 'BlameJared Maven'
url 'https://maven.blamejared.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
}
}
//APIs-2.8.3
implementation rfg.deobf("curse.maven:codechicken-lib-1-8-242818:2779848")
implementation rfg.deobf("curse.maven:gregtech-ce-unofficial-557242:4951281")
implementation rfg.deobf("curse.maven:gregicality-multiblocks-564858:4910674")
implementation rfg.deobf("curse.maven:gregtech-food-option-477021:4716101")
implementation rfg.deobf("curse.maven:ae2-extended-life-570458:4773115")
implementation rfg.deobf("curse.maven:artisan-worktables-284351:3205284")
runtimeOnly 'curse.maven:athenaeum-284350:4633750'
implementation 'mezz.jei:jei_1.12.2:4.16.1.302'
runtimeOnly 'curse.maven:top-245211:2667280'
compileOnly(rfg.deobf('CraftTweaker2:CraftTweaker2-API:4.1.20.684'))
compileOnly(rfg.deobf("curse.maven:ctm-267602:2915363"))
}
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("${projectDir}/src/main/resources/${location}")
tasks.srgifyBinpatchedJar.accessTransformerFiles.from("${projectDir}/src/main/resources/${location}")
} else {
throw new GradleException("Access Transformer file [$fileLocation] does not exist!")
}
}
}
processResources {
filesMatching(['mcmod.info', 'pack.mcmeta', 'mixins.*(?!refmap).*\\.json']) {
def authors = propertyString('mod_authors').split(',').collect { """\"${ it.trim() }\"""" }.join(', ')
expand(
'mod_id': propertyString('mod_id'),
'mod_name': propertyString('mod_name'),
'mod_version': propertyString('mod_version'),
'mod_description': propertyString('mod_description'),
'mod_authors': "[${authors}]",
'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"]
}
}
compiler.javac {
afterEvaluate {
javacAdditionalOptions = "-encoding utf8"
moduleJavacAdditionalOptions = [
(project.name + ".main"): tasks.compileJava.options.compilerArgs.collect { '"' + it + '"' }.join(' ')
]
}
}
}
}
}
compileTestJava {
sourceCompatibility = targetCompatibility = 8
}
test {
javaLauncher.set(javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(8)
})
}
changelog {
header.set("[${propertyString('mod_version')}] - ${LocalDate.now().format("yyyy-MM-dd")}")
headerParserRegex.set(~/(\d+\.\d+)/)
}
if (propertyBool('spotless')) {
apply plugin: 'com.diffplug.spotless'
// noinspection GroovyAssignabilityCheck
spotless {
encoding 'UTF-8'
format 'misc', {
target '.gitignore'
endWithNewline()
indentWithSpaces()
trimTrailingWhitespace()
}
java {
target 'src/main/java/**/*.java', 'src/test/java/**/*.java'
endWithNewline()
formatAnnotations()
importOrder()
indentWithSpaces()
removeUnusedImports()
toggleOffOn()
trimTrailingWhitespace()
if (propertyBool('cleanthat')) {
cleanthat().sourceCompatibility('1.8')
}
}
json {
target 'src/main/resources/**/*.json', 'src/test/resources/**/*.json'
simple().indentWithSpaces(6)
}
}
}
tasks.register('generateMixinJson') {
group 'cleanroom helpers'
onlyIf {
if (propertyBool('use_mixins') && propertyBool('generate_mixins_json')) {
return !file("src/main/resources/mixins.${propertyString('mod_id')}_early.json").exists()
}
return false
}
doLast {
def file = file("src/main/resources/mixins.${propertyString('mod_id')}_early.json")
file << """{\n\t"package": "\${mixin_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(16))
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'))
}
idea.project.settings {
taskTriggers {
afterSync 'cleanroomAfterSync'
}
}
apply from: 'gradle/scripts/publishing.gradle'
apply from: 'gradle/scripts/extra.gradle'