ViaFabric/build.gradle

225 lines
6.3 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 "3.1.1"
2022-01-26 21:31:31 +01:00
id "com.matthewprenger.cursegradle" version "1.4.0"
2022-05-22 18:56:30 +02:00
id "com.modrinth.minotaur" version "2.2.0"
2022-05-28 22:23:07 +02:00
id "fabric-loom" version "0.12-SNAPSHOT" apply false
id "com.github.ben-manes.versions" version "0.42.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"
2022-05-22 19:23:17 +02:00
version = "0.4.7+" + ENV.GITHUB_RUN_NUMBER + "-" + getBranch()
logger.lifecycle("Building ViaFabric: $version")
2021-05-02 16:01:46 +02:00
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"
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 {
implementation rootProject
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)
}
}
2022-05-22 18:12:13 +02:00
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)
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
2021-05-02 16:01:46 +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")
versionType.set("alpha")
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)
2022-06-03 22:43:45 +02:00
if (!rootProject.modrinth_mc_snapshot.isEmpty()) mcs.add(rootProject.modrinth_mc_snapshot)
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
}
}
2022-05-22 19:23:17 +02:00
defaultTasks("clean", "build")