ViaFabric/build.gradle

227 lines
6.5 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.1"
2022-01-26 21:31:31 +01:00
id "com.matthewprenger.cursegradle" version "1.4.0"
id "com.modrinth.minotaur" version "2.8.7"
2023-10-16 14:24:59 +02:00
id "fabric-loom" version "1.4-SNAPSHOT" apply false
id "com.github.ben-manes.versions" version "0.50.0"
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"
2023-12-05 20:37:05 +01:00
version = "0.4.12+" + 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"
2022-04-23 12:17:36 +02:00
java {
toolchain {
// lwjgl2 works with Adoptium
languageVersion = JavaLanguageVersion.of(17)
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 }
implementation("org.yaml:snakeyaml:${rootProject.yaml_version}")
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 {
dependencies {
2023-03-14 20:52:50 +01:00
implementation(rootProject) {
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
}
}
}
}
2021-06-04 20:26:43 +02:00
subprojects.each {
remapJar.dependsOn("${it.path}:remapJar")
}
2021-05-02 16:01:46 +02:00
dependencies {
2021-11-06 21:50:53 +01:00
// dummy version
minecraft("com.mojang:minecraft:1.14.4")
mappings("net.fabricmc:yarn:1.14.4+build.18:v2")
2021-05-02 16:01:46 +02:00
2022-01-26 21:22:09 +01:00
include("com.viaversion:viaversion:${rootProject.viaver_version}")
include("org.yaml:snakeyaml:${rootProject.yaml_version}")
include("com.github.TinfoilMC:ClientCommands:1.1.0")
2021-05-02 17:01:24 +02:00
2021-05-10 01:34:48 +02:00
subprojects.each {
include project("${it.name}:")
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())
2022-05-22 18:12:13 +02:00
List<String> javaVersions = IntStream.rangeClosed(8, 18)
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
2023-09-18 12:23:07 +02:00
releaseType = "alpha"
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("fabric-api")
2022-01-26 21:22:09 +01:00
optionalDependency("legacy-fabric-api")
2022-01-19 13:07:36 +01:00
embeddedLibrary("cotton-client-commands")
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 "P7dR8mSH" // fabric api
2023-01-26 11:36:23 +01:00
optional.project "9CJED7xi" // legacy fabric api
2022-05-22 18:12:13 +02:00
}
}
2022-05-22 19:23:17 +02:00
defaultTasks("clean", "build")