forked from 62832/MEGACells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
245 lines (204 loc) · 7.14 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
import net.fabricmc.loom.api.LoomGradleExtensionAPI
import net.fabricmc.loom.task.RemapJarTask
plugins {
java
`maven-publish`
alias(libs.plugins.loom) apply false
alias(libs.plugins.vineflower) apply false
alias(libs.plugins.architectury)
alias(libs.plugins.shadow)
alias(libs.plugins.spotless)
}
val modId: String by project
val modVersion = (System.getenv("MEGA_VERSION") ?: "v0.0.0").substring(1)
val minecraftVersion: String = libs.versions.minecraft.get()
tasks {
register("releaseInfo") {
doLast {
val output = System.getenv("GITHUB_OUTPUT")
if (!output.isNullOrEmpty()) {
val outputFile = File(output)
outputFile.appendText("MOD_VERSION=$modVersion\n")
outputFile.appendText("MINECRAFT_VERSION=$minecraftVersion\n")
}
}
}
withType<Jar> {
enabled = false
}
}
subprojects {
apply(plugin = "java")
apply(plugin = rootProject.libs.plugins.architectury.get().pluginId)
apply(plugin = rootProject.libs.plugins.loom.get().pluginId)
apply(plugin = rootProject.libs.plugins.vineflower.get().pluginId)
apply(plugin = rootProject.libs.plugins.spotless.get().pluginId)
base.archivesName.set("$modId-${project.name}")
version = "$modVersion-$minecraftVersion"
group = property("mavenGroup").toString()
val javaVersion: String by project
java {
sourceCompatibility = JavaVersion.valueOf("VERSION_$javaVersion")
targetCompatibility = JavaVersion.valueOf("VERSION_$javaVersion")
withSourcesJar()
}
architectury {
minecraft = minecraftVersion
injectInjectables = false
}
configure<LoomGradleExtensionAPI> {
silentMojangMappingsLicense()
@Suppress("UnstableApiUsage")
mixin.defaultRefmapName.set("$modId.refmap.json")
}
repositories {
maven {
name = "ModMaven (K4U-NL)"
url = uri("https://modmaven.dev/")
content {
includeGroup("appeng")
includeGroup("mezz.jei")
}
}
maven {
name = "CurseMaven"
url = uri("https://cursemaven.com")
content {
includeGroup("curse.maven")
}
}
maven {
name = "Modrinth Maven"
url = uri("https://api.modrinth.com/maven")
content {
includeGroup("maven.modrinth")
}
}
}
dependencies {
"minecraft"(rootProject.libs.minecraft)
"mappings"(project.extensions.getByName<LoomGradleExtensionAPI>("loom").officialMojangMappings())
}
sourceSets {
create("data") {
val main = sourceSets.main.get()
compileClasspath += main.compileClasspath + main.output
runtimeClasspath += main.runtimeClasspath + main.output
}
}
tasks {
jar {
from(rootProject.file("LICENSE")) {
rename { "${it}_$modId"}
}
}
withType<JavaCompile> {
options.encoding = "UTF-8"
options.release.set(javaVersion.toInt())
}
}
spotless {
java {
target("src/**/java/**/*.java")
endWithNewline()
indentWithSpaces(4)
removeUnusedImports()
palantirJavaFormat()
importOrderFile(rootProject.file("codeformat/mega.importorder"))
// courtesy of diffplug/spotless#240
// https://github.com/diffplug/spotless/issues/240#issuecomment-385206606
custom("noWildcardImports") {
if (it.contains("*;\n")) {
throw Error("No wildcard imports allowed")
}
it
}
bumpThisNumberIfACustomStepChanges(1)
}
json {
target("src/**/resources/**/*.json")
targetExclude("src/generated/resources/**")
prettier().config(mapOf("parser" to "json"))
}
}
}
for (platform in property("enabledPlatforms").toString().split(',')) {
project(":$platform") {
apply(plugin = rootProject.libs.plugins.shadow.get().pluginId)
architectury {
platformSetupLoomIde()
loader(platform)
}
fun capitalise(str: String): String {
return str.replaceFirstChar {
if (it.isLowerCase()) {
it.titlecase()
} else {
it.toString()
}
}
}
val common: Configuration by configurations.creating
val shadowCommon: Configuration by configurations.creating
configurations {
compileClasspath.get().extendsFrom(common)
runtimeClasspath.get().extendsFrom(common)
getByName("development${capitalise(platform)}").extendsFrom(common)
}
dependencies {
common(project(path = ":common", configuration = "namedElements")) {
isTransitive = false
}
shadowCommon(project(path = ":common", configuration = "transformProduction${capitalise(platform)}")) {
isTransitive = false
}
}
sourceSets {
main {
resources {
srcDir(file("src/generated/resources"))
exclude("**/.cache")
}
}
getByName("data") {
val commonData = project(":common").sourceSets.getByName("data")
compileClasspath += commonData.output
runtimeClasspath += commonData.output
}
}
tasks {
processResources {
val commonProps by extra { mapOf(
"version" to project.version,
"minecraftVersion" to minecraftVersion,
"ae2Version" to rootProject.libs.versions.ae2.get(),
"ae2wtVersion" to rootProject.libs.versions.ae2wtlib.get(),
"appbotVersion" to rootProject.libs.versions.appbot.get())
}
inputs.properties(commonProps)
}
shadowJar {
exclude("architectury.common.json")
configurations = listOf(shadowCommon)
archiveClassifier.set("dev-shadow")
}
withType<RemapJarTask> {
inputFile.set(shadowJar.get().archiveFile)
dependsOn(shadowJar)
archiveClassifier.set(null as String?)
}
jar {
archiveClassifier.set("dev")
}
getByName<Jar>("sourcesJar") {
val commonSources = project(":common").tasks.getByName<Jar>("sourcesJar")
dependsOn(commonSources)
from(commonSources.archiveFile.map { zipTree(it) })
}
}
val javaComponent = components["java"] as AdhocComponentWithVariants
javaComponent.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) {
skip()
}
}
}