ViaFabric/build.gradle
2022-04-23 07:17:36 -03:00

203 lines
5.7 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 "3.1.1"
id "com.matthewprenger.cursegradle" version "1.4.0"
id "fabric-loom" version "0.11-SNAPSHOT" apply false
id "com.github.ben-manes.versions" version "0.41.0"
}
def ENV = System.getenv()
group = "com.viaversion.fabric"
description = "Client-side and server-side ViaVersion implementation for Fabric"
version = "0.4.6+" + ENV.GITHUB_RUN_NUMBER + "-" + getBranch()
logger.lifecycle("Building ViaFabric: $version")
def getBranch() {
def ENV = System.getenv()
if (ENV.GITHUB_REF) {
def branch = ENV.GITHUB_REF
return branch.substring(branch.lastIndexOf("/") + 1)
}
if (grgit == null) {
return "unknown"
}
def 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
}
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<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> versionToAdd = new ArrayList<>(Arrays.asList("Fabric", "1.19-Snapshot", "1.18.2", "1.17.1",
"1.16.5", "1.15.2", "1.14.4", "1.8.9"))
versionToAdd.addAll(IntStream.rangeClosed(8, 18)
.mapToObj { n -> (String) "Java $n" }
.collect(Collectors.toList()))
curseforge {
if (ENV.CURSEFORGE_API_KEY) {
apiKey = ENV.CURSEFORGE_API_KEY
}
project {
id = "391298"
changelog = "A changelog can be found at https://github.com/ViaVersion/ViaFabric/commits"
releaseType = "alpha"
versionToAdd.forEach { ver -> addGameVersion(ver) }
mainArtifact(remapJar) {
displayName = "[${getBranch()}] ViaFabric " + rootProject.version
relations {
optionalDependency("fabric-api")
optionalDependency("legacy-fabric-api")
embeddedLibrary("cotton-client-commands")
}
}
afterEvaluate {
uploadTask.dependsOn("remapJar")
}
}
options {
forgeGradleIntegration = false
}
}
if (getBranch() == "main" && ENV.CURSEFORGE_API_KEY && !ENV.CURSEFORGE_API_KEY.isEmpty()) {
defaultTasks("clean", "build", "curseforge")
} else {
defaultTasks("clean", "build")
}