Repository navigation
Expand file tree
/
Copy pathbuild.gradle
More file actions
399 lines (344 loc) · 12.9 KB
/
Copy pathbuild.gradle
File metadata and controls
399 lines (344 loc) · 12.9 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
395
396
397
398
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.errors.RepositoryNotFoundException
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
maven {
url "https://jitpack.io/"
}
mavenCentral()
}
dependencies {
classpath "com.gradle.publish:plugin-publish-plugin:0.9.1"
classpath 'org.eclipse.jgit:org.eclipse.jgit:5.10.0.202012080955-r'
// Need ASM on buildscript classpath to patch SpecialSource classes
classpath 'org.ow2.asm:asm:9.7.1'
classpath 'org.ow2.asm:asm-tree:9.7.1'
classpath 'org.ow2.asm:asm-commons:9.7.1'
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: "com.gradle.plugin-publish"
project.ext {
GIT_INFO = gitInfo(rootProject.file('.'))
OLD_FORMAT = '2.1-SNAPSHOT'
}
group = 'net.minecraftforge.gradle'
version = project.version == "unspecified" ? "1.1.0" : project.version
archivesBaseName = 'ForgeGradle'
targetCompatibility = '8'
sourceCompatibility = '8'
repositories {
mavenLocal()
maven {
name = "forge"
url = "https://maven.minecraftforge.net"
}
maven {
// because Srg2Source needs an eclipse dependency.
name = "eclipse"
url = "https://repo.eclipse.org/content/groups/eclipse/"
}
mavenCentral()
maven {
url "https://jitpack.io/"
}
// because of the GradleStart stuff
maven {
name = "mojang"
url = "https://libraries.minecraft.net/"
}
}
configurations {
deployerJars
shade
compileOnly.extendsFrom shade
}
dependencies {
implementation gradleApi()
implementation 'com.google.guava:guava:18.0'
implementation 'net.sf.opencsv:opencsv:2.3' // reading CSVs.. also used by SpecialSource
implementation 'com.cloudbees:diff4j:1.1' // for difing and patching
implementation 'com.github.abrarsyed.jastyle:jAstyle:1.3' // formatting
implementation 'net.sf.trove4j:trove4j:2.1.0' // because its awesome.
implementation 'com.github.jponge:lzma-java:1.3' // replaces the LZMA binary
implementation 'com.nothome:javaxdelta:2.0.1' // GDIFF implementation for BinPatches
implementation 'com.google.code.gson:gson:2.2.4' // Used instead of Argo for buuilding changelog.
implementation 'com.github.tony19:named-regexp:0.2.3' // 1.7 Named regexp features
implementation 'net.minecraftforge:fernflower:2.0-SNAPSHOT' // Fernflower Forge edition
shade ('com.github.thefightagainstmalware:SpecialSource:ab856ded6b')
// deobf and reobs
// compile 'net.md-5:SpecialSource:1.7.4' // when md5 publishes
// Override SpecialSource's bundled old ASM with Java 21-compatible version
shade 'org.ow2.asm:asm:9.7.1'
shade 'org.ow2.asm:asm-commons:9.7.1'
shade 'org.ow2.asm:asm-tree:9.7.1'
shade 'org.ow2.asm:asm-analysis:9.7.1'
shade 'org.ow2.asm:asm-util:9.7.1'
// because curse
implementation 'org.apache.httpcomponents:httpclient:4.3.3'
implementation 'org.apache.httpcomponents:httpmime:4.3.3'
// mcp stuff
shade 'de.oceanlabs.mcp:RetroGuard:3.6.6'
shade 'com.github.thefightagainstmalware:MCInjector:daef64f'
shade 'net.minecraftforge.srg2source:Srg2Source:3.3-SNAPSHOT'
// The old version used by S2S is gone, so we need to force the latest build of that minor release
shade 'org.eclipse.jdt:org.eclipse.jdt.core:3.10.0.+'
//Stuff used in the GradleStart classes
compileOnly 'com.mojang:authlib:1.5.16'
compileOnly ("net.minecraft:launchwrapper:1.11")
testImplementation 'junit:junit:4.12'
}
sourceSets {
main.compileClasspath += configurations.shade;
main.runtimeClasspath += configurations.shade;
test.compileClasspath += configurations.shade;
test.runtimeClasspath += configurations.shade;
}
compileJava {
options.deprecation = true
}
processResources {
duplicatesStrategy = DuplicatesStrategy.WARN
from(sourceSets.main.resources.srcDirs) {
include 'forgegradle.version.txt'
expand 'version': project.version
}
from(sourceSets.main.resources.srcDirs) {
exclude 'forgegradle.version.txt'
}
}
jar {
duplicatesStrategy = DuplicatesStrategy.INCLUDE;
// Pass 1: all shade deps, excluding their bundled ASM
configurations.shade.each { dep ->
from(project.zipTree(dep)){
exclude 'META-INF', 'META-INF/**'
exclude 'org/objectweb/asm/**'
}
}
// Pass 2: ASM 9.7.1 shade deps only (re-adds modern ASM to override old)
configurations.shade.findAll { it.name.contains('asm') && it.name.contains('9.7.1') }.each { dep ->
from(project.zipTree(dep)){
exclude 'META-INF', 'META-INF/**'
}
}
manifest {
attributes 'version':project.version
attributes 'javaCompliance': project.targetCompatibility
attributes 'group':project.group
attributes 'Implementation-Version': project.version + "-" + GIT_INFO.hash
}
}
// Patch SpecialSource bytecode to use ASM9 API level instead of ASM5.
// Fixes "NestHost requires ASM7" — SpecialSource compiled with Opcodes.ASM5 (327680)
// but ASM 9.7.1's ClassVisitor checks (api < ASM7) before visitNestHost/visitNestMember.
import org.objectweb.asm.*
import org.objectweb.asm.tree.*
jar.doLast {
def jarFile = jar.archivePath
def tempFile = new File(jarFile.absolutePath + ".tmp")
def asmApiUpgrade = [262144: 589824, 327680: 589824, 393216: 589824] // ASM4/5/6 → ASM9
// Track seen entry names to handle duplicates from two-pass jar shading
def seen = new HashSet<String>()
def fis = new FileInputStream(jarFile)
def zis = new java.util.zip.ZipInputStream(fis)
def fos = new FileOutputStream(tempFile)
def zos = new java.util.zip.ZipOutputStream(fos)
zos.setLevel(java.util.zip.Deflater.DEFAULT_COMPRESSION)
java.util.zip.ZipEntry entry
while ((entry = zis.nextEntry) != null) {
// Skip duplicate entries (two-pass jar can produce overlapping entries)
if (!seen.add(entry.name)) {
continue
}
// Use manual read loop instead of readAllBytes() for Java 8 compatibility on JitPack
def buf = new byte[8192]
def bos = new java.io.ByteArrayOutputStream()
int len
while ((len = zis.read(buf)) > 0) {
bos.write(buf, 0, len)
}
def bytes = bos.toByteArray()
if (entry.name.startsWith('net/md_5/specialsource/') && entry.name.endsWith('.class')) {
try {
ClassReader cr = new ClassReader(bytes)
ClassNode cn = new ClassNode(Opcodes.ASM9)
cr.accept(cn, 0)
boolean patched = false
for (MethodNode mn : cn.methods) {
def insns = mn.instructions.toArray()
for (AbstractInsnNode insn : insns) {
if (insn instanceof LdcInsnNode) {
LdcInsnNode ldc = (LdcInsnNode) insn
def newVal = asmApiUpgrade.get(ldc.cst)
if (newVal != null) {
ldc.cst = newVal
patched = true
}
}
}
}
if (patched) {
ClassWriter cw = new ClassWriter(0)
cn.accept(cw)
bytes = cw.toByteArray()
println "Patched ASM API level in ${entry.name}"
}
} catch (Exception e) {
println "Warning: could not patch ${entry.name}: ${e.message}"
}
}
def newEntry = new java.util.zip.ZipEntry(entry.name)
newEntry.setTime(entry.time)
zos.putNextEntry(newEntry)
zos.write(bytes)
zos.closeEntry()
}
zis.close()
zos.close()
fos.close()
fis.close()
jarFile.delete()
tempFile.renameTo(jarFile)
println "SpecialSource ASM API level patching complete."
}
javadoc {
classpath += configurations.compileOnly
// linked javadoc urls.. why not...
options.addStringOption 'link', 'https://gradle.org/docs/current/javadoc/'
options.addStringOption 'link', 'https://docs.guava-libraries.googlecode.com/git-history/v18.0/javadoc'
options.addStringOption 'link', 'https://asm.ow2.org/asm50/javadoc/user/'
}
artifacts {
archives jar
//archives javadocJar
}
test {
// These tests are outdated, and I can't be arsed to fix them
exclude "*"
// if (project.hasProperty("filesmaven")) // disable this test when on the forge jenkins
// exclude "**/ExtensionMcpMappingTest*"
}
pluginBundle {
website = 'https://www.gradle.org/'
vcsUrl = 'https://github.com/thefightagainstmalware/ForgeGradle'
description = 'Gradle plugin for all Minecraft mod development needs'
tags = ['forge', 'minecraft', 'minecraftforge', 'sponge', 'mcp']
plugins {
patcher {
id = 'net.minecraftforge.gradle.patcher'
displayName = 'Minicraft Patcher Plugin'
}
tweakerClient {
id = 'net.minecraftforge.gradle.tweaker-client'
displayName = 'Mincraft Client Tweaker Plugin'
}
tweakerServer {
id = 'net.minecraftforge.gradle.tweaker-server'
displayName = 'Mincraft Server Tweaker Plugin'
}
forge {
id = 'net.minecraftforge.gradle.forge'
displayName = 'MincraftForge Mod Development Plugin'
}
launch4j {
id = 'net.minecraftforge.gradle.launch4j'
displayName = 'Specialized Launch4J Gradle Plugin'
}
}
}
// write out version so its convenient for doc deployment
file('build').mkdirs()
file('build/version.txt').text = version;
def gitInfo(dir) {
String.metaClass.rsplit = { String del, int limit = -1 ->
def lst = new ArrayList()
def x = 0, idx
def tmp = delegate
while ((idx = tmp.lastIndexOf(del)) != -1 && (limit == -1 || x++ < limit)) {
lst.add(0, tmp.substring(idx + del.length(), tmp.length()))
tmp = tmp.substring(0, idx)
}
lst.add(0, tmp)
return lst
}
def git = null
try {
git = Git.open(dir)
} catch (RepositoryNotFoundException e) {
return [
tag: '0.0',
offset: '0',
hash: '00000000',
branch: 'master',
commit: '0000000000000000000000',
abbreviatedId: '00000000'
]
}
def value = git.describe().setLong(true).setTags(true).call();
if (value == null) {
return [
tag: '0.0',
offset: '0',
hash: '00000000',
branch: 'master',
commit: '0000000000000000000000',
abbreviatedId: '00000000'
]
}
def head = git.repository.exactRef('HEAD')
def longBranch = head.symbolic ? head?.target?.name : null // matches Repository.getFullBranch() but returning null when on a detached HEAD
def ret = [:]
ret.tag = desc[0]
ret.offset = desc[1]
ret.hash = desc[2]
ret.branch = longBranch != null ? org.eclipse.jgit.lib.Repository.shortenRefName(longBranch) : null
ret.commit = org.eclipse.jgit.lib.ObjectId.toString(head.objectId)
ret.abbreviatedId = head.objectId.abbreviate(8).name()
return ret
}
publishing {
publications {
mavenJava(MavenPublication) {
pom {
name = 'ForgeGradle'
description = 'A concise description of my library'
url = 'https://github.com/thefightagainstmalware/ForgeGradle/'
licenses {
license {
name = ' GNU LESSER GENERAL PUBLIC LICENSE\n' +
' Version 2.1'
url = 'https://raw.githubusercontent.com/thefightagainstmalware/ForgeGradle/nosession-main/LICENSE'
}
}
developers {
developer {
id = 'forgedevs'
name = 'Forge Developers'
}
developer {
id = 'pandaninjas'
name = "PandaNinjas"
email = "admin@malwarefight.wip.la"
}
developer {
id = 'mikidevahm'
name = "MikiDevAHM"
}
}
scm {
connection = 'scm:git:git://github.com/thefightagainstmalware/ForgeGradle'
developerConnection = 'scm:git:https://github.com/thefightagainstmalware/ForgeGradle'
url = 'https://github.com/thefightagainstmalware/ForgeGradle/'
}
}
from components.java
}
}
}