forked from MartinTheDragon/Nuclear-Tech-Mod-Remake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
407 lines (347 loc) · 16.3 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
import org.codehaus.groovy.runtime.GStringImpl
buildscript {
repositories {
maven { url = 'https://maven.minecraftforge.net' }
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id 'com.github.johnrengelman.shadow' version '7.1.2'
id "maven-publish"
}
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'kotlin'
// apply plugin: 'eclipse'
apply plugin: 'idea'
apply from: '.scripts/properties-reader.gradle'
if (project.hasProperty("release")) project.ext.mod_version = "$mod_version_major.$mod_version_api.$mod_version_minor.$mod_version_patch" as GStringImpl
else project.ext.mod_version = "$mod_version_major.$mod_version_api.$mod_version_minor.${mod_version_patch.toInteger() + 1}-snapshot${new Date().format("yyyyMMdd'T'HHmmss")}" as GStringImpl // snapshots are always one patch higher than the current release
version = "$minecraft_version-$mod_version" as Object
group = 'at.martinthedragon'
archivesBaseName = "$modid"
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
println("Mod version: ${project.version}")
sourceSets {
api {
resources.srcDirs = []
}
main {
resources {
include '**/**'
srcDirs += 'src/datagen/generated/resources'
exclude '.cache'
}
compileClasspath += api.output
runtimeClasspath += api.output
}
datagen {
java.srcDirs = ['src/datagen/main/java'] // so java doesn't create a new folder outside
kotlin.srcDirs = ['src/datagen/main/kotlin']
resources.srcDirs = ['src/datagen/main/resources']
compileClasspath += api.output + main.output
}
}
minecraft {
mappings channel: 'official', version: "$minecraft_version"
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
runs {
client {
workingDirectory file("run")
// for getting tokens, see https://gist.github.com/50ap5ud5/beebcf056cbdd3c922cc8993689428f4#approach-1---use-minecraft-instance
if (project.localProperties != null &&
project.localProperties.containsKey('dev.auth.uuid') &&
project.localProperties.containsKey('dev.auth.token') &&
project.localProperties.containsKey('dev.auth.username') &&
project.localProperties.containsKey('dev.auth.type')
) {
println("Setting Minecraft authentication for " + project.localProperties.get('dev.auth.username'))
args('--uuid', project.localProperties.get('dev.auth.uuid'), '--accessToken', project.localProperties.get('dev.auth.token'), '--username', project.localProperties.get('dev.auth.username'), '--userType', project.localProperties.get('dev.auth.type'))
}
property 'forge.logging.console.level', 'debug'
property 'mixin.env.remapRefMap', 'true'
property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"
// you'll have to use JetBrains Runtime to get anything out of this
// see http://hotswapagent.org/mydoc_quickstart-jdk17.html
// for use with hotswap agent, use the following arguments: -XX:+AllowEnhancedClassRedefinition,-XX:HotswapAgent=fatjar,-Xlog:redefine+class*=info
// don't forget to regenerate run configs when changing arguments
if (project.localProperties != null && project.localProperties.containsKey('jvm.args')) {
jvmArgs(project.localProperties.get('jvm.args').split(','))
}
mods {
nucleartech {
sources((SourceSet[]) [sourceSets.main, sourceSets.api])
}
}
}
server {
workingDirectory file("run")
property 'forge.logging.console.level', 'debug'
property 'mixin.env.remapRefMap', 'true'
property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"
// you'll have to use JetBrains Runtime to get anything out of this
// see http://hotswapagent.org/mydoc_quickstart-jdk17.html
// for use with hotswap agent, use the following arguments: -XX:+AllowEnhancedClassRedefinition,-XX:HotswapAgent=fatjar,-Xlog:redefine+class*=info
// don't forget to regenerate run configs when changing arguments
if (project.localProperties != null && project.localProperties.containsKey('jvm.args')) {
jvmArgs(project.localProperties.get('jvm.args').split(','))
}
mods {
nucleartech {
sources((SourceSet[]) [sourceSets.main, sourceSets.api])
}
}
}
data {
workingDirectory file("run")
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
property 'forge.logging.console.level', 'debug'
property 'mixin.env.remapRefMap', 'true'
property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
args '--mod', "$modid", '--all', '--output', file('src/datagen/generated/resources/'), '--existing', file('src/main/resources/')
mods {
nucleartech {
sources((SourceSet[]) [sourceSets.main, sourceSets.api, sourceSets.datagen])
}
}
}
}
}
minecraft.runs.all {
lazyToken("minecraft_classpath") {
configurations.library.copyRecursive().resolve()
.collect { it.absolutePath }
//.findAll { !it.contains("org.jetbrains\\annotations\\13.0") && !it.contains("org.jetbrains/annotations/13.0") } // somewhat inelegantly remove duplicate
.join(File.pathSeparator)
}
}
repositories {
maven {
// location of the maven that hosts JEI files
name = "Progwml6 maven"
url = "https://dvs1.progwml6.com/files/maven/"
}
maven {
// location of a maven mirror for JEI files, as a fallback
name = "ModMaven"
url = "https://modmaven.k-4u.nl"
}
maven { url 'https://modmaven.dev/' }
maven { url "https://maven.shedaniel.me" }
mavenCentral()
}
configurations {
library // workaround for IDE runtime
implementation.extendsFrom library
apiImplementation.extendsFrom(implementation)
datagenImplementation.extendsFrom(implementation)
datagenCompileOnly.extendsFrom(compileOnly)
datagenRuntimeOnly.extendsFrom(runtimeOnly)
}
dependencies {
minecraft "net.minecraftforge:forge:$minecraft_version-$forge_version"
library ("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version") {
exclude group: 'org.jetbrains', module: 'annotations'
}
// reload gradle and run genIntellijRuns (or eclipse) after changing
def devModeREI = project.localProperties != null && project.localProperties.containsKey('dev.mode.rei') && Boolean.valueOf(project.localProperties.get("dev.mode.rei"))
println("Currently running integration for ${devModeREI ? "REI" : "JEI"}")
compileOnly fg.deobf("mezz.jei:jei-$minecraft_version:$jei_version:api")
compileOnly fg.deobf("me.shedaniel:RoughlyEnoughItems-api-forge:$rei_version")
compileOnly fg.deobf("me.shedaniel:RoughlyEnoughItems-default-plugin-forge:$rei_version")
if (devModeREI) {
implementation fg.deobf("me.shedaniel:RoughlyEnoughItems-forge:$rei_version")
implementation fg.deobf("me.shedaniel.cloth:cloth-config-forge:$cloth_config_version")
implementation fg.deobf("dev.architectury:architectury-forge:$architectury_version")
} else {
runtimeOnly fg.deobf("mezz.jei:jei-$minecraft_version:$jei_version")
}
// for testing compatibility
runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}")
runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}:additions")
runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}:generators")
runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}:tools")
datagenCompileOnly sourceSets.main.output
}
def manifestAttributes() {
return [
"Specification-Title": "Nuclear Tech Mod",
"Specification-Vendor": "MartinTheDragon",
"Specification-Version": project.mod_version,
"Implementation-Title": project.name,
"Implementation-Version": project.mod_version,
"Implementation-Vendor" :"MartinTheDragon",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
]
}
jar {
dependsOn(classes)
duplicatesStrategy(DuplicatesStrategy.INCLUDE) // is this bad? i dunno
from([sourceSets.api.output, sourceSets.main.output])
// configurations {shaded.extendsFrom library}
// from { configurations.shaded.collect() { it.isDirectory() ? it : zipTree(it) }}
archiveClassifier.set("slim")
manifest.attributes(manifestAttributes())
afterEvaluate { finalizedBy reobfJar }
}
shadowJar {
archiveClassifier.set("")
configurations = [project.configurations.library]
from([sourceSets.api.output, sourceSets.main.output])
def relocation = "${project.group}.relocated"
relocate "kotlin", "${relocation}.kotlin"
relocate "org.intellij", "${relocation}.intellij"
relocate "org.jetbrains", "${relocation}.jetbrains"
afterEvaluate { finalizedBy reobfShadowJar }
}
assemble.dependsOn shadowJar
// you have no idea how much pain and headaches getting this to work caused me
task sourcesJar(type: Jar, dependsOn: [classes, apiClasses]) {
duplicatesStrategy(DuplicatesStrategy.INCLUDE)
archiveClassifier.set("sources")
from([sourceSets.api.kotlin, sourceSets.main.kotlin])
manifest.attributes(manifestAttributes())
}
task apiJar(type: Jar) {
duplicatesStrategy(DuplicatesStrategy.INCLUDE)
archiveClassifier.set("api")
from sourceSets.api.output
manifest.attributes(manifestAttributes())
afterEvaluate { finalizedBy reobfApiJar }
}
artifacts {
archives apiJar
archives jar
}
reobf {
apiJar { classpath.from(sourceSets.api.compileClasspath) }
jar { classpath.from(sourceSets.main.compileClasspath) }
shadowJar {}
}
/*
opt-in=kotlin.RequiresOptIn - Enables usage of experimental APIs
jvm-default=all - Generates defaults in interfaces for Java users
lambdas=indy - Uses invokedynamic for lambdas instead of generating explicit classes
no-call-assertions - Disables not-null assertions on Platform types (when calling Java code)
no-param-assertions - Disables not-null assertions on method parameters given by Java code
use-fast-jar-file-system - Uses an experimental implementation for faster compilation
extended-compiler-checks - Gives some more information about things
*/
def kotlinCompilerArgs = ["-opt-in=kotlin.RequiresOptIn", "-Xjvm-default=all", "-Xlambdas=indy", "-Xno-call-assertions", "-Xno-param-assertions", "-Xuse-fast-jar-file-system"]
compileKotlin {
kotlinOptions {
jvmTarget = "17"
freeCompilerArgs += kotlinCompilerArgs
}
}
compileApiKotlin {
kotlinOptions {
jvmTarget = "17"
freeCompilerArgs += kotlinCompilerArgs + ["-Xexplicit-api=strict"]
}
}
compileDatagenKotlin {
kotlinOptions {
jvmTarget = "17"
freeCompilerArgs += kotlinCompilerArgs
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "17"
freeCompilerArgs += kotlinCompilerArgs
}
}
idea {
module {
excludeDirs += file("run")
}
}
// how shitty of an IDE plugin can you make for a language?
// i hate this
// i'm slowly becoming insane
publishing {
publications {
//noinspection GroovyAssignabilityCheck
maven(MavenPublication) {
//noinspection GroovyAssignabilityCheck
from components.java
//noinspection GroovyAssignabilityCheck
artifacts = [apiJar, jar, sourcesJar]
//noinspection GroovyAssignabilityCheck
artifactId = project.archivesBaseName
pom {
//noinspection GroovyAssignabilityCheck
name = "NuclearTechMod"
//noinspection GroovyAssignabilityCheck
packaging = "jar"
//noinspection GroovyAssignabilityCheck
description = "A Minecraft mod about nuclear machinery, bombs and other random things"
//noinspection GroovyAssignabilityCheck
url = "https://github.com/MartinTheDragon/Nuclear-Tech-Mod-Remake"
issueManagement {
//noinspection GroovyAssignabilityCheck
system = "github"
//noinspection GroovyAssignabilityCheck
url = "https://github.com/MartinTheDragon/Nuclear-Tech-Mod-Remake/issues"
}
licenses {
license {
//noinspection GroovyAssignabilityCheck
name = "LGPLv3"
//noinspection GroovyAssignabilityCheck
distribution = "repo"
//noinspection GroovyAssignabilityCheck
url = "https://www.gnu.org/licenses/lgpl-3.0"
}
}
developers {
developer {
//noinspection GroovyAssignabilityCheck
id = "MartinTheDragon"
//noinspection GroovyAssignabilityCheck
name = "Martin Alexander Prommegger"
}
}
scm {
//noinspection GroovyAssignabilityCheck
connection = "scm:git:git://github.com/MartinTheDragon/Nuclear-Tech-Mod-Remake.git"
//noinspection GroovyAssignabilityCheck
url = "https://github.com/MartinTheDragon/Nuclear-Tech-Mod-Remake"
}
// hacky way of modifying the dependencies, because the Gradle developers thought their bad and complicated solution was good enough: https://github.com/gradle/gradle/issues/10861
withXml {
def allDependencies = it.asNode().dependencies.'*'
// forge is always present
allDependencies.findAll {
it.artifactId.text() == "forge" && it.groupId.text() == "net.minecraftforge"
}.forEach() { it.parent().remove(it) }
// if the dependency is mapped, it means in our case that it's a mod we have integration for, which is optional
allDependencies.findAll {
it.version.text().contains("_mapped_")
}.each {
it.version.each { version ->
def versionString = version.text()
version.setValue(versionString.substring(0, versionString.indexOf("_mapped_")))
}
it.appendNode("optional", true)
}
}
}
}
}
}
// boo hoo, the class cannot be "applied" to withType, even though IT HAS A CLASS AS A PARAMETER
// WHY ARE INTELLIJ GROOVY INSPECTIONS SO EXTREMELY BAD
//noinspection GroovyAssignabilityCheck
tasks.withType(GenerateModuleMetadata) {
enabled = false // disable this, it causes more trouble than it's worth, because gradle apparently cannot follow the xml modifications we made for publishing
}