forked from ReplayMod/ReplayMod
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbuild.gradle
348 lines (300 loc) · 12.9 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
buildscript {
def (major, minor, patch) = '1.16.4-forge'.tokenize('-')[0].tokenize('.')
def mcVersion = "${major}${minor.padLeft(2, '0')}${(patch ?: '').padLeft(2, '0')}" as int
def fabric = false
project.ext.mcVersion = mcVersion
project.ext.fabric = fabric
repositories {
mavenLocal()
mavenCentral()
maven { url = "https://plugins.gradle.org/m2/" }
maven { url = "https://files.minecraftforge.net/maven" }
maven { url='https://repo.spongepowered.org/repository/maven-public/' }
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url = "https://maven.tterrag.com/" }
maven { url = 'https://jitpack.io' }
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '4.1.+', changing: true
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0'
}
}
def mcVersionStr = "${(int)(mcVersion/10000)}.${(int)(mcVersion/100)%100}" + (mcVersion%100==0 ? '' : ".${mcVersion%100}")
// def jGui = project.evaluationDependsOn(":jGui:1.16.4-forge")
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'org.spongepowered.mixin'
ext {
mixinSrg = new File(project.buildDir, 'tmp/mixins/mixins.srg')
mixinRefMap = new File(project.buildDir, 'tmp/mixins/mixins.replaymod.refmap.json')
}
compileJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
options.compilerArgs += [
"-AoutSrgFile=${project.mixinSrg.canonicalPath}",
"-AoutRefMapFile=${project.mixinRefMap.canonicalPath}",
"-AreobfSrgFile=${project.file('build/mcp-srg.srg').canonicalPath}"
]
}
mixin {
add sourceSets.main, "mixins.replaymod.refmap.json"
}
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
version = project.name + '-' + rootProject.version
group= "com.replaymod"
archivesBaseName = "replaymod"
sourceSets {
main
api
integrationTest {
compileClasspath += main.runtimeClasspath + main.output
java {
srcDir file('src/integration-test/java')
}
resources.srcDir file('src/integration-test/resources')
}
}
minecraft {
runs {
client {
workingDirectory rootProject.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
property 'fml.earlyprogresswindow', 'false'
property 'mixin.env.disableRefMap', 'true'
arg '-mixin.config=mixins.replaymod.json'
mods {
replaymod {
source sourceSets.main
}
}
}
server {
workingDirectory rootProject.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
property 'mixin.env.disableRefMap', 'true'
arg '-mixin.config=mixins.replaymod.json'
mods {
replaymod {
source sourceSets.main
}
}
}
data {
workingDirectory rootProject.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
jvmArgs ['-Dfml.earlyprogresswindow=false']
args '--mod', 'replaymod', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
mods {
replaymod {
source sourceSets.main
}
}
}
}
mappings channel: 'snapshot', version: '20210309-1.16.4'
}
repositories {
mavenLocal()
maven { url "https://repo.spongepowered.org/maven/" }
maven {
url 'https://maven.terraformersmc.com/releases/'
content {
includeGroup 'com.terraformersmc'
}
}
maven {
url 'https://jitpack.io'
content {
includeGroupByRegex 'com\\.github\\..*'
}
}
}
configurations {
// Include dep in fat jar without relocation and, when forge supports it, without exploding (TODO)
shade
compile.extendsFrom shade
// Include dep in fat jar with relocation and minimization
shadow
compile.extendsFrom shadow
}
dependencies {
def mixinVersion = '0.8.2'
def shadeExclusions = {
// Cannot just add these to the shade configuration because they'd be inherited by the compile configuration then
exclude group: 'com.google.guava', module: 'guava-jdk5'
exclude group: 'com.google.guava', module: 'guava' // provided by MC
exclude group: 'com.google.code.gson', module: 'gson' // provided by MC
}
minecraft 'net.minecraftforge:forge:1.16.4-35.1.37'
annotationProcessor "org.spongepowered:mixin:$mixinVersion"
compileOnly "org.spongepowered:mixin:$mixinVersion"
shade("org.spongepowered:mixin:$mixinVersion") { transitive = false } // deps should all be bundled with MC
// Mixin needs these (and depends on them but for some reason that's not enough. FG, did you do that?)
annotationProcessor 'com.google.code.gson:gson:2.2.4'
annotationProcessor 'com.google.guava:guava:21.0'
annotationProcessor 'org.ow2.asm:asm-tree:6.2'
annotationProcessor 'org.apache.logging.log4j:log4j-core:2.0-beta9'
for (suffix in ['', ':natives-linux', ':natives-windows', ':natives-macos']) {
shadow('org.lwjgl:lwjgl-tinyexr:3.2.2' + suffix) {
exclude group: 'org.lwjgl', module: 'lwjgl' // comes with MC
}
}
shadow 'com.googlecode.mp4parser:isoparser:1.1.7'
shadow 'org.apache.commons:commons-exec:1.3'
shadow 'com.google.apis:google-api-services-youtube:v3-rev178-1.22.0', shadeExclusions
shadow 'com.google.api-client:google-api-client-gson:1.20.0', shadeExclusions
shadow 'com.google.api-client:google-api-client-java6:1.20.0', shadeExclusions
shadow 'com.google.oauth-client:google-oauth-client-jetty:1.20.0'
shadow 'com.github.javagl.JglTF:jgltf-model:3af6de4'
shadow 'org.aspectj:aspectjrt:1.8.2'
shadow 'com.github.ReplayMod.JavaBlend:2.79.0:a0696f8'
shadow "com.github.ReplayMod:ReplayStudio:a1f82a7"
shadow 'com.github.ReplayMod:lwjgl-utils:27dcd66'
// implementation(jGui){ transitive = false } // FG 1.2 puts all MC deps into the compile configuration and we don't want to shade those
testCompile 'junit:junit:4.11'
}
File configureRelocationOutput = new File(project.buildDir, 'configureRelocation')
task configureRelocation() {
dependsOn tasks.jar
dependsOn configurations.shadow
outputs.file(configureRelocationOutput)
doLast {
def pkgs = files(configurations.shadow).filter { it.exists() }.collect {
def tree = it.isDirectory() ? fileTree(it) : zipTree(it)
def pkgs = [].toSet()
tree.visit { file ->
if (!file.directory && file.name.endsWith('.class') && file.path.contains('/')) {
def pkg = file.path.substring(0, file.path.lastIndexOf('/')) + '/'
if (pkg.startsWith('com/')) {
if (pkg.startsWith('com/google/')) {
if (!pkg.startsWith('com/google/common') && !pkg.startsWith('com/google/gson')) {
pkgs << pkg.substring(0, pkg.indexOf('/', 'com/google/'.length()))
}
} else if (!pkg.startsWith('com/replaymod')) {
pkgs << pkg.substring(0, pkg.indexOf('/', 4))
}
} else if (pkg.startsWith('net/')) {
if (!pkg.startsWith('net/minecraft')
&& !pkg.startsWith('net/fabric')) {
pkgs << pkg.substring(0, pkg.indexOf('/', 'net/'.length()))
}
} else if (pkg.startsWith('org/')) {
if (pkg.startsWith('org/apache/')) {
if (pkg.startsWith('org/apache/commons/')) {
if (!pkg.startsWith('org/apache/commons/io')) {
pkgs << pkg.substring(0, pkg.indexOf('/', 'org/apache/commons/'.length()))
}
} else if (!pkg.startsWith('org/apache/logging')) {
pkgs << pkg.substring(0, pkg.indexOf('/', 'org/apache/'.length()))
}
} else if (pkg.startsWith('org/lwjgl')) {
return // either bundled with MC or uses natives which we can't relocate
} else if (!pkg.startsWith('org/spongepowered')) {
pkgs << pkg.substring(0, pkg.indexOf('/', 4))
}
} else if (pkg.startsWith('it/unimi/dsi/fastutil') && mcVersion >= 11400) {
return // MC uses this as well
} else if (!pkg.startsWith('javax/')) {
// Note: we cannot just use top level packages as those will be too generic and we'll run
// into this long standing bug: https://github.com/johnrengelman/shadow/issues/232
def i = pkg.indexOf('/')
def i2 = pkg.indexOf('/', i + 1)
if (i2 > 0) {
pkgs << pkg.substring(0, i2)
}
}
}
}
pkgs
}.flatten().unique()
configureRelocationOutput.write(pkgs.join('\n'))
}
}
// tasks.removeByName('shadowJar') // we want to base our shadowed jar on the reobfJar output, not the sourceSet output
tasks.whenTaskAdded { task ->
if(task.name.contains('shadowJar')) {
System.out.println(task + "is disabled")
task.enabled = false
}
}
task jarCustom(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
classifier 'shadow'
from { new File(project.buildDir, 'reobfJar/output.jar') }
dependsOn { tasks.configureRelocation }
dependsOn { tasks.reobfJar }
manifest.inheritFrom tasks.jar.manifest
configurations = [project.configurations.shadow]
// from { project.configurations.shade }
inputs.file configureRelocationOutput
// No need to shadow netty, MC provides it
// (actually, pre-1.12 ships a netty which is too old, so we need to shade it there anyway)
relocate 'com.github.steveice10.netty', 'io.netty'
exclude 'com/github/steveice10/netty/**'
exclude 'it/unimi/dsi/fastutil/**'
exclude 'META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'module-info.class'
minimize {
exclude(dependency('.*spongepowered:mixin:.*'))
}
doFirst {
new File(project.buildDir, 'configureRelocation').readLines().each { pkg ->
def pkgName = pkg.replace('/', '.')
relocate pkgName, 'com.replaymod.lib.' + pkgName
}
}
}
tasks.assemble.dependsOn tasks.jarCustom
jar {
classifier = 'raw'
from files(project.mixinRefMap.canonicalPath)
manifest {
attributes 'TweakClass': 'org.spongepowered.asm.launch.MixinTweaker',
'FMLCorePluginContainsFMLMod': 'true',
'FMLAT': 'replaymod_at.cfg',
'MixinConfigs': 'mixins.replaymod.json'
}
}
processResources {
// this will ensure that this task is redone when the versions change.
inputs.property 'version', { project.version }
inputs.property 'mcversion', { mcVersionStr }
// replace stuff in mcmod.info (forge) and fabric.mod.json, nothing else
filesMatching(['mcmod.info', 'fabric.mod.json']) {
// replace version and mcversion
expand 'version': project.version, 'mcversion': mcVersionStr
}
// strip comments from (strict) JSON files
filesMatching('pack.mcmeta') {
filter { line -> line.trim().startsWith('//') ? '' : line}
}
// exclude mod meta for non-applicable loader
exclude 'fabric.mod.json'
}
task copySrg(dependsOn: 'createMcpToSrg') {
doLast {
def tsrg = file(project.tasks.createMcpToSrg.output).readLines()
def srg = []
def cls = ''
for (def line : tsrg) {
if (line[0] != '\t') {
srg.add('CL: ' + line)
cls = line.split(' ')[0]
} else {
def parts = line.substring(1).split(' ')
if (line.contains('(')) {
srg.add('MD: ' + cls + '/' + parts[0] + ' ' + parts[1] + ' ' + cls + '/' + parts[2] + ' ' + parts[1])
} else {
srg.add('FD: ' + cls + '/' + parts[0] + ' ' + cls + '/' + parts[1])
}
}
}
new File(project.buildDir, 'mcp-srg.srg').write(srg.join('\n'))
}
}
compileJava.dependsOn copySrg
defaultTasks 'build'