ViaFabric/build.gradle

251 lines
7.0 KiB
Groovy
Raw Normal View History

2021-07-16 12:03:07 +02:00
// todo migrate this code to kotlin
2022-01-26 13:05:18 +01:00
import com.google.gson.JsonParser
import java.nio.file.Files
2022-01-26 21:22:09 +01:00
import java.util.stream.Collectors
import java.util.stream.IntStream
2021-05-02 16:01:46 +02:00
// 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 "legacy-looming" version "1.6-SNAPSHOT" apply false // Version = fabric-loom
2024-02-03 22:55:55 +01:00
id "com.github.ben-manes.versions" version "0.51.0"
id "xyz.wagyourtail.jvmdowngrader" version "0.7.1"
2021-05-02 16:01:46 +02:00
}
def ENV = System.getenv()
2022-01-26 21:22:09 +01:00
group = "com.viaversion.fabric"
2021-05-02 19:13:07 +02:00
description = "Client-side and server-side ViaVersion implementation for Fabric"
version = "0.4.15+" + ENV.GITHUB_RUN_NUMBER + "-" + getBranch()
logger.lifecycle("Building ViaFabric: $version")
2021-05-02 16:01:46 +02:00
def getBranch() {
def ENV = System.getenv()
2023-03-14 20:52:50 +01:00
def branch = "unknown"
2021-05-02 16:01:46 +02:00
2023-03-14 20:52:50 +01:00
if (ENV.GITHUB_REF) {
branch = ENV.GITHUB_REF
} else if (grgit != null) {
branch = grgit.branch.current().name
2021-05-02 16:01:46 +02:00
}
return branch.substring(branch.lastIndexOf("/") + 1)
}
allprojects {
apply plugin: "maven-publish"
apply plugin: "fabric-loom"
apply plugin: "legacy-looming"
2021-05-02 16:01:46 +02:00
2022-04-23 12:17:36 +02:00
java {
toolchain {
// lwjgl2 works with Adoptium
languageVersion = JavaLanguageVersion.of(21)
2022-04-23 12:17:36 +02:00
vendor = JvmVendorSpec.ADOPTIUM
}
withSourcesJar()
}
2021-05-02 16:01:46 +02:00
tasks.withType(JavaCompile).configureEach {
2021-11-06 21:28:11 +01:00
it.options.release.set(8)
2021-05-02 16:01:46 +02:00
}
2022-04-23 12:17:36 +02:00
tasks.withType(JavaExec).configureEach {
it.javaLauncher.set(javaToolchains.launcherFor(java.toolchain))
}
2021-05-02 16:01:46 +02:00
2021-09-19 00:19:46 +02:00
version = rootProject.version
2022-01-26 21:22:09 +01:00
group = rootProject.group
2021-05-02 16:01:46 +02:00
repositories {
mavenCentral()
maven { url = "https://repo.viaversion.com/" }
maven { url = "https://maven.fabricmc.net/" }
maven { url = "https://maven.legacyfabric.net/" }
2021-10-23 16:55:23 +02:00
maven { url = "https://maven.terraformersmc.com/releases/" }
2022-01-26 13:05:18 +01:00
maven { url = "https://jitpack.io/" }
2021-05-02 16:01:46 +02:00
}
dependencies {
2021-09-24 23:23:06 +02:00
// transitive = false because Guava is conflicting on runClient
2022-01-26 21:22:09 +01:00
implementation("com.viaversion:viaversion:${rootProject.viaver_version}") { transitive = false }
2021-09-24 23:23:06 +02:00
2022-01-26 21:22:09 +01:00
modImplementation("net.fabricmc:fabric-loader:${rootProject.loader_version}")
2021-05-02 16:01:46 +02:00
}
2021-05-10 01:34:48 +02:00
processResources {
filesMatching("fabric.mod.json") {
2022-01-26 13:05:18 +01:00
it.expand(rootProject.properties)
2021-05-02 16:01:46 +02:00
}
}
}
2021-05-10 01:34:48 +02:00
subprojects {
loom {
runs {
named("client") {
client()
ideConfigGenerated(true)
runDir("run")
}
named("server") {
server()
ideConfigGenerated(true)
runDir("run")
}
}
}
2021-05-10 01:34:48 +02:00
dependencies {
implementation(project(path: ":", configuration: "namedElements")) {
2022-06-11 22:47:10 +02:00
exclude group: "net.fabricmc", module: "fabric-loader" // prevent duplicate fabric-loader on run
}
2021-05-02 16:01:46 +02:00
}
publishing {
publications {
mavenJava(MavenPublication) {
2021-11-25 23:26:02 +01:00
from components.java
2021-05-02 16:01:46 +02:00
}
}
setupRepositories(repositories)
}
}
publishing {
publications {
mavenJava(MavenPublication) {
2022-01-26 21:22:09 +01:00
from components.java
2021-05-02 16:01:46 +02:00
}
}
setupRepositories(repositories)
}
2021-11-06 21:28:11 +01:00
static void setupRepositories(RepositoryHandler repositories) {
2021-05-02 16:01:46 +02:00
//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
}
}
}
}
2024-01-21 10:43:22 +01:00
subprojects.each {
remapJar.dependsOn("${it.path}:remapJar")
}
configurations {
includeJ8
}
jvmdg.dg(configurations.includeJ8)
2021-05-02 16:01:46 +02:00
dependencies {
2021-11-06 21:50:53 +01:00
// dummy version
minecraft("com.mojang:minecraft:1.13.2")
mappings("net.legacyfabric:yarn:1.13.2+build.541:v2")
2021-05-02 16:01:46 +02:00
includeJ8("com.viaversion:viaversion:${rootProject.viaver_version}")
}
2021-05-02 17:01:24 +02:00
remapJar {
nestedJars.from configurations.includeJ8
afterEvaluate {
subprojects.each {
2024-01-21 10:43:22 +01:00
nestedJars.from project("${it.path}").tasks.named("remapJar")
}
2021-05-02 16:01:46 +02:00
}
}
2022-01-26 13:05:18 +01:00
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)
}
}
2023-03-14 20:52:50 +01:00
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)
2022-01-26 21:22:09 +01:00
.mapToObj { n -> (String) "Java $n" }
2022-05-22 18:12:13 +02:00
.collect(Collectors.toList())
String changelogMsg = "A changelog can be found at https://github.com/ViaVersion/ViaFabric/commits"
String versionNameMsg = "[${getBranch()}] ViaFabric " + rootProject.version
2022-01-26 21:22:09 +01:00
2021-05-02 16:01:46 +02:00
curseforge {
if (ENV.CURSEFORGE_API_KEY) {
apiKey = ENV.CURSEFORGE_API_KEY
}
project {
id = "391298"
2022-05-22 18:12:13 +02:00
changelog = changelogMsg
releaseType = "beta" // alpha is hidden by default
2022-01-26 21:22:09 +01:00
2022-05-22 18:12:13 +02:00
mcReleases.forEach { ver -> addGameVersion(ver) }
2022-06-03 22:43:45 +02:00
if (!rootProject.curseforge_mc_snapshot.isEmpty()) addGameVersion(rootProject.curseforge_mc_snapshot)
2022-05-22 18:12:13 +02:00
javaVersions.forEach(v -> addGameVersion(v))
addGameVersion("Fabric")
2021-05-02 16:01:46 +02:00
2021-11-26 23:02:09 +01:00
mainArtifact(remapJar) {
2022-05-22 18:12:13 +02:00
displayName = versionNameMsg
2021-05-02 17:01:24 +02:00
relations {
optionalDependency("legacy-fabric-api")
2021-05-02 17:01:24 +02:00
}
2021-05-02 16:01:46 +02:00
}
afterEvaluate {
uploadTask.dependsOn("remapJar")
}
}
options {
forgeGradleIntegration = false
}
}
2021-05-02 17:01:24 +02:00
2022-05-22 18:56:30 +02:00
modrinth {
token.set(ENV.MODRINTH_TOKEN)
projectId.set("YlKdE5VK")
2023-09-18 12:23:07 +02:00
versionType.set("alpha")
2022-05-22 18:56:30 +02:00
versionNumber.set(rootProject.version)
versionName.set(versionNameMsg)
changelog.set(changelogMsg)
2022-05-22 18:12:13 +02:00
2022-05-22 18:56:30 +02:00
uploadFile.set(remapJar)
2022-05-22 18:12:13 +02:00
2022-05-22 18:56:30 +02:00
List<String> mcs = new ArrayList<>(mcReleases)
2023-03-14 20:52:50 +01:00
if (!rootProject.modrinth_mc_snapshot.isEmpty()) mcs.add(rootProject.modrinth_mc_snapshot.toString())
2022-05-22 18:56:30 +02:00
gameVersions.set(mcs)
loaders.set(["fabric"])
2022-05-22 18:12:13 +02:00
dependencies {
optional.project "9CJED7xi" // legacy fabric api
2024-07-07 19:35:48 +02:00
embedded.project "P1OZGk5p" // viaversion
2022-05-22 18:12:13 +02:00
}
}
2022-05-22 19:23:17 +02:00
defaultTasks("clean", "build")