forked from fr1kin/ForgeHax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
193 lines (162 loc) · 4.85 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
plugins {
id 'java'
id 'dev.fiki.forgehax.mapper'
alias libs.plugins.forgegradle
alias libs.plugins.gitgradle
}
ext {
minecraftVersion = libs.versions.minecraft.get()
forgeVersion = libs.versions.forge.get()
}
final git = versionDetails()
group 'dev.fiki.forgehax'
version "${git.lastTag.substring(1)}.r${git.commitDistance}_${git.gitHash}"
archivesBaseName = "ForgeHax_${minecraftVersion}"
final isCiBuilding = System.getenv().get('CI') == 'true'
if (isCiBuilding) {
logger.warn 'CI build. Certain modules will be omitted from this build'
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}
configurations {
all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
}
sourceSets {
api {
compileClasspath += main.compileClasspath
}
main {
if (isCiBuilding) {
java {
exclude 'dev/fiki/forgehax/main/mods/ForgeModListSpoofer.java'
}
}
compileClasspath += api.output
}
}
minecraft {
mappings channel: 'official', version: minecraftVersion
runs {
client {
workingDirectory project.file('run')
property 'forge.logging.console.level', 'info'
property 'forgehax.logging.level', 'debug'
mods {
ForgeHax {
sources sourceSets.main
}
}
}
}
}
mapper {
targets sourceSets.main, sourceSets.test
}
dependencies {
minecraft libs.minecraftforge
compileOnly libs.lombok
annotationProcessor libs.lombok
testCompileOnly libs.lombok
testAnnotationProcessor libs.lombok
testImplementation libs.bundles.jupiter
testImplementation libs.assertj
}
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" : "fikidev",
"Specification-Version" : "1",
"Implementation-Title" : project.name,
"Implementation-Version" : project.version,
"Implementation-Vendor" : "fikidev",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}
static def getForgeMajorVersion(String version) {
final dash = version.indexOf('-')
return version.substring(dash + 1, version.indexOf('.', dash))
}
def getContributors(String apiUrl) {
try {
final url = new URL(apiUrl)
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'
}
}
processResources {
from 'logo.png'
filesMatching('**/mods.toml') {
//noinspection UnnecessaryQualifiedReference
it.filter org.apache.tools.ant.filters.ReplaceTokens, tokens: [
'forgehax.version' : project.version as String,
'forgehax.forge.version': getForgeMajorVersion(forgeVersion), // only extract major version
'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('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]) {
onlyIf { !isCiBuilding }
doFirst {
if (file(project.ext.gameDir).exists()) {
final files = { directory, filter, closure ->
new File(directory).eachFileMatch(filter, closure)
}
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 createGitHubActionsVars() {
onlyIf { isCiBuilding }
doFirst {
println "::set-output name=mcversion::${minecraftVersion}"
println "::set-output name=version::${project.version}"
println "::set-output name=jar::${jar.archiveFileName.get()}"
}
}
build {
finalizedBy copyJar, createGitHubActionsVars
}