forked from homchom/recode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
229 lines (194 loc) · 6.99 KB
/
build.gradle.kts
File metadata and controls
229 lines (194 loc) · 6.99 KB
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
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.9.23"
id("fabric-loom") version "1.5-SNAPSHOT"
id("com.modrinth.minotaur") version "2.+"
id("com.github.johnrengelman.shadow") version "7.1.2"
}
val modName: String by project
val modVersion: String by project
val minecraftVersion: String by project
val modVersionWithMeta get() = "$modVersion+$minecraftVersion"
version = "$modVersionWithMeta-LATEST"
val mavenGroup: String by project
group = mavenGroup
val fabricVersion: String by project
val loaderVersion: String by project
val flkVersion: String by project
val requiredDependencyMods = dependencyModsOfType("required")
val optionalDependencyMods = dependencyModsOfType("optional")
base {
archivesName.set(modName)
}
repositories {
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = uri("https://api.modrinth.com/maven")
}
}
filter { includeGroup("maven.modrinth") }
}
maven {
name = "CottonMC"
url = uri("https://server.bbkr.space/artifactory/libs-release")
}
maven {
url = uri("https://maven.shedaniel.me/")
}
maven {
url = uri("https://maven.terraformersmc.com/")
}
maven {
url = uri("https://jitpack.io")
}
mavenCentral()
}
val shade: Configuration by configurations.creating {
isCanBeResolved = true
// exclude slf4j because it is already provided by Minecraft TODO: can this workaround be removed now?
exclude(group = "org.slf4j")
}
dependencies {
// minecraft
minecraft("com.mojang:minecraft:$minecraftVersion")
mappings(loom.officialMojangMappings())
// fabric
modImplementation("net.fabricmc.fabric-api:fabric-api:$fabricVersion")
modImplementation("net.fabricmc:fabric-loader:$loaderVersion")
// kotlin
modImplementation("net.fabricmc:fabric-language-kotlin:$flkVersion")
// mod dependencies listed in gradle.properties
for (mod in requiredDependencyMods) {
include(modImplementation("${mod.artifact}:${mod.version}")!!)
}
for (mod in optionalDependencyMods) {
modCompileOnly("${mod.artifact}:${mod.version}")
}
// Websocket TODO: clean this up
shade(implementation("org.java-websocket:Java-WebSocket:1.5.3")!!)
include(implementation("javax.websocket:javax.websocket-api:1.1")!!)
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present. If you remove this line, sources will not be generated.
withSourcesJar()
}
tasks {
withType<JavaCompile> {
options.encoding = "UTF-8"
}
withType<KotlinCompile> {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
freeCompilerArgs.set(listOf(
"-Xjvm-default=all",
))
}
}
processResources {
// these properties can be used in fabric_mod_json_template.txt in Groovy template syntax
val exposedProperties = arrayOf(
"modName" to modName,
"version" to modVersion,
"minecraftVersion" to minecraftVersion,
"loaderVersion" to loaderVersion,
"fabricVersion" to fabricVersion,
"flkVersion" to flkVersion
)
inputs.properties(*exposedProperties)
inputs.properties(project.properties.filterKeys { it.startsWith("required.") })
// evaluate fabric_mod_json_template.txt as a Groovy template
filesMatching("fabric_mod_json_template.txt") {
val metadataRegex = Regex("""\+.+$""")
expand(
*exposedProperties,
"metadataRegex" to metadataRegex.toPattern(),
"dependencyMods" to requiredDependencyMods.joinToString(", ") { mod ->
val version = mod.version.replace(metadataRegex, "")
"\"${mod.id}\": \"${mod.versionSpec}$version\""
}
)
}
rename("fabric_mod_json_template.txt", "fabric.mod.json")
}
jar {
// disable jar (in favor of shadowJar)
enabled = false
}
val relocate by registering(ConfigureShadowRelocation::class) {
// repackage shaded dependencies
target = shadowJar.get()
prefix = "$mavenGroup.recode.shaded"
}
shadowJar {
dependsOn(relocate.get())
configurations = listOf(shade)
// output shaded jar in the correct destination to be used by remapJar
destinationDirectory.set(file("build/devlibs"))
archiveClassifier.set("dev")
from("LICENSE")
}
remapJar {
// use the shaded jar with remapJar
inputFile.value(shadowJar.get().archiveFile)
}
}
tasks.modrinth.get().dependsOn(tasks.modrinthSyncBody)
modrinth {
// DO NOT PUT THIS IN RECODE'S GRADLE.PROPERTIES. Your modrinth token should remain private to everyone.
token.set(findProperty("privateModrinthToken")?.toString() ?: "")
projectId.set("recode")
versionNumber.set(modVersionWithMeta)
val match = Regex("""-(?<phase>beta|alpha)\.""").find(modVersion)
if (match == null) {
versionName.set(modVersion)
versionType.set("release")
} else {
val phase = match.groups["phase"]!!.value
versionName.set(modVersion.replaceRange(match.range, " $phase "))
versionType.set(phase)
}
// remove "LATEST" classifiers when uploading to modrinth
uploadFile.set(tasks.remapJar.map { task ->
val jarFile = task.archiveFile.get().asFile
val newPath = jarFile.path.replace("-LATEST", "")
jarFile.renameTo(File(newPath))
newPath
})
gameVersions.addAll(minecraftVersion)
dependencies {
required.version("fabric-api", fabricVersion)
}
// TODO: use something other than readText?
syncBodyFrom.set(file("README.md").readText())
changelog.set(file("CHANGELOG.md").readText())
}
data class DependencyMod(
val id: String,
val artifact: String,
val version: String,
val versionSpec: String
) {
constructor(id: String, artifact: Any?, version: Any?, versionSpec: Any?) :
this(id, artifact.toString(), version.toString(), versionSpec.toString())
}
/**
* @return The list of [DependencyMod] values matching [type] in gradle.properties.
*/
fun dependencyModsOfType(type: String): List<DependencyMod> {
val regex = Regex("""$type\.([^\.]+)\.artifact""")
return properties.mapNotNull { (key, value) ->
regex.matchEntire(key)?.let { match ->
val id = match.groupValues[1]
val version = project.properties["$type.$id.version"]
val versionSpec = project.properties.getOrDefault("$type.$id.versionSpec", "^")
DependencyMod(id, value, version, versionSpec)
}
}
}