forked from Shadows-of-Fire/Apothic-Spawners
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
320 lines (278 loc) · 10.8 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
plugins {
id 'java-library'
id 'idea'
id 'eclipse'
id 'maven-publish'
id 'net.neoforged.gradle.userdev' version '7.0.152'
id 'com.diffplug.eclipse.apt' version '3.42.2'
id 'net.darkhax.curseforgegradle' version '1.1.18'
}
base {
archivesName = "${fileName}-${mcVersion}"
}
java.toolchain.languageVersion = JavaLanguageVersion.of(project.properties.javaVersion)
minecraft {
accessTransformers.file file('src/main/resources/META-INF/accesstransformer.cfg')
}
subsystems {
parchment {
def split = "${parchmentVersion}".split('-')
minecraftVersion = split[1]
mappingsVersion = split[0]
}
}
runs {
configureEach {
systemProperty 'forge.logging.markers', ''
systemProperty 'forge.logging.console.level', 'debug'
modSource project.sourceSets.main
}
client {
systemProperty 'forge.enabledGameTestNamespaces', "${modid}"
}
server {
systemProperty 'forge.enabledGameTestNamespaces', "${modid}"
programArgument '--nogui'
}
data {
programArguments.addAll '--mod', "${modid}", '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
}
}
sourceSets.main.resources {
srcDir 'src/generated/resources'
}
repositories {
maven {
// CurseForge
url "https://www.cursemaven.com"
content {
includeGroup "curse.maven"
}
}
maven {
// Curios
url "https://maven.theillusivec4.top"
content {
includeGroupByRegex "top\\.theillusivec4.*"
}
}
maven {
// Patchouli
url "https://maven.blamejared.com"
content {
includeGroup "vazkii.patchouli"
includeGroupByRegex "net\\.darkhax.*"
includeGroupByRegex "com\\.blamejared.*"
includeGroup "org.openzen.zencode"
includeGroup "mezz.jei"
}
}
maven {
// Shadows
url "https://maven.shadowsoffire.dev/releases"
content {
includeGroup "dev.shadowsoffire"
}
}
maven {
// Emi
url "https://maven.terraformersmc.com/"
content {
includeGroup "dev.emi"
}
}
}
dependencies {
implementation "net.neoforged:neoforge:${forgeVersion}"
if(project.mixin.toBoolean()) annotationProcessor "org.spongepowered:mixin:${mixinVersion}:processor"
if(project.hasProperty('placeboVersion')) implementation "dev.shadowsoffire:Placebo:${mcVersion}-${placeboVersion}"
if(project.hasProperty('jeiVersion')) implementation "mezz.jei:jei-${mcVersion}-neoforge:${jeiVersion}"
if(project.hasProperty('jadeFileId')) implementation "curse.maven:jade-324717:${jadeFileId}"
if(project.hasProperty('curiosVersion')) implementation "top.theillusivec4.curios:curios-neoforge:${curiosVersion}"
if(project.hasProperty('patchouliVersion')) implementation "vazkii.patchouli:Patchouli:${patchouliVersion}"
if(project.hasProperty('bookshelfVersion')) compileOnly "net.darkhax.bookshelf:Bookshelf-Forge-${mcVersion}:${bookshelfVersion}"
if(project.hasProperty('gamestagesVersion')) compileOnly "net.darkhax.gamestages:GameStages-Forge-${mcVersion}:${gamestagesVersion}"
if(project.hasProperty('twilightFileId')) implementation "curse.maven:the-twilight-forest-227639:${twilightFileId}"
if(project.hasProperty('gatewaysVersion')) implementation "dev.shadowsoffire:GatewaysToEternity:${mcVersion}-${gatewaysVersion}"
if(project.hasProperty('attributeslibVersion')) implementation "dev.shadowsoffire:ApothicAttributes:${mcVersion}-${attributeslibVersion}"
if(project.hasProperty('emiVersion')) compileOnly "dev.emi:emi-neoforge:${emiVersion}+${mcVersion}:api"
}
tasks.named('processResources', ProcessResources).configure {
def replaceProperties = [
modGroup: modGroup,
modid: modid,
version: version,
modName: modName,
author: author,
desc: desc,
mcVersion: mcVersion,
javaVersion: javaVersion,
forgeVersion: forgeVersion
]
def licenseFile = file('LICENSE')
if (!licenseFile.exists()) {
throw new Exception('Missing LICENSE file in repository root.')
}
replaceProperties.put 'license', file('LICENSE').readLines().get(0)
if (project.hasProperty('placeboVersion')) replaceProperties.put 'placeboVersion', placeboVersion
if (project.hasProperty('attributeslibVersion')) replaceProperties.put 'attributeslibVersion', attributeslibVersion
if (project.hasProperty('curiosVersion')) replaceProperties.put 'curiosVersion', curiosVersion
if (project.hasProperty('topVersion')) replaceProperties.put 'topVersion', topVersion
if (project.hasProperty('patchouliVersion')) replaceProperties.put 'patchouliVersion', patchouliVersion
replaceProperties.put 'mixinConfig', project.mixin.toBoolean() ? "[[mixins]]\nconfig=\"${modid}.mixins.json\"" : ""
inputs.properties replaceProperties
def resourceTargets = [
'META-INF/neoforge.mods.toml'
]
filesMatching(resourceTargets) {
expand replaceProperties
}
// Automatically populate mixins.json from the mixin package and rename to modid.mixins.json
filesMatching('mixins.json') {
def mixinFiles = []
def clientMixinFiles = []
def path = "${project.projectDir}/src/main/java/${modGroup}/${modid}/mixin".replaceAll('\\.', '/')
fileTree(path).visit { FileVisitDetails details ->
def name = details.file.path.replace('\\', '/')
name = name.substring(name.indexOf('mixin/') + 'mixin/'.length(), name.length())
if(name.endsWith('.java')) {
name = name.substring(0, name.length() - '.java'.length())
if(name.startsWith('client')) {
clientMixinFiles.add(name)
} else {
mixinFiles.add(name)
}
}
}
def mixins = ''
def clientMixins = ''
for (int i = 0; i < mixinFiles.size(); i++) {
def name = mixinFiles[i]
name = name.replaceAll('\\/', '.')
mixins += ' "' + name + '"'
if (i != mixinFiles.size() - 1) {
mixins += ',\n'
}
}
for (int i = 0; i < clientMixinFiles.size(); i++) {
def name = clientMixinFiles[i]
name = name.replaceAll('\\/', '.')
clientMixins += ' "' + name + '"'
if (i != clientMixinFiles.size() - 1) {
clientMixins += ',\n'
}
}
replaceProperties.put('mixins', mixins)
replaceProperties.put('clientMixins', clientMixins)
expand replaceProperties
name "${modid}.mixins.json".toString()
}
// Automatically populate coremods.json file from existing coremod js files in /coremods
filesMatching('META-INF/coremods.json') {
def names = []
fileTree("${project.projectDir}/src/main/resources/coremods").visit { FileVisitDetails details ->
def name = details.file.path.replace('\\', '/')
name = name.substring(name.indexOf('coremods'), name.length())
if(name.endsWith('.js')) {
names.add(name)
}
}
def coremods = ''
for (int i = 0; i < names.size(); i++) {
def name = names[i]
coremods += "\t\"${modid}_" + name.substring('coremods/'.length(), name.length() - 3) + '": "' + name + '"'
if (i != names.size() - 1) {
coremods += ',\n'
}
}
replaceProperties.put('coremods', coremods)
expand replaceProperties
}
}
java {
withSourcesJar()
// withJavadocJar()
}
publishing {
repositories {
maven {
name = "shadowsMaven"
url = "https://maven.shadowsoffire.dev/releases"
credentials(PasswordCredentials)
authentication {
basic(BasicAuthentication)
}
}
}
publications {
mavenJava(MavenPublication) {
groupId = "${modGroup}"
artifactId = "${fileName}"
version = "${mcVersion}-${version}"
pom.withXml {
def node = asNode()
if(node.dependencies.size() > 0)
node.remove(node.dependencies) // Remove deps, as they are all mappings-dependent and/or forge
}
from components.java
}
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}
tasks.withType(GenerateModuleMetadata) {
enabled = false // Can't figure out how to disable the dependencies block here, and it's wrong by default (it pulls deobf deps).
}
def getChangelogLink() {
def repo = ''
def proc = 'git config --get remote.origin.url'.execute();
proc.in.eachLine { line -> repo = line}
proc.err.eachLine { line -> println line }
proc.waitFor();
def branch = ''
proc = 'git rev-parse --abbrev-ref HEAD'.execute()
proc.in.eachLine { line -> branch = line }
proc.err.eachLine { line -> println line }
proc.waitFor()
// Remove ".git" and append /blob/branch/changelog.md
if (!repo.isBlank() && !branch.isBlank()) {
return repo.substring(0, repo.length() - 4) + '/blob/' + branch + '/changelog.md'
}
else {
return ''
}
}
// Splits a list of values separated by ', ' (comma + space).
def splitList(list) {
def split = list.split(', ')
assert split.length == list.count(',') + 1
return split
}
tasks.register('publishCurseForge', net.darkhax.curseforgegradle.TaskPublishCurseForge).configure {
if (project.hasProperty('curseforgeUploadToken') && project.hasProperty('curseforgeProjectId')) {
apiToken = getProperty('curseforgeUploadToken')
disableVersionDetection()
def projectId = getProperty('curseforgeProjectId')
def mainFile = upload(projectId, jar)
mainFile.changelog = getChangelogLink()
mainFile.addModLoader(splitList("${modLoaders}"))
mainFile.addJavaVersion("Java ${javaVersion}")
mainFile.addGameVersion("${mcVersion}")
mainFile.releaseType = "${releaseType}"
if (project.hasProperty('requiredDeps')) {
mainFile.addRequirement(splitList("${requiredDeps}"))
}
if (project.hasProperty('optionalDeps')) {
mainFile.addOptional(splitList("${optionalDeps}"))
}
if (project.hasProperty('incompatibleDeps')) {
mainFile.addIncompatibility(splitList("${incompatibleDeps}"))
}
mainFile.withAdditionalFile(sourcesJar)
}
}
task publishAll() {
dependsOn publish
dependsOn publishCurseForge
}