-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.gradle.kts
261 lines (223 loc) · 8.81 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
/*
* Numismatics
* Copyright (c) 2024 The Railways Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.fabricmc.loom.api.LoomGradleExtensionAPI
import net.fabricmc.loom.task.RemapJarTask
import org.gradle.configurationcache.extensions.capitalized
import java.io.ByteArrayOutputStream
plugins {
java
`maven-publish`
id("architectury-plugin") version "3.4.+"
id("dev.architectury.loom") version "1.7.+" apply false
id("me.modmuss50.mod-publish-plugin") version "0.3.4" apply false // https://github.com/modmuss50/mod-publish-plugin
id("com.github.johnrengelman.shadow") version "8.1.1" apply false
id("dev.ithundxr.silk") version "0.11.+" // https://github.com/IThundxr/silk
id("net.kyori.blossom") version "2.1.0" apply false // https://github.com/KyoriPowered/blossom
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.8" // https://github.com/JetBrains/gradle-idea-ext-plugin
}
println("Numismatics v${"mod_version"()}")
val isRelease = System.getenv("RELEASE_BUILD")?.toBoolean() ?: false
val buildNumber = System.getenv("GITHUB_RUN_NUMBER")?.toInt()
val gitHash = "\"${calculateGitHash() + (if (hasUnstaged()) "-modified" else "")}\""
extra["gitHash"] = gitHash
architectury {
minecraft = "minecraft_version"()
}
allprojects {
apply(plugin = "java")
apply(plugin = "architectury-plugin")
apply(plugin = "maven-publish")
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.encoding = "UTF-8"
}
java {
withSourcesJar()
}
}
subprojects {
apply(plugin = "dev.architectury.loom")
apply(plugin = "net.kyori.blossom")
val capitalizedName = project.name.capitalized()
val loom = project.extensions.getByType<LoomGradleExtensionAPI>()
loom.apply {
silentMojangMappingsLicense()
runs.configureEach {
vmArg("-XX:+AllowEnhancedClassRedefinition")
vmArg("-XX:+IgnoreUnrecognizedVMOptions")
vmArg("-Dmixin.debug.export=true")
vmArg("-Dmixin.env.remapRefMap=true")
vmArg("-Dmixin.env.refMapRemappingFile=${projectDir}/build/createSrgToMcp/output.srg")
}
}
repositories {
mavenCentral()
maven("https://maven.shedaniel.me/") // Cloth Config, REI
maven("https://maven.blamejared.com/") // JEI, Carry On
maven("https://maven.parchmentmc.org") // Parchment mappings
maven("https://mvn.devos.one/snapshots/") // Create Fabric, Porting Lib, Forge Tags, Milk Lib, Registrate Fabric, Steam 'n' Rails
maven("https://mvn.devos.one/releases") // Porting Lib Releases, Steam 'n' Rails Releases
maven("https://maven.tterrag.com/") { // Flywheel
content {
// need to be specific here due to version overlaps
includeGroup("com.jozufozu.flywheel")
}
}
}
@Suppress("UnstableApiUsage")
dependencies {
"minecraft"("com.mojang:minecraft:${"minecraft_version"()}")
"mappings"(loom.layered {
officialMojangMappings { nameSyntheticMembers = false }
parchment("org.parchmentmc.data:parchment-${"minecraft_version"()}:${"parchment_version"()}@zip")
})
}
publishing {
publications {
create<MavenPublication>("maven${capitalizedName}") {
artifactId = "${"archives_base_name"()}-${project.name}-${"minecraft_version"()}"
from(components["java"])
}
}
repositories {
val mavenToken = System.getenv("MAVEN_TOKEN")
val maven = if (isRelease) "releases" else "snapshots"
if (mavenToken != null && mavenToken.isNotEmpty()) {
maven {
url = uri("https://mvn.devos.one/${maven}")
credentials {
username = "ithundxr-github"
password = mavenToken
}
}
}
}
}
// from here down is platform configuration
if(project.path == ":common") {
return@subprojects
}
apply(plugin = "com.github.johnrengelman.shadow")
apply(plugin = "me.modmuss50.mod-publish-plugin")
architectury {
platformSetupLoomIde()
}
tasks.named<RemapJarTask>("remapJar") {
val shadowJar = project.tasks.named<ShadowJar>("shadowJar").get()
inputFile.set(shadowJar.archiveFile)
injectAccessWidener = true
dependsOn(shadowJar)
archiveClassifier = null
}
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)
}
tasks.named<ShadowJar>("shadowJar") {
archiveClassifier = "dev-shadow"
configurations = listOf(shadowCommon)
exclude("architectury.common.json")
destinationDirectory = layout.buildDirectory.dir("devlibs").get()
}
tasks.processResources {
// set up properties for filling into metadata
val properties = mapOf(
"version" to 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"().split(".")[0], // only specify major version of forge
"create_forge_version" to "create_forge_version"().split("-")[0], // cut off build number
"create_fabric_version" to "create_fabric_version"()
)
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 calculateGitHash(): String {
try {
val stdout = ByteArrayOutputStream()
exec {
commandLine("git", "rev-parse", "HEAD")
standardOutput = stdout
}
return stdout.toString().trim()
} catch(ignored: Throwable) {
return "unknown"
}
}
fun hasUnstaged(): Boolean {
try {
val stdout = ByteArrayOutputStream()
exec {
commandLine("git", "status", "--porcelain")
standardOutput = stdout
}
val result = stdout.toString().replace("M gradlew", "").trimEnd()
if (result.isNotEmpty())
println("Found stageable results:\n${result}\n")
return result.isNotEmpty()
} catch(ignored: Throwable) {
return false
}
}
tasks.create("numismaticsPublish") {
when (val platform = System.getenv("PLATFORM")) {
"both" -> {
dependsOn(tasks.build, ":fabric:publish", ":forge:publish", ":common:publish", ":fabric:publishMods", ":forge:publishMods")
}
"fabric", "forge" -> {
dependsOn("${platform}:build", "${platform}:publish", "${platform}:publishMods")
}
}
}
operator fun String.invoke(): String {
return rootProject.ext[this] as? String
?: throw IllegalStateException("Property $this is not defined")
}