-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.gradle
More file actions
394 lines (346 loc) · 12.3 KB
/
Copy pathbuild.gradle
File metadata and controls
394 lines (346 loc) · 12.3 KB
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
import org.jetbrains.gradle.ext.Gradle
plugins {
id 'java'
id 'java-library'
id 'maven-publish'
id 'scala'
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.4.1'
id 'com.gradleup.shadow' version '9.4.0'
id 'xyz.wagyourtail.unimined' version '1.4.37-kappa'
id 'com.diffplug.spotless' version '8.4.0'
}
apply from: 'gradle/scripts/helpers.gradle'
private String gitOutput(List<String> args, String fallback) {
try {
def process = new ProcessBuilder(['git'] + args)
.directory(rootProject.projectDir)
.redirectErrorStream(true)
.start()
def stdout = process.inputStream.getText('UTF-8').trim()
if (process.waitFor() == 0 && !stdout.isEmpty()) {
return stdout
}
} catch (Exception ignored) {
// Fall through to the fallback for source archives or environments without git.
}
return fallback
}
private String defaultModVersion() {
def previousTag = gitOutput(['describe', '--tags', '--abbrev=0', '--exclude=dev'], '0.0.0')
if (previousTag.startsWith('v')) {
previousTag = previousTag.substring(1)
}
def shortHash = gitOutput(['rev-parse', '--short', 'HEAD'], 'unknown')
return "${previousTag}+${shortHash}"
}
if (!gradle.startParameter.projectProperties.containsKey('mod_version')) {
project.setProperty('mod_version', defaultModVersion())
}
// Early Assertions
assertProperty 'mod_version'
assertProperty 'root_package'
assertProperty 'mod_id'
assertProperty 'mod_name'
assertProperty 'legacy_ae_mod_id'
assertSubProperties 'use_lombok_ap', 'lombok_version'
assertSubProperties 'use_access_transformer', 'access_transformer_locations'
assertSubProperties 'is_coremod', 'coremod_includes_mod', 'coremod_plugin_class_name'
assertSubProperties 'use_asset_mover', 'asset_mover_version'
setDefaultProperty 'generate_sources_jar', true, false
setDefaultProperty 'generate_javadocs_jar', true, false
setDefaultProperty 'minecraft_username', true, 'Developer'
setDefaultProperty 'extra_jvm_args', false, ''
version = propertyString('mod_version')
group = propertyString('root_package')
base {
archivesName = propertyString('mod_id')
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
if (propertyBool('generate_sources_jar')) {
withSourcesJar()
}
if (propertyBool('generate_javadocs_jar')) {
withJavadocJar()
}
}
scala {
scalaVersion = '2.11.1'
}
configurations {
contain
implementation.extendsFrom(contain)
modCompileOnly
compileOnly.extendsFrom(modCompileOnly)
testCompileOnly.extendsFrom(compileOnly)
modRuntimeOnly
runtimeOnly.extendsFrom(modRuntimeOnly)
}
String remapTaskName = propertyBool('enable_shadow') ? "remapShadowJar" : "remapJar"
def gtceuMappingsJar = layout.projectDirectory.file(".gradle/unimined/local/mappings/srg2mcp.jar")
def gtceuMappingsSrg = layout.projectDirectory.file(".gradle/unimined/local/mappings/srg2mcp.tsrg")
def gtceuMappingsCsvDir = layout.buildDirectory.dir("gtceu/mcp-csv")
def prepareGtceuDevMappings = tasks.register("prepareGtceuDevMappings", Copy) {
from({ zipTree(gtceuMappingsJar.asFile) }) {
include "fields.csv", "methods.csv"
}
into(gtceuMappingsCsvDir)
}
tasks.matching { it.name == 'runClient' || it.name == 'runServer' }.configureEach {
dependsOn(prepareGtceuDevMappings)
}
repositories {
// Other repositories described by default:
// CleanroomMC: https://maven.cleanroommc.com
maven {
name = 'CurseMaven'
url = 'https://cursemaven.com'
}
maven {
name = 'CleanroomCurseMaven'
url = 'https://curse.cleanroommc.com'
}
maven {
name = 'Modrinth'
url = 'https://api.modrinth.com/maven'
}
maven {
name = "ModMaven"
url = uri("https://modmaven.dev/")
}
maven {
url = "https://maven.crystaelix.com/releases/"
}
mavenCentral()
mavenLocal()
maven { url 'https://jitpack.io' }
}
unimined.minecraft {
version "1.12.2"
mappings {
mcp("stable", "39-1.12")
}
cleanroom {
if (propertyBool('use_access_transformer')) {
accessTransformer "${rootProject.projectDir}/src/main/resources/${propertyString('access_transformer_locations')}"
}
loader "0.6.10-alpha"
runs.auth.username = minecraft_username
runs.all {
systemProperty("crl.dev.mixin", "${mod_id}.mixin.json")
systemProperty("net.minecraftforge.gradle.GradleStart.srg.notch-srg", gtceuMappingsSrg.asFile.absolutePath)
systemProperty("net.minecraftforge.gradle.GradleStart.csvDir", gtceuMappingsCsvDir.get().asFile.absolutePath)
def extraArgs = propertyString('extra_jvm_args')
if (extraArgs != null && !extraArgs.trim().isEmpty()) {
jvmArgs += extraArgs.split { "\\s+" }.toList()
}
systemProperty('mixin.debug.export', 'true')
if (propertyBool('enable_foundation_debug')) {
systemProperty("foundation.dump", "true")
systemProperty("foundation.verbose", "true")
}
if (propertyBool('is_coremod')) {
systemProperty("fml.coreMods.load", propertyString('coremod_plugin_class_name'))
}
return
}
}
defaultRemapJar = false
String jarTaskName = propertyBool('enable_shadow') ? "shadowJar" : "jar"
remap(tasks.named(jarTaskName).get()) {
mixinRemap {
enableBaseMixin()
enableMixinExtra()
}
}
mods {
remap(configurations.modCompileOnly)
remap(configurations.modRuntimeOnly)
}
}
dependencies {
if (propertyBool('use_lombok_ap')) {
compileOnly "org.projectlombok:lombok:${propertyString('lombok_version')}"
annotationProcessor "org.projectlombok:lombok:${propertyString('lombok_version')}"
testCompileOnly "org.projectlombok:lombok:${propertyString('lombok_version')}"
testAnnotationProcessor "org.projectlombok:lombok:${propertyString('lombok_version')}"
}
if (propertyBool('use_asset_mover')) {
implementation "com.cleanroommc:assetmover:${propertyString('asset_mover_version')}"
}
if (propertyBool('enable_junit_testing')) {
testImplementation 'org.junit.jupiter:junit-jupiter:6.0.3'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testRuntimeOnly 'com.google.code.gson:gson:2.10.1'
}
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
}
apply from: 'gradle/scripts/dependencies.gradle'
def generatedTagsSourceDir = layout.buildDirectory.dir('generated/sources/tags/java')
def generateTagsSource = tasks.register('generateTagsSource') {
def tagsPackage = "${propertyString('root_package')}.${propertyString('mod_id')}"
def outputFile = generatedTagsSourceDir.map {
it.file("${tagsPackage.replace('.', '/')}/Tags.java")
}
inputs.property('root_package', propertyString('root_package'))
inputs.property('mod_id', propertyString('mod_id'))
inputs.property('mod_name', propertyString('mod_name'))
inputs.property('mod_version', propertyString('mod_version'))
outputs.file(outputFile)
doLast {
def file = outputFile.get().asFile
file.parentFile.mkdirs()
file.text = """package ${tagsPackage};
public final class Tags {
public static final String MOD_ID = "${propertyString('mod_id')}";
public static final String MOD_NAME = "${propertyString('mod_name')}";
public static final String VERSION = "${propertyString('mod_version')}";
private Tags() {
}
}
"""
}
}
processResources {
rename '(.+_at.cfg)', 'META-INF/$1'
def legacyAeModId = propertyString('legacy_ae_mod_id')
def resourceProps = [
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', ',').collect { it.strip() }.join('", "'),
mod_credits : propertyString('mod_credits'),
mod_license : propertyString('mod_license'),
mod_url : propertyString('mod_url'),
mod_issue_tracker_url: propertyString('mod_issue_tracker_url'),
mod_update_json : propertyString('mod_update_json'),
mod_icon_item : propertyString('mod_icon_item'),
mod_logo_path : propertyString('mod_logo_path'),
mod_icon_path : propertyString('mod_icon_path'),
mod_background_path : propertyString('mod_background_path')
]
inputs.properties(resourceProps)
inputs.property('legacy_ae_mod_id', legacyAeModId)
filesMatching('mcmod.info') {
expand(resourceProps + [mod_id: legacyAeModId])
}
filesMatching('pack.mcmeta') {
expand(resourceProps)
}
}
sourceSets {
main {
java {
srcDir generatedTagsSourceDir
}
}
}
if (!propertyBool('enable_shadow')) {
shadowJar.enabled = false
}
compileJava {
dependsOn(generateTagsSource)
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_25
}
tasks.matching { it.name == 'sourcesJar' }.configureEach {
dependsOn(generateTagsSource)
}
jar {
archiveClassifier = 'dev'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
if (configurations.contain.size() > 0) {
into('/') {
from configurations.contain
}
}
doFirst {
manifest {
def attribute_map = [:]
attribute_map['ModType'] = "CRL"
attribute_map['MixinConfigs'] = "${mod_id}.mixin.json"
if (configurations.contain.size() > 0) {
attribute_map['ContainedDeps'] = configurations.contain.collect { it.name }.join(' ')
attribute_map['NonModDeps'] = true
}
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)
}
}
finalizedBy(tasks.named(remapTaskName).get())
}
shadowJar {
configurations = [project.configurations.shadow]
archiveClassifier = "shadow"
}
tasks.named(remapTaskName).configure {
doFirst {
logging.captureStandardOutput LogLevel.INFO
}
doLast {
logging.captureStandardOutput LogLevel.QUIET
}
}
idea {
module {
inheritOutputDirs = true
}
project {
settings {
runConfigurations {
"0. Apply Spotless"(Gradle) {
taskNames = ["spotlessApply"]
}
"1. Run Client"(Gradle) {
taskNames = ["runClient"]
}
"2. Run Server"(Gradle) {
taskNames = ["runServer"]
}
"3. Build Mod"(Gradle) {
taskNames = ["build"]
}
}
compiler.javac {
afterEvaluate {
javacAdditionalOptions = "-encoding utf8"
moduleJavacAdditionalOptions = [
(project.name + ".main"): tasks.compileJava.options.compilerArgs.collect { '"' + it + '"' }.join(' ')
]
}
}
}
}
}
compileTestJava {
classpath += compileJava.classpath
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_25
}
test {
classpath += compileJava.classpath
classpath = configurations.testRuntimeClasspath.filter { it.name == 'gson-2.10.1.jar' } + classpath
useJUnitPlatform()
javaLauncher.set(javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(25)
})
if (propertyBool('show_testing_output')) {
testLogging {
showStandardStreams = true
}
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
apply from: 'gradle/scripts/publishing.gradle'
apply from: 'gradle/scripts/extra.gradle'