-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbuild.gradle.kts
297 lines (260 loc) · 9.95 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
290
291
292
293
294
295
296
297
@file:Suppress("UnstableApiUsage")
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.fabricmc.loom.api.LoomGradleExtensionAPI
import net.fabricmc.loom.task.RemapJarTask
val license: String by project
val minecraftVersion: String by project
val modVersion: String by project
val modId: String by project
val modName: String by project
val modDescription: String by project
val modAuthor: String by project
val modPackage: String by project
val autoServiceVersion: String by project
val junitVersion: String by project
val parchmentVersion: String by project
val fabricApiVersion: String by project
val neoforgeVersion: String by project
val jeiVersion: String by project
val reiVersion: String by project
val emiVersion: String by project
val githubRepo: String by project
val githubUser: String by project
plugins {
id("architectury-plugin") version "3.4.+"
id("dev.architectury.loom") version "1.7.+" apply false
id("com.github.johnrengelman.shadow") version "8.1.1" apply false
java
`maven-publish`
}
architectury {
minecraft = minecraftVersion
}
/**
* configurations for all projects including the root project
*/
allprojects {
apply(plugin = "java")
tasks {
withType<JavaCompile> {
options.encoding = "UTF-8"
options.release.set(21)
}
withType<GenerateModuleMetadata> {
enabled = false
}
}
extensions.configure<JavaPluginExtension> {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
withSourcesJar()
}
}
/**
* configurations for all projects except the root project
*/
subprojects {
apply(plugin = "architectury-plugin")
apply(plugin = "dev.architectury.loom")
apply(plugin = "maven-publish")
base {
archivesName.set("$modId-${project.name.lowercase()}")
version = "$minecraftVersion-$modVersion"
}
repositories {
maven("https://maven.neoforged.net/releases")
maven("https://maven.parchmentmc.org") // Parchment
maven("https://maven.shedaniel.me") // REI
maven("https://maven.blamejared.com/") // JEI
maven("https://maven.terraformersmc.com/") // EMI
mavenLocal()
}
val loom = project.extensions.getByName<LoomGradleExtensionAPI>("loom")
loom.silentMojangMappingsLicense()
loom.createRemapConfigurations(sourceSets.getByName("test")) // create test implementations that allow remapping
dependencies {
/**
* Minecraft
* Kotlin accessor methods are not generated in this gradle
* they can be accessed through quoted names instead
*/
"minecraft"("com.mojang:minecraft:$minecraftVersion")
"mappings"(loom.layered {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-1.21:$parchmentVersion@zip") // TODO: replace on parchment update
})
/**
* non-Minecraft dependencies
*/
compileOnly(testCompileOnly("com.google.auto.service:auto-service:$autoServiceVersion")!!)
annotationProcessor(testAnnotationProcessor("com.google.auto.service:auto-service:$autoServiceVersion")!!)
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
}
tasks {
val apiJar = register<Jar>("apiJar") {
val remapJar = named<RemapJarTask>("remapJar")
archiveClassifier.set("api")
dependsOn(remapJar)
from(zipTree(remapJar.get().archiveFile))
include(modPackage.replace('.', '/') + "/api/**")
}
build {
dependsOn(apiJar)
}
/**
* resource processing for defined targets
* will replace `${key}` with the specified values from the map below
*/
processResources {
val resourceTargets = listOf("META-INF/neoforge.mods.toml", "fabric.mod.json", "pack.mcmeta")
val replaceProperties = mapOf(
"version" to project.version as String,
"license" to license,
"modId" to modId,
"modName" to modName,
"minecraftVersion" to minecraftVersion,
"modAuthor" to modAuthor,
"modDescription" to modDescription,
"fabricApiVersion" to fabricApiVersion,
"neoforgeVersion" to neoforgeVersion,
"jeiVersion" to jeiVersion,
"reiVersion" to reiVersion,
"emiVersion" to emiVersion,
"githubUser" to githubUser,
"githubRepo" to githubRepo
)
println("[Process Resources] Replacing resource properties for project '${project.name}': ")
replaceProperties.forEach { (key, value) -> println("\t -> $key = $value") }
inputs.properties(replaceProperties)
filesMatching(resourceTargets) {
expand(replaceProperties)
}
}
}
/**
* Maven publishing
*/
publishing {
publications {
val mpm = project.properties["maven-publish-method"] as String
println("[Publish Task] Publishing method for project '${project.name}': $mpm")
register(mpm, MavenPublication::class) {
artifactId = base.archivesName.get()
from(components["java"])
val apiJarTask = tasks.named<Jar>("apiJar")
artifact(apiJarTask) {
classifier = "api"
}
}
}
/**
* information on how to set up publishing
* https://docs.gradle.org/current/userguide/publishing_maven.html
*/
repositories {
maven("file://${System.getenv("local_maven")}")
}
}
/**
* disabling the runtime transformer from Architectury
* if the runtime transformer should be enabled again, remove this block and
* add the following to the respective subproject:
*
* configurations {
* "developmentFabric" { extendsFrom(configurations["common"]) }
* "developmentForge" { extendsFrom(configurations["common"]) }
* }
*/
architectury {
compileOnly()
}
}
/**
* configurations for all subprojects except the common project
*/
subprojects {
if (project.path == ":Common") {
return@subprojects
}
apply(plugin = "com.github.johnrengelman.shadow")
/**
* add the outputs of the common test source set to the test source set classpath
*/
sourceSets.named("test") {
val cst = project(":Common").sourceSets.getByName("test")
this.compileClasspath += cst.output
this.runtimeClasspath += cst.output
}
extensions.configure<LoomGradleExtensionAPI> {
runs {
create("test_client") {
name("Testmod Client")
client()
source(sourceSets.test.get())
property("fabric-api.gametest", "true")
property("neoforge.gameTestServer", "true")
property("neoforge.enabledGameTestNamespaces", "testmod")
property("$modId.gametest.testPackages", "testmod.*")
property("$modId.configDir", rootProject.projectDir.toPath().resolve("testmod_configs").toString())
}
create("gametest") {
name("Gametest")
server()
source(sourceSets.test.get())
property("fabric-api.gametest", "true")
property("neoforge.gameTestServer", "true")
property("neoforge.enabledGameTestNamespaces", "testmod")
property("$modId.gametest.testPackages", "testmod.*")
property("$modId.configDir", rootProject.projectDir.toPath().resolve("testmod_configs").toString())
}
forEach {
val dir = "../run/${project.name.lowercase()}_${it.environment}"
println("[Run Config] ${project.name} '${it.name}' directory: $dir")
it.runDir(dir)
// allows DCEVM hot-swapping when using the JBR (https://github.com/JetBrains/JetBrainsRuntime)
it.vmArgs("-XX:+IgnoreUnrecognizedVMOptions", "-XX:+AllowEnhancedClassRedefinition")
}
}
/**
* "main" matches the default mod name
* since `compileOnly()` is being used in Architectury, the local mods for the
* loaders need to be set up too
* otherwise, they won't recognize :Common.
*/
with(mods.maybeCreate("main")) {
fun Project.sourceSets() = extensions.getByName<SourceSetContainer>("sourceSets")
sourceSet(sourceSets().getByName("main"))
sourceSet(project(":Common").sourceSets().getByName("main"))
}
}
val common by configurations.creating
val shadowCommon by configurations.creating // don't use shadow from the plugin, IDEA shouldn't index this
configurations {
"compileClasspath" { extendsFrom(common) }
"runtimeClasspath" { extendsFrom(common) }
}
with(components["java"] as AdhocComponentWithVariants) {
withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) { skip() }
}
tasks {
named<ShadowJar>("shadowJar") {
exclude("architectury.common.json")
configurations = listOf(shadowCommon)
archiveClassifier.set("dev-shadow")
}
named<RemapJarTask>("remapJar") {
inputFile.set(named<ShadowJar>("shadowJar").get().archiveFile)
dependsOn("shadowJar")
archiveClassifier.set(null as String?)
injectAccessWidener.set(true)
}
named<Jar>("jar") {
archiveClassifier.set("dev")
}
named<Jar>("sourcesJar") {
val commonSources = project(":Common").tasks.named<Jar>("sourcesJar")
dependsOn(commonSources)
from(commonSources.get().archiveFile.map { zipTree(it) })
archiveClassifier.set("sources")
}
}
}