-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
283 lines (227 loc) Β· 7.35 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
import net.fabricmc.loom.task.RemapJarTask
import java.net.URI
plugins {
`java-library`
`maven-publish`
id("fabric-loom") version "1.7-SNAPSHOT"
}
class ModInfo {
val id = property("mod.id").toString()
val group = property("mod.group").toString()
val version = property("mod.version").toString()
}
class Dependencies {
val minecraft = property("deps.minecraft").toString()
val loader = property("deps.loader").toString()
val yarn = property("deps.yarn").toString()
val fabricApi = property("deps.fabricapi").toString()
}
allprojects {
apply(plugin = "java-library")
apply(plugin = "maven-publish")
apply(plugin = "fabric-loom")
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.release = 21
}
java {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
val mod = ModInfo()
val deps = Dependencies()
group = mod.group
version = mod.version
dependencies {
minecraft("com.mojang:minecraft:${deps.minecraft}")
mappings("net.fabricmc:yarn:${deps.yarn}:v2")
modImplementation("net.fabricmc:fabric-loader:${deps.loader}")
modImplementation("net.fabricmc.fabric-api:fabric-api:${deps.fabricApi}")
}
tasks.withType<ProcessResources> {
inputs.property("id", mod.id)
inputs.property("version", mod.version)
inputs.property("loader_version", deps.loader)
inputs.property("minecraft_version", deps.minecraft)
val map = mapOf(
"id" to mod.id,
"version" to mod.version,
"loader_version" to deps.loader,
"minecraft_version" to deps.minecraft
)
filesMatching("fabric.mod.json") { expand(map) }
}
loom {
splitEnvironmentSourceSets()
if (file("src/main/resources/${project.name}.accesswidener").exists()) accessWidenerPath =
file("src/main/resources/${project.name}.accesswidener")
}
for (modProject in allprojects) {
loom.mods.register(modProject.name) {
sourceSet(modProject.sourceSets.getByName("main"))
sourceSet(modProject.sourceSets.getByName("client"))
}
loom.mods.register(modProject.name + "-testmod") {
sourceSet(modProject.sourceSets.getByName("testmod"))
sourceSet(modProject.sourceSets.getByName("testmodClient"))
}
}
tasks.withType<GenerateModuleMetadata>().configureEach {
enabled = false
}
}
tasks.javadoc {
with(options as StandardJavadocDocletOptions) {
source = "21"
encoding = "UTF-8"
charset("UTF-8")
memberLevel = JavadocMemberLevel.PACKAGE
addStringOption("Xdoclint:none", "-quiet")
}
allprojects.forEach { proj ->
source(proj.sourceSets.main.map { it.allJava.srcDirs })
source(proj.sourceSets.getByName("client").allSource.srcDirs)
}
classpath = project.files(sourceSets.main.map { it.compileClasspath }, sourceSets.getByName("client").compileClasspath)
include("**/api/**")
isFailOnError = false
}
val javadocJar by tasks.registering(Jar::class) {
dependsOn(tasks.javadoc)
from(tasks.javadoc.map { it.destinationDir!! })
archiveClassifier.set("fatjavadoc")
}
tasks.assemble.configure {
dependsOn(javadocJar)
}
tasks.test.configure {
dependsOn(tasks.named("runGametest"))
}
subprojects {
version = rootProject.version
sourceSets.create("testmod") {
compileClasspath += sourceSets.main.get().compileClasspath
runtimeClasspath += sourceSets.main.get().runtimeClasspath
}
sourceSets.create("testmodClient") {
compileClasspath += sourceSets.main.get().compileClasspath
runtimeClasspath += sourceSets.main.get().runtimeClasspath
compileClasspath += sourceSets.getByName("client").compileClasspath
runtimeClasspath += sourceSets.getByName("client").runtimeClasspath
compileClasspath += sourceSets.getByName("testmod").compileClasspath
runtimeClasspath += sourceSets.getByName("testmod").runtimeClasspath
}
dependencies {
"testmodImplementation"(sourceSets.main.map { it.output })
"testmodClientImplementation"(sourceSets.getByName("client").output)
"testmodClientImplementation"(sourceSets.getByName("testmod").output)
}
extensions.configure(PublishingExtension::class.java) {
publications {
create("mavenJava", MavenPublication::class.java) {
from(components.getByName("java"))
}
}
repositories {
maven {
name = "EchosMavenReleases"
url = URI("https://maven.callmeecho.dev/releases")
credentials(PasswordCredentials::class)
}
}
}
tasks.javadoc.configure {
isEnabled = false
}
}
val remapMavenJar by tasks.registering(RemapJarTask::class) {
inputFile.set(tasks.jar.flatMap { it.archiveFile })
archiveFileName.set("${project.properties["archivesBaseName"]}-${project.version}-maven.jar")
addNestedDependencies = false
dependsOn(tasks.jar)
}
tasks.assemble.configure {
dependsOn(remapMavenJar)
}
extensions.configure(PublishingExtension::class.java) {
publications {
val mavenJava by creating(MavenPublication::class) {
artifact(remapMavenJar) {
builtBy(remapMavenJar)
}
artifact(tasks.named("sourcesJar")) {
builtBy(tasks.remapSourcesJar)
}
artifact(tasks.named("javadocJar"))
pom.withXml {
val depsNode = asNode().appendNode("dependencies")
subprojects.forEach {
val depNode = depsNode.appendNode("dependency")
depNode.appendNode("groupId", it.group)
depNode.appendNode("artifactId", it.name)
depNode.appendNode("version", it.version)
depNode.appendNode("scope", "compile")
}
}
}
@Suppress("UnstableApiUsage")
loom.disableDeprecatedPomGeneration(mavenJava)
}
repositories {
maven {
name = "EchosMavenReleases"
url = URI("https://maven.callmeecho.dev/releases")
credentials(PasswordCredentials::class)
}
}
}
sourceSets.create("testmod") {
compileClasspath += sourceSets.main.get().compileClasspath
runtimeClasspath += sourceSets.main.get().runtimeClasspath
}
sourceSets.create("testmodClient") {
compileClasspath += sourceSets.main.get().compileClasspath
runtimeClasspath += sourceSets.main.get().runtimeClasspath
compileClasspath += sourceSets.getByName("client").compileClasspath
runtimeClasspath += sourceSets.getByName("client").runtimeClasspath
compileClasspath += sourceSets.getByName("testmod").compileClasspath
runtimeClasspath += sourceSets.getByName("testmod").runtimeClasspath
}
loom {
runs.create("testmodClient") {
client()
ideConfigGenerated(project.rootProject == project)
name = "Testmod Client"
source(sourceSets.getByName("testmodClient"))
}
runs.create("testmodServer") {
server()
ideConfigGenerated(project.rootProject == project)
name = "Testmod Server"
source(sourceSets.getByName("testmod"))
}
runs.create("gametest") {
server()
ideConfigGenerated(project.rootProject == project)
name = "Game Test"
source(sourceSets.getByName("testmod"))
vmArg("-Dfabric-api.gametest")
vmArg("-Dfabric-api.gametest.report-file=${project.layout.buildDirectory.get()}/junit.xml")
runDir = "build/gametest"
}
}
dependencies {
afterEvaluate {
subprojects.forEach {
api(project(":${it.name}", "namedElements"))
"clientImplementation"(project(":${it.name}").sourceSets.getByName("client").output)
include(project("${it.name}:"))
compileOnly("org.tomlj:tomlj:${property("deps.tomlj")}")
"testmodImplementation"("org.tomlj:tomlj:${property("deps.tomlj")}")
"testmodImplementation"(project(":${it.name}").sourceSets["testmod"].output)
"testmodClientImplementation"(project("${it.name}:").sourceSets["testmodClient"].output)
}
}
}
for (subproject in subprojects) tasks.remapJar.configure { dependsOn(":${subproject.name}:remapJar") }