-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.gradle
203 lines (175 loc) · 6.45 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
import java.nio.file.Files
import java.util.function.Function
import io.github.brassmc.bradle.util.gson.Library.OS
plugins {
id 'java'
id 'io.github.brassmc.bradle' version '0.6.0'
}
repositories {
mavenCentral()
maven {
name = 'forge'
url = 'https://maven.minecraftforge.net/'
}
}
minecraft {
minecraftVersion = '1.20'
mappings 'official', '1.20'
}
sourceSets {
boot
mixin
}
configurations {
mcServer
mcClient
boot
bootImplementation.extendsFrom(boot)
minecraftRuntime
minecraftClientRuntime.extendsFrom(minecraftRuntime)
minecraftServerRuntime.extendsFrom(minecraftRuntime)
bootImplementation.extendsFrom(minecraftRuntime)
bootImplementation.extendsFrom(minecraftClientRuntime)
mixinImplementation.extendsFrom(minecraftClientRuntime)
mixinCompileOnly.extendsFrom(mcClient)
compileOnly.extendsFrom(mcClient)
}
final asm = [
"org.ow2.asm:asm:$asmVersion",
"org.ow2.asm:asm-util:$asmVersion",
"org.ow2.asm:asm-tree:$asmVersion"
]
dependencies {
bootImplementation 'com.google.guava:guava:31.1-jre'
bootImplementation 'org.jetbrains:annotations:23.0.0'
bootImplementation 'org.hjson:hjson:3.0.0'
bootImplementation 'commons-validator:commons-validator:1.7'
boot 'cpw.mods:bootstraplauncher:1.1.2'
boot "cpw.mods:securejarhandler:$sshVersion"
compileOnly "cpw.mods:securejarhandler:$sshVersion"
asm.each {
boot it
bootCompileOnly it
}
mcClient bradle.deobf('net.minecraft:client:1.20:joined')
mcServer bradle.deobf('net.minecraft:server:1.20:joined', 'server')
bootCompileOnly "cpw.mods:securejarhandler:$sshVersion"
mixinCompileOnly "cpw.mods:securejarhandler:$sshVersion"
minecraftRuntime "cpw.mods:modlauncher:$mmlVersion"
minecraftRuntime "org.spongepowered:mixin:$mixinVersion"
minecraftRuntime 'com.google.guava:guava:31.1-jre'
minecraftRuntime 'org.jetbrains:annotations:23.0.0'
minecraftRuntime 'org.hjson:hjson:3.0.0'
minecraftRuntime 'commons-validator:commons-validator:1.7'
bootCompileOnly group:'com.google.auto.service', name:'auto-service', version:'1.0.1'
bootAnnotationProcessor group:'com.google.auto.service', name:'auto-service', version:'1.0.1'
compileOnly sourceSets.boot.output
mixinImplementation sourceSets.main.output
mixinImplementation sourceSets.boot.output
}
processMixinResources {
inputs.properties([
'mixinVersion': mixinVersion
])
filesMatching('brassloader.mixins.json') {
expand 'mixinVersion': mixinVersion
}
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
jar {
from sourceSets.mixin.output
manifest.attributes([
'Automatic-Module-Name': 'io.github.brassmc.brassloader',
])
}
tasks.create('fatJar', Jar) {
it.from sourceSets.boot.output
it.dependsOn(jar)
classifier 'fat'
it.from(jar.archiveFile.get().asFile) {
rename(inTxt -> 'brass.jar')
into 'META-INF/jars'
}
manifest.attributes([
'Automatic-Module-Name': 'io.github.brassmc.brassloader.boot'
])
}
final Function<String, java.nio.file.Path> legacyCpPath = (String type) -> project.file("$buildDir/resources/boot/mc_cp_${type}.txt").toPath().toAbsolutePath()
processBootResources {
doLast {
final configurationResolver = { String type ->
final lines = configurations."minecraft${type.capitalize()}Runtime".resolve().stream()
.map { it.toPath().toAbsolutePath().toString() }
.toList()
final outPath = legacyCpPath.apply(type)
lines.add(fatJar.archiveFile.get().asFile.toString())
Files.createDirectories(outPath.parent)
Files.write(outPath, lines)
}
configurationResolver('client')
configurationResolver('server')
}
}
//noinspection GroovyAssignabilityCheck
final var configureRunTask = { JavaExec it, String type ->
println "Using Java version ${it.getJavaVersion()} for $type configuration"
it.dependsOn('fatJar')
it.getMainClass().set('cpw.mods.bootstraplauncher.BootstrapLauncher')
final sshModule = 'cpw.mods.securejarhandler'
it.jvmArgs(
'--module-path', configurations.boot.resolve().stream().map { it.toString() }.toList().join(File.pathSeparator),
"-DlegacyClassPath.file=${legacyCpPath.apply(type)}",
'--add-modules', 'ALL-MODULE-PATH',
'--add-opens', "java.base/java.util.jar=$sshModule",
'--add-opens', "java.base/java.lang.invoke=$sshModule",
'--add-exports', "java.base/sun.security.util=$sshModule",
'--add-exports', 'jdk.naming.dns/com.sun.jndi.dns=java.naming',
'-Dmixin.debug.verbose=true', '-Dmixin.debug.export=true',
)
if (OS.current in [OS.LINUX, OS.OSX]) it.jvmArgs('-XstartOnFirstThread')
it.group = 'minecraft'
Files.createDirectories(it.workingDir.toPath())
it.dependsOn(gradle.includedBuild('BrassAPI').task(':jar'))
it.doFirst {
if (gradle.includedBuild('BrassAPI') === null) return
final libsDir = gradle.includedBuild('BrassAPI').projectDir.toPath().resolve('build/libs')
Files.list(libsDir)
.map { it.toAbsolutePath() }
.filter { it.toString().endsWith('.jar') }
.max(Comparator.comparing({ Files.getLastModifiedTime(it) }))
.ifPresent {
final dest = project.file("run/$type/mods/brassapi.jar").toPath()
Files.createDirectories(dest.parent)
Files.deleteIfExists(dest)
Files.copy(it, dest)
}
}
}
tasks.register('runClient', JavaExec) {
it.setWorkingDir(project.file('run/client'))
it.jvmArgs(
"-Dbrassloader.mclocation=${configurations.mcClient.resolve().stream().findFirst().orElseThrow()}"
)
args(
'--launchTarget', 'brass:mcclient',
'--accessToken', '***',
'--version', '1.20',
'--assetIndex', '1.20',
'--assetsDir', downloadAssets.output
)
configureRunTask(it, 'client')
}
tasks.register('runServer', JavaExec) {
it.setWorkingDir(project.file('run/server'))
it.jvmArgs(
"-Dbrassloader.mclocation=${configurations.mcServer.resolve().stream().findFirst().orElseThrow()}"
)
it.args(
'--launchTarget', 'brass:mcserver',
)
configureRunTask(it, 'server')
}