-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle.kts
289 lines (242 loc) · 8.71 KB
/
build.gradle.kts
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
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import dev.architectury.plugin.ArchitectPluginExtension
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import net.fabricmc.loom.api.LoomGradleExtensionAPI
import net.fabricmc.loom.task.RemapJarTask
import java.io.ByteArrayOutputStream
import java.util.jar.JarEntry
import java.util.jar.JarFile
import java.util.jar.JarOutputStream
import java.util.zip.Deflater
plugins {
java
id("architectury-plugin") version "3.4.159" apply false
id("dev.architectury.loom") version "1.6.411" apply false
id("com.github.johnrengelman.shadow") version "8.1.1" apply false
}
println("Interiors v${"mod_version"()}")
apply(plugin = "architectury-plugin")
architectury {
minecraft = "minecraft_version"()
}
val isRelease = System.getenv("RELEASE_BUILD")?.toBoolean() ?: false
val buildNumber = System.getenv("GITHUB_RUN_NUMBER")?.toInt()
val gitHash = "\"${calculateGitHash() + (if (hasUnstaged()) "-modified" else "")}\""
tasks.jar { enabled = false }
allprojects {
apply(plugin = "java")
apply(plugin = "architectury-plugin")
base.archivesName.set("archives_base_name"())
group = "maven_group"()
// Formats the mod version to include the loader, Minecraft version, and build number (if present)
// example: 1.0.0+fabric-1.19.2-build.100 (or -local)
val build = buildNumber?.let { "-build.${it}" } ?: "-local"
version = "${"mod_version"()}+${project.name}-mc${"minecraft_version"()}${if (isRelease) "" else build}"
tasks.withType<JavaCompile>().configureEach {
options.release = 17
options.encoding = "UTF-8"
}
java {
withSourcesJar()
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
}
subprojects {
apply(plugin = "dev.architectury.loom")
setupRepositories()
val capitalizedName = project.name.replaceFirstChar(Char::uppercase)
val loom = project.extensions.getByType<LoomGradleExtensionAPI>()
loom.silentMojangMappingsLicense()
configurations.configureEach {
resolutionStrategy {
force("net.fabricmc:fabric-loader:${"fabric_loader_version"()}")
}
}
@Suppress("UnstableApiUsage")
dependencies {
"minecraft"("com.mojang:minecraft:${"minecraft_version"()}")
// layered mappings - Mojmap names, parchment and QM docs and parameters
"mappings"(loom.layered {
mappings("org.quiltmc:quilt-mappings:${"minecraft_version"()}+build.${"qm_version"()}:intermediary-v2")
officialMojangMappings { nameSyntheticMembers = false }
parchment("org.parchmentmc.data:parchment-${"minecraft_version"()}:${"parchment_version"()}@zip")
})
}
tasks.register<Copy>("moveBuiltJars") {
if (project.path != ":common") {
val remapJar by project.tasks.named<RemapJarTask>("remapJar")
dependsOn(remapJar)
from(remapJar)
}
into(rootProject.file("jars"))
}
// from here down is platform configuration
if(project.path == ":common") {
return@subprojects
}
apply(plugin = "com.github.johnrengelman.shadow")
architectury {
platformSetupLoomIde()
}
tasks.named<RemapJarTask>("remapJar") {
val shadowJar = project.tasks.named<ShadowJar>("shadowJar").get()
inputFile.set(shadowJar.archiveFile)
injectAccessWidener = true
dependsOn(shadowJar)
archiveClassifier = null
doLast {
squishJar(archiveFile.get().asFile)
}
}
val common: Configuration by configurations.creating
val shadowCommon: Configuration by configurations.creating
val development = configurations.maybeCreate("development${capitalizedName}")
configurations {
compileOnly.get().extendsFrom(common)
runtimeOnly.get().extendsFrom(common)
development.extendsFrom(common)
}
dependencies {
common(project(":common", "namedElements")) { isTransitive = false }
shadowCommon(project(":common", "transformProduction${capitalizedName}")) { isTransitive = false }
}
tasks.named<ShadowJar>("shadowJar") {
archiveClassifier = "dev-shadow"
configurations = listOf(shadowCommon)
exclude("architectury.common.json")
destinationDirectory = layout.buildDirectory.dir("devlibs").get()
}
tasks.processResources {
// include packs
from(project(":common").file("src/main/resources")) {
include("resourcepacks/")
}
// set up properties for filling into metadata
val properties = mapOf(
"version" to "mod_version"(),
"minecraft_version" to "minecraft_version"(),
"fabric_api_version" to "fabric_api_version"(),
"fabric_loader_version" to "fabric_loader_version"(),
"forge_version" to "forge_version"().substringBefore("."), // only specify major version of forge
"create_forge_version" to "create_forge_version"().substringBefore("-"), // cut off build number
"create_fabric_version" to "create_fabric_version"().substringBefore("+") // Trim +mcX.XX.X from version string
)
inputs.properties(properties)
filesMatching(listOf("fabric.mod.json", "META-INF/mods.toml")) {
expand(properties)
}
}
tasks.jar {
archiveClassifier = "dev"
manifest {
attributes(mapOf("Git-Hash" to gitHash))
}
}
tasks.named<Jar>("sourcesJar") {
val commonSources = project(":common").tasks.getByName<Jar>("sourcesJar")
dependsOn(commonSources)
from(commonSources.archiveFile.map { zipTree(it) })
manifest {
attributes(mapOf("Git-Hash" to gitHash))
}
}
components.getByName<AdhocComponentWithVariants>("java") {
withVariantsFromConfiguration(project.configurations["shadowRuntimeElements"]) {
skip()
}
}
}
fun squishJar(jar: File) {
val contents = linkedMapOf<String, ByteArray>()
JarFile(jar).use {
it.entries().asIterator().forEach { entry ->
if (!entry.isDirectory) {
contents[entry.name] = it.getInputStream(entry).readAllBytes()
}
}
}
jar.delete()
JarOutputStream(jar.outputStream()).use { out ->
out.setLevel(Deflater.BEST_COMPRESSION)
contents.forEach { var (name, data) = it
if(name.startsWith("architectury_inject_"))
return@forEach
if (name.endsWith(".json") || name.endsWith(".mcmeta")) {
data = (JsonOutput.toJson(JsonSlurper().parse(data)).toByteArray())
}
out.putNextEntry(JarEntry(name))
out.write(data)
out.closeEntry()
}
out.finish()
out.close()
}
}
operator fun String.invoke(): String {
return rootProject.ext[this] as? String
?: throw IllegalStateException("Property $this is not defined")
}
fun Project.setupRepositories() {
repositories {
mavenCentral()
maven("https://maven.shedaniel.me/") // Cloth Config, REI
maven("https://maven.blamejared.com/") // JEI, Hex Casting
exclusiveMaven("https://maven.parchmentmc.org", "org.parchmentmc.data") // Parchment mappings
exclusiveMaven("https://maven.quiltmc.org/repository/release", "org.quiltmc") // Quilt Mappings
maven("https://jm.gserv.me/repository/maven-public/") // JourneyMap API
exclusiveMaven("https://api.modrinth.com/maven", "maven.modrinth") // LazyDFU, JourneyMap
exclusiveMaven("https://cursemaven.com", "curse.maven")
maven("https://maven.theillusivec4.top/") // Curios
maven("https://maven.tterrag.com/") { // Flywheel, Registrate, Create
content {
includeGroup("com.simibubi.create")
includeGroup("com.tterrag.registrate")
includeGroup("com.jozufozu.flywheel")
}
}
exclusiveMaven("https://maven.jamieswhiteshirt.com/libs-release", "com.jameswhiteshirt.reach-entity-attributes")// Reach Entity Attributes
maven("https://maven.terraformersmc.com/releases/") // Mod Menu, EMI
maven("https://mvn.devos.one/snapshots/") // Create Fabric, Porting Lib, Forge Tags, Milk Lib, Registrate Fabric
maven("https://maven.cafeteria.dev/releases") // Fake Player API
maven("https://maven.jamieswhiteshirt.com/libs-release") // Reach Entity Attributes
maven("https://raw.githubusercontent.com/Fuzss/modresources/main/maven/") // forge config api port
exclusiveMaven("https://maven.blamejared.com", "at.petra-k", "vazkii.patchouli") // JEI, Hex Casting
exclusiveMaven("https://maven.ladysnake.org/releases", "dev.onyxstudios.cardinal-components-api") // Cardinal Components (Hex Casting dependency)
maven("https://jitpack.io") // MixinExtras and FabricASM
}
}
fun calculateGitHash(): String {
val stdout = ByteArrayOutputStream()
exec {
commandLine("git", "rev-parse", "HEAD")
standardOutput = stdout
}
return stdout.toString().trim()
}
fun hasUnstaged(): Boolean {
val stdout = ByteArrayOutputStream()
exec {
commandLine("git", "status", "--porcelain")
standardOutput = stdout
}
val result = stdout.toString().replace(Regex("M gradlew(\\.bat)?"), "").trimEnd()
if (result.isNotEmpty())
println("Found stageable results:\n${result}\n")
return result.isNotEmpty()
}
fun Project.architectury(action: Action<ArchitectPluginExtension>) {
action.execute(this.extensions.getByType<ArchitectPluginExtension>())
}
fun RepositoryHandler.exclusiveMaven(url: String, vararg groups: String) {
exclusiveContent {
forRepository { maven(url) }
filter {
groups.forEach {
includeGroup(it)
}
}
}
}