ViaFabric/build.gradle

210 lines
5.7 KiB
Groovy
Raw Normal View History

2021-07-16 12:03:07 +02:00
// todo migrate this code to kotlin
2021-09-19 00:19:46 +02:00
import net.fabricmc.loom.task.RemapJarTask
import org.apache.tools.ant.filters.ReplaceTokens
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"
id "com.matthewprenger.cursegradle" version "1.4.0"
2021-11-06 21:28:11 +01:00
id "fabric-loom" version "0.10-SNAPSHOT" apply false
2021-05-02 16:01:46 +02:00
}
def ENV = System.getenv()
2021-11-26 23:02:09 +01:00
def vvVer = "4.1.0-1.18-rc3-SNAPSHOT"
2021-06-17 20:04:30 +02:00
def yamlVer = "1.29"
2021-05-02 16:01:46 +02:00
2021-05-02 19:13:07 +02:00
description = "Client-side and server-side ViaVersion implementation for Fabric"
2021-10-29 23:43:18 +02:00
version = "0.4.4+" + 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"
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
}
group = "com.viaversion.fabric"
2021-09-19 00:19:46 +02:00
version = rootProject.version
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-11-06 21:28:11 +01:00
maven { url = "https://server.bbkr.space/artifactory/libs-release" }
2021-10-23 16:55:23 +02:00
maven { url = "https://maven.terraformersmc.com/releases/" }
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
implementation("com.viaversion:viaversion:$vvVer") { transitive = false }
implementation("org.yaml:snakeyaml:$yamlVer")
2021-11-06 21:28:11 +01:00
modImplementation("net.fabricmc:fabric-loader:0.12.5")
2021-05-02 16:01:46 +02:00
}
2021-05-10 01:34:48 +02:00
processResources {
filesMatching("fabric.mod.json") {
filter(ReplaceTokens, tokens: [
2021-05-10 01:34:48 +02:00
version : rootProject.version,
description: rootProject.description
])
2021-05-02 16:01:46 +02:00
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
2021-11-06 21:28:11 +01:00
archiveClassifier.set("sources")
2021-05-02 16:01:46 +02:00
from sourceSets.main.allSource
}
}
2021-05-10 01:34:48 +02:00
subprojects {
dependencies {
implementation rootProject
2021-05-02 16:01:46 +02:00
}
task remapMavenJar(type: Copy, dependsOn: remapJar) {
afterEvaluate {
from("${project.buildDir}/libs/$archivesBaseName-${version}.jar")
into("${project.buildDir}/libs/")
rename { String fn -> "$archivesBaseName-${version}-maven.jar" }
}
}
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)
}
}
2021-09-19 00:19:46 +02:00
task remapMavenJar(type: RemapJarTask, dependsOn: jar) {
2021-05-02 16:01:46 +02:00
afterEvaluate {
2021-11-26 23:02:09 +01:00
input = jar.archiveFile
2021-05-02 17:01:24 +02:00
archiveFileName = "${archivesBaseName}-${version}-maven.jar"
2021-11-06 21:28:11 +01:00
addNestedDependencies.set(false)
2021-05-02 16:01:46 +02:00
}
}
2021-11-26 23:02:09 +01:00
build.dependsOn remapMavenJar
2021-05-02 16:01:46 +02:00
publishing {
publications {
mavenJava(MavenPublication) {
2021-11-26 23:02:09 +01:00
artifact(remapMavenJar) {
builtBy remapMavenJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
2021-05-02 16:01:46 +02:00
pom.withXml {
2021-11-26 23:02:09 +01:00
def depsNode = asNode().appendNode("dependencies")
2021-05-02 16:01:46 +02:00
subprojects.each {
def depNode = depsNode.appendNode("dependency")
depNode.appendNode("groupId", it.group)
depNode.appendNode("artifactId", it.name)
depNode.appendNode("version", it.version)
depNode.appendNode("scope", "compile")
}
}
}
}
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
2021-05-06 01:11:28 +02:00
include("com.viaversion:viaversion:$vvVer")
2021-06-17 20:04:30 +02:00
include("org.yaml:snakeyaml:$yamlVer")
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
}
}
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"
2021-09-28 12:25:37 +02:00
Arrays.<String> asList("1.18-Snapshot", "1.17.1", "1.16.5", "1.15.2", "1.14.4", "1.8.9",
2021-09-18 22:53:00 +02:00
"Java 8", "Java 9", "Java 10", "Java 11", "Java 12", "Java 13", "Java 14", "Java 15", "Java 16", "Java 17", "Fabric")
2021-05-02 17:01:24 +02:00
.forEach { ver -> addGameVersion(ver) }
2021-05-02 16:01:46 +02:00
2021-11-26 23:02:09 +01:00
mainArtifact(remapJar) {
2021-05-02 19:35:52 +02:00
displayName = "[${getBranch()}] ViaFabric " + rootProject.version
2021-05-02 17:01:24 +02:00
relations {
optionalDependency("fabric-api")
optionalDependency("legacy-fabric-api")
2021-05-02 17:26:15 +02:00
optionalDependency("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
2021-05-02 18:49:49 +02:00
if (getBranch() == "main" && ENV.CURSEFORGE_API_KEY && !ENV.CURSEFORGE_API_KEY.isEmpty()) {
2021-05-02 17:01:24 +02:00
defaultTasks("clean", "build", "curseforge")
} else {
defaultTasks("clean", "build")
2021-05-02 18:21:27 +02:00
}