ViaFabric/build.gradle

240 lines
6.9 KiB
Groovy

// 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.14+" + 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 }
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")
}
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("org.yaml:snakeyaml:${rootProject.yaml_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")
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<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
optional.project "9CJED7xi" // legacy fabric api
embedded.project "P1OZGk5p" // viaversion
}
}
defaultTasks("clean", "build")