forked from fr1kin/ForgeHax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
242 lines (204 loc) · 7.02 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
buildscript {
repositories {
mavenCentral()
maven { url "http://files.minecraftforge.net/maven" }
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
}
}
ext {
forgehaxCommit = { ->
try {
def out = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput out
}
return out.toString().trim()
} catch (Throwable t) {
String commit = System.getenv('GIT_COMMIT')
if (commit == null) {
logger.warn('Unable to obtain the latest git commit hash.')
return 'latest'
}
return commit
}
}.call()
forgehaxTag = '3.3.1'
forgehaxVersion = "${forgehaxTag}-${forgehaxCommit}"
minecraftVersion = '1.16.5'
forgeVersion = '36.2.2'
fmlVersion = '2.0.0-milestone.1'
lombokVersion = '1.18.16'
mcpVersion = '1.16.5'
mcpChannel = 'official'
mcpMapping = '20201028'
}
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/groups/public/" }
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'dev.fiki.forgehax.mapper'
group 'dev.fiki.forgehax'
version forgehaxVersion
archivesBaseName = "ForgeHax-${minecraftVersion}"
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
final isCiBuilding = System.getenv().containsKey('CI')
if (isCiBuilding) {
logger.warn 'CI build. Certain modules will be omitted from this build'
}
sourceSets {
api {
compileClasspath += main.compileClasspath
}
main {
if (isCiBuilding) {
java {
exclude 'dev/fiki/forgehax/main/mods/ForgeModListSpoofer.java'
}
}
compileClasspath += api.output
}
}
minecraft {
mappings channel: mcpChannel, version: mcpChannel == 'official' ? mcpVersion : "${mcpMapping}-${mcpVersion}"
runs {
client {
workingDirectory project.file('run')
property 'forge.logging.console.level', 'info'
property 'forgehax.logging.level', 'debug'
mods {
ForgeHax {
sources sourceSets.main
}
}
}
}
}
mapper {
include sourceSets.main, sourceSets.test
}
dependencies {
// forge provides us the wrong version, might need to remove this eventually
implementation group: 'org.ow2.asm', name: 'asm-util', version: '7.2'
compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
minecraft "net.minecraftforge:forge:${minecraftVersion}-${forgeVersion}"
testCompileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
testAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.0'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.7.0'
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.18.1'
}
compileJava {
// this will allow use to read a constructors parameter names at runtime
options.compilerArgs << '-parameters'
}
test {
useJUnitPlatform()
}
jar {
manifest {
attributes([
"Specification-Title" : "ForgeHax",
"Specification-Vendor" : "nhackindustries",
"Specification-Version" : "1",
"Implementation-Title" : project.name,
"Implementation-Version" : project.version,
"Implementation-Vendor" : "nhackindustries",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}
processResources {
from 'logo.png'
filesMatching('**/config.properties') {
//noinspection UnnecessaryQualifiedReference
it.filter org.apache.tools.ant.filters.ReplaceTokens, tokens: [
"forgehax.version" : forgehaxVersion.toString(),
"forgehax.mc.version" : minecraftVersion.toString(),
"forgehax.forge.version": forgeVersion.toString(),
"forgehax.mcp.version" : mcpVersion.toString(),
"forgehax.mcp.channel" : mcpChannel.toString(),
"forgehax.mcp.mapping" : mcpMapping.toString()
]
}
filesMatching('**/mods.toml') {
final getMajorVersion = { version ->
final pattern = /^(?<major>[0-9]+)\.(?<minor>[0-9]+)\.(?<patch>[0-9]+)$/
final res = forgeVersion =~ pattern
if (res.find()) {
return "[${res.group('major')},)" as String
} else {
throw new Error("'$version' is not valid semantic versioning!")
}
}
final getContributors = { api ->
try {
final url = new URL(api)
final json = new groovy.json.JsonSlurper().parseText(url.text)
return String.join(', ', json.collect { it.login })
} catch (Throwable t) {
logger.warn("Failed to get contributors from GitHub API! Defaulting to hardcoded users...")
logger.debug(t.getMessage(), t)
return 'fr1kin, BabbaJ, 0x22'
}
}
//noinspection UnnecessaryQualifiedReference
it.filter org.apache.tools.ant.filters.ReplaceTokens, tokens: [
'forgehax.version' : project.version as String,
'forgehax.forge.version': getMajorVersion.call(forgeVersion),
'forgehax.issue.tracker': 'https://github.com/fr1kin/ForgeHax/issues',
'forgehax.update.url' : 'TODO',
'forgehax.url' : 'fiki.dev',
'forgehax.logo.file' : 'logo.png',
'forgehax.credits' : 'Rain#4705 for the logo',
'forgehax.authors' : getContributors.call('https://api.github.com/repos/fr1kin/ForgeHax/contributors'),
'forgehax.description' : 'Hax 4 Forge'
]
}
}
task setGameDir() {
// Check if custom gamedir has been passed, if not use default ones per platform
if (!project.hasProperty("gameDir")) {
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
project.ext.gameDir = System.getenv("APPDATA") + "/.minecraft"
} else if (org.gradle.internal.os.OperatingSystem.current().isMacOsX()) {
project.ext.gameDir = System.properties["user.home"] + "/Library/Application Support/minecraft"
} else {
project.ext.gameDir = System.properties["user.home"] + "/.minecraft"
}
}
}
task copyJar(type: DefaultTask, dependsOn: [setGameDir]) {
if (file(project.ext.gameDir).exists()) {
final files = { directory, filter, closure ->
new File(directory).eachFileMatch(filter, closure)
}
doLast {
final mods = "${project.ext.gameDir}/mods"
project.copy {
// delete previous ForgeHax jars
files(mods, ~/ForgeHax-.*\.jar/) { file ->
file.delete()
}
from project.jar
into mods
}
}
}
}
task setupActionsOutputs() {
println "::set-output name=mc-version::${minecraftVersion}"
println "::set-output name=forgehax-tag::${forgehaxTag}"
println "::set-output name=forgehax-version::${forgehaxVersion}"
println "::set-output name=forge-version::${forgeVersion}"
}
build.finalizedBy copyJar