forked from ViaVersion/ViaFabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
235 lines (195 loc) · 6.61 KB
/
build.gradle
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
// todo migrate this code to kotlin
import com.google.gson.JsonParser
import java.nio.file.Files
import java.util.stream.Collectors
import java.util.stream.IntStream
// Stolen https://github.com/FabricMC/fabric/blob/1.17/build.gradle
plugins {
id "java"
id "maven-publish"
id "org.ajoberstar.grgit" version "5.2.2"
id "com.matthewprenger.cursegradle" version "1.4.0" // This repository is archived on GH
id "com.modrinth.minotaur" version "2.8.7"
id "fabric-loom" version "1.6-SNAPSHOT" apply false
id "com.github.ben-manes.versions" version "0.51.0"
id "xyz.wagyourtail.jvmdowngrader" version "0.7.1"
}
def ENV = System.getenv()
group = "com.viaversion.fabric"
description = "Client-side and server-side ViaVersion implementation for Fabric"
version = "0.4.15+" + ENV.GITHUB_RUN_NUMBER + "-" + getBranch()
logger.lifecycle("Building ViaFabric: $version")
def getBranch() {
def ENV = System.getenv()
def branch = "unknown"
if (ENV.GITHUB_REF) {
branch = ENV.GITHUB_REF
} else if (grgit != null) {
branch = grgit.branch.current().name
}
return branch.substring(branch.lastIndexOf("/") + 1)
}
allprojects {
apply plugin: "maven-publish"
apply plugin: "fabric-loom"
java {
toolchain {
// lwjgl2 works with Adoptium
languageVersion = JavaLanguageVersion.of(21)
vendor = JvmVendorSpec.ADOPTIUM
}
withSourcesJar()
}
tasks.withType(JavaCompile).configureEach {
it.options.release.set(8)
}
tasks.withType(JavaExec).configureEach {
it.javaLauncher.set(javaToolchains.launcherFor(java.toolchain))
}
version = rootProject.version
group = rootProject.group
repositories {
mavenCentral()
maven { url = "https://repo.viaversion.com/" }
maven { url = "https://maven.fabricmc.net/" }
maven { url = "https://maven.legacyfabric.net/" }
maven { url = "https://maven.terraformersmc.com/releases/" }
maven { url = "https://jitpack.io/" }
}
dependencies {
// transitive = false because Guava is conflicting on runClient
implementation("com.viaversion:viaversion:${rootProject.viaver_version}") { transitive = false }
modImplementation("net.fabricmc:fabric-loader:${rootProject.loader_version}")
}
processResources {
filesMatching("fabric.mod.json") {
it.expand(rootProject.properties)
}
}
}
subprojects {
dependencies {
implementation(rootProject) {
exclude group: "net.fabricmc", module: "fabric-loader" // prevent duplicate fabric-loader on run
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
setupRepositories(repositories)
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
setupRepositories(repositories)
}
static void setupRepositories(RepositoryHandler repositories) {
//repositories.mavenLocal() // uncomment for testing
def ENV = System.getenv()
if (ENV.MAVEN_URL) {
repositories.maven {
url ENV.MAVEN_URL
credentials {
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
}
}
}
}
subprojects.each {
remapJar.dependsOn("${it.path}:remapJar")
}
configurations {
includeJ8
}
jvmdg.dg(configurations.includeJ8)
dependencies {
// dummy version
minecraft("com.mojang:minecraft:1.14.4")
mappings("net.fabricmc:yarn:1.14.4+build.18:v2")
includeJ8("com.viaversion:viaversion:${rootProject.viaver_version}")
include("com.github.TinfoilMC:ClientCommands:1.1.0")
}
remapJar {
nestedJars.from configurations.includeJ8
afterEvaluate {
subprojects.each {
nestedJars.from project("${it.path}").tasks.named("remapJar")
}
}
}
processResources {
filesMatching("assets/*/lang/*.lang") {
HashMap<String, String> langMap = new HashMap<>()
Files.list(rootProject.file("src/main/resources/assets/viafabric/lang").toPath())
.filter(path -> path.toString().endsWith(".json"))
.forEach(path -> {
String legacyFile = "\n" + String.join("\n", JsonParser
.parseReader(Files.newBufferedReader(path)).asJsonObject.entrySet().stream()
.map(entry -> entry.key + "=" + entry.value.asString)
.toArray(String[]::new))
langMap.put(path.getFileName().toString().replace(".json", ""), legacyFile)
})
it.expand(langMap)
}
}
List<String> mcReleases = Arrays.stream(rootProject.publish_mc_versions.toString().split(","))
.map({ it -> it.trim() })
.collect(Collectors.toList())
List<String> javaVersions = IntStream.rangeClosed(8, 22)
.mapToObj { n -> (String) "Java $n" }
.collect(Collectors.toList())
String changelogMsg = "A changelog can be found at https://github.com/ViaVersion/ViaFabric/commits"
String versionNameMsg = "[${getBranch()}] ViaFabric " + rootProject.version
curseforge {
if (ENV.CURSEFORGE_API_KEY) {
apiKey = ENV.CURSEFORGE_API_KEY
}
project {
id = "391298"
changelog = changelogMsg
releaseType = "beta" // alpha is hidden by default
mcReleases.forEach { ver -> addGameVersion(ver) }
if (!rootProject.curseforge_mc_snapshot.isEmpty()) addGameVersion(rootProject.curseforge_mc_snapshot)
javaVersions.forEach(v -> addGameVersion(v))
addGameVersion("Fabric")
mainArtifact(remapJar) {
displayName = versionNameMsg
relations {
optionalDependency("fabric-api")
embeddedLibrary("cotton-client-commands")
}
}
afterEvaluate {
uploadTask.dependsOn("remapJar")
}
}
options {
forgeGradleIntegration = false
}
}
modrinth {
token.set(ENV.MODRINTH_TOKEN)
projectId.set("YlKdE5VK")
versionType.set("alpha")
versionNumber.set(rootProject.version)
versionName.set(versionNameMsg)
changelog.set(changelogMsg)
uploadFile.set(remapJar)
List<String> mcs = new ArrayList<>(mcReleases)
if (!rootProject.modrinth_mc_snapshot.isEmpty()) mcs.add(rootProject.modrinth_mc_snapshot.toString())
gameVersions.set(mcs)
loaders.set(["fabric"])
dependencies {
optional.project "P7dR8mSH" // fabric api
embedded.project "P1OZGk5p" // viaversion
}
}
defaultTasks("clean", "build")