// 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.1" id "com.matthewprenger.cursegradle" version "1.4.0" id "com.modrinth.minotaur" version "2.8.7" id "fabric-loom" version "1.5-SNAPSHOT" apply false id "com.github.ben-manes.versions" version "0.50.0" } def ENV = System.getenv() group = "com.viaversion.fabric" description = "Client-side and server-side ViaVersion implementation for Fabric" version = "0.4.12+" + 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(17) 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 } implementation("org.yaml:snakeyaml:${rootProject.yaml_version}") 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") } dependencies { // dummy version minecraft("com.mojang:minecraft:1.14.4") mappings("net.fabricmc:yarn:1.14.4+build.18:v2") include("com.viaversion:viaversion:${rootProject.viaver_version}") include("org.yaml:snakeyaml:${rootProject.yaml_version}") include("com.github.TinfoilMC:ClientCommands:1.1.0") subprojects.each { include project("${it.name}:") } } processResources { filesMatching("assets/*/lang/*.lang") { HashMap 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 mcReleases = Arrays.stream(rootProject.publish_mc_versions.toString().split(",")) .map({ it -> it.trim() }) .collect(Collectors.toList()) List javaVersions = IntStream.rangeClosed(8, 18) .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 = "alpha" 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") optionalDependency("legacy-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 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 optional.project "9CJED7xi" // legacy fabric api } } defaultTasks("clean", "build")