ViaFabric/build.gradle
2022-06-03 17:43:45 -03:00

225 lines
6.3 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 "com.modrinth.minotaur" version "2.2.0"
id "fabric-loom" version "0.12-SNAPSHOT" apply false
id "com.github.ben-manes.versions" version "0.42.0"
}
def ENV = System.getenv()
group = "com.viaversion.fabric"
description = "Client-side and server-side ViaVersion implementation for Fabric"
version = "0.4.7+" + 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> mcReleases = new ArrayList<>(
Arrays.asList("1.18.2", "1.17.1", "1.16.5", "1.15.2", "1.14.4", "1.8.9"))
List<String> 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<String> mcs = new ArrayList<>(mcReleases)
if (!rootProject.modrinth_mc_snapshot.isEmpty()) mcs.add(rootProject.modrinth_mc_snapshot)
gameVersions.set(mcs)
loaders.set(["fabric"])
dependencies {
optional.project "P7dR8mSH" // fabric api
}
}
defaultTasks("clean", "build")