-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.gradle
371 lines (313 loc) · 11 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
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
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id 'fabric-loom' version '1.8.+'
//id 'org.gradle.toolchains.foojay-resolver-convention' version "0.5.0"
id 'maven-publish'
id "com.modrinth.minotaur" version "2.+"
id 'com.matthewprenger.cursegradle' version '1.4.+'
id "io.github.goooler.shadow" version "8.1.7"
// To trigger musical code on project refresh and run processResources on project launch in Idea
id "org.jetbrains.gradle.plugin.idea-ext" version "0.10"
id "io.github.dexman545.outlet" version '1.6.+'
}
import com.matthewprenger.cursegradle.CurseUploadTask
import com.modrinth.minotaur.dependencies.ModDependency
import groovy.json.JsonSlurper
repositories {
maven {
url 'https://api.modrinth.com/maven'
name 'Modrinth'
}
maven {
url 'https://jitpack.io'
content {
includeGroup "com.github.dexman545"
}
}
}
outlet.cacheTime = null
outlet.mcVersionRange = project.range
//outlet.cacheTime = new TimeDuration(0, 12, 0, 0,0)
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(outlet.javaVersion()))
}
}
System.out.println("Using toolchain: " + outlet.javaVersion())
archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group
logger.lifecycle(outlet.latestMc())
boolean useLatestMc = true
if (useLatestMc && file('asdev.txt').exists()) {
logger.lifecycle('Using latest versions')
project.minecraft_version = outlet.latestMc()
//project.modmenu_version = getLatestModMenu()
project.loader_version = outlet.loaderVersion()
project.yarn_mappings = outlet.yarnVersion()
project.fabric_version = outlet.fapiVersion()
project.java = outlet.javaLanguageCompatibility()
} else {
logger.lifecycle('Using specified versions')
}
outlet {
maintainPropertiesFile = file('asdev.txt').exists()
propertiesData = ['fabric_version': project.fabric_version,
'minecraft_version' : project.minecraft_version,
'yarn_mappings' : project.yarn_mappings,
'loader_version' : project.loader_version,
'java' : project.java]
}
loom {
// Enable runtime only log4j, forces mod to use SLF4J for logging.
runtimeOnlyLog4j = true
runs {
// This adds a new gradle task that runs the datagen API: "gradlew runDatagenClient"
datagenClient {
inherit client
name "Data Generation"
vmArg "-Dfabric-api.datagen"
vmArg "-Dfabric-api.datagen.output-dir=${file("src/main/generated")}"
vmArg "-Dfabric-api.datagen.strict-validation"
runDir "build/datagen"
}
}
}
// Controls if optional deps. should be loaded at runtime via runClient
def useCompileOnlyDeps = false
configurations { //todo move into Outlet, change include to work differently
optional {
transitive = false
}
requiredModImpl {
transitive = false
}
requiredModApi {
transitive = false
}
requiredLib
shade
implementation.extendsFrom shade
modShade
modImplementation.extendsFrom modShade
// Natural hierarchy is inverted for Gradle
modCompileOnly.extendsFrom(optional)
if (useCompileOnlyDeps) modRuntime.extendsFrom(optional)
modImplementation.extendsFrom(requiredModImpl)
implementation.extendsFrom(requiredLib)
include.extendsFrom(requiredModApi, /*requiredModImpl,*/) // Disabled modImpl as fapi modules depend on other modules
modApi.extendsFrom(requiredModApi)
}
shadowJar {
minimize()
from sourceSets.main.output
configurations = [ project.configurations.shade, project.configurations.modShade ]
}
sourceSets {
main {
resources {
srcDirs += [
'src/main/generated'
]
}
}
}
//noinspection SpellCheckingInspection
dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.officialMojangMappings() //"net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API.
requiredModImpl("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}") {
exclude module: "fabric-api-deprecated"
}
// OWNER library
//requiredLib "org.aeonbits.owner:owner:1.0.12"
requiredLib files('api/owner-1.0.13-SNAPSHOT.jar') // Custom version allowing EnumSets to be used
shade files('api/owner-1.0.13-SNAPSHOT.jar')
// Autoswitch API
requiredModApi("com.github.dexman545:autoswitch-api:3.0.0") {//-SNAPSHOT
exclude group: "net.fabricmc", module: "fabric-loader"
}
// Mod Compat ------------
// ModMenu
//optional "maven.modrinth:modmenu:${project.modmenu_version}"
}
remapJar {
dependsOn(shadowJar)
inputFile.set(shadowJar.archiveFile)
}
/**
* Generate list of Fabric API modules based on fabric.mod.json
*/
Set<String> fapiModules() {
def out = []
project.sourceSets.main.resources.files.each {
if (it.name == 'fabric.mod.json') {
def modJson = new JsonSlurper().parse(it)
out = modJson.depends.keySet().findAll { id ->
(id as String).startsWith('fabric-')
}
}
}
return out
}
/*remapJar { //Disabled till loom 0.7 adds it. Planned for creating a standalone jar
include configurations.requiredLib
}*/
processResources {
inputs.property "version", project.version
inputs.property "range", project.range
inputs.property "java", project.java
filesMatching("fabric.mod.json") {
expand "version": project.version, "range": project.range, "java": project.java
}
filesMatching("autoswitch.mixins.json") {
expand "java": project.java
}
}
tasks.withType(JavaCompile).configureEach {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// If Javadoc is generated, this must be specified in that task too.
it.options.encoding = "UTF-8"
it.options.incremental = true
// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used.
// We'll use that if it's available, but otherwise we'll use the older option.
def targetVersion = project.java as int
System.out.println("Using level: " + targetVersion)
if (JavaVersion.current().isJava9Compatible()) {
it.options.release.set(targetVersion)
} else {
it.sourceCompatibility = JavaVersion.toVersion(targetVersion)
it.targetCompatibility = JavaVersion.toVersion(targetVersion)
}
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}
jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}" }
}
}
// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
static def getCheckedOutGitCommitHash() {
'git rev-parse --verify --short HEAD'.execute().text.trim()
}
def uniChangelog = "This is autopublished from Github Actions. Use at your own risk. See commit history or a release " +
"build for changes. Based on commit: ${getCheckedOutGitCommitHash()}\n\n<br />" +
"This build may work on Minecraft versions not specified for this version. Release cadence at time of writing " +
"(2023/05/10):\n\n<br />" +
"1.x.x -> 1.14-1.15 | 2.x.x -> 1.16.x | 3.x.x -> 1.16.2 - 1.18.1 | 4.x.x -> 1.18.2 (22w06a) - 1.19 (22w15a) " +
"| 5.x.x -> 1.19 (22w16a) - 1.19.3 (22w44a) | 6.x.x -> 1.19.3 (~22w45a) - 1.19.4 " +
"| 7 -> 1.20-pre.1 - 1.20.1 | 8 -> 1.20.1-pre.1 - 1.20.4 | 9 -> 1.20.5 (24w09a) - current (and possibly beyond)\n\n<br />"
modrinth {
token = System.getenv("MODRINTH")
projectId = 'uSdcnlts'
versionName = "AutoSwitch $project.version (autopublished)"
versionNumber = project.version
versionType = getReleaseMonicker()
uploadFile = remapJar
gameVersions = outlet.mcVersions()
loaders = ["fabric"]
changelog = uniChangelog
dependencies {
required.project "fabric-api"
}
//debugMode = true
}
curseforge {
if (System.getenv("CURSE")) {
apiKey = System.getenv("CURSE")
}
project {
id = '347405'
changelog = uniChangelog
releaseType = getReleaseMonicker()
outlet.curseforgeMcVersions().each {
if (it.endsWith(".0")) it = it.substring(0, it.length()-2)
addGameVersion it
}
addGameVersion 'Fabric'
changelogType = 'html'
mainArtifact(remapJar) {
displayName = "AutoSwitch $project.version (autopublished)"
}
relations {
requiredDependency 'fabric-api'
}
afterEvaluate {
uploadTask.dependsOn("remapJar")
}
}
options {
forgeGradleIntegration = false
//debug = true // Non-upload testing
}
}
// Only publish to Curseforge for releases
// I intend for beta and alpha builds to be Modrinth exclusives
tasks.withType(CurseUploadTask).configureEach {
onlyIf {
("release" == getReleaseMonicker() || "beta" == getReleaseMonicker()) /*&& !versionAlreadyUploaded()*/
}
}
/**
* Get latest Mod Menu version from Fabric's maven. Not keyed to MC version.
*
* @return mod menu version.
*/
// I got tired of having to find the right version, ok?
String getLatestModMenu() {
outlet.latestModrinthModVersion('modmenu')
}
// Checks only Modrinth as it gets all versions
def versionAlreadyUploaded() {
project.version == outlet.latestModrinthModVersion('autoswitch')
}
/**
* Get the type of release.
* <p>
* Used for publishing to distribution services.
*
* @return build release type, such as 'alpha', 'beta', or 'release'
*/
String getReleaseMonicker() {
if (((String) project.version).contains('alpha')) return "alpha"
if (((String) project.version).contains('beta')) return "beta"
return "release"
}
tasks.publish.onlyIf {
!versionAlreadyUploaded()
}
tasks.modrinth.onlyIf {
!versionAlreadyUploaded()
}
publish.finalizedBy(tasks.curseforge)
publish.finalizedBy(tasks.modrinth)
tasks.runClient.dependsOn(tasks.processResources)