ViaForge/build.gradle

215 lines
7.2 KiB
Groovy
Raw Normal View History

buildscript {
repositories {
gradlePluginPortal()
2024-08-21 09:15:43 +02:00
maven { url = "https://maven.minecraftforge.net/" }
maven { url = "https://repo.spongepowered.org/repository/maven-public/" }
}
dependencies {
classpath "com.gradleup.shadow:shadow-gradle-plugin:8.3.3"
classpath "net.minecraftforge.gradle:ForgeGradle:6.+"
classpath "org.spongepowered:mixingradle:0.7-SNAPSHOT"
classpath "xyz.wagyourtail.jvmdowngrader:gradle-plugin:1.1.3"
}
}
allprojects {
apply plugin: "java-library"
2024-08-21 08:58:23 +02:00
apply plugin: "com.gradleup.shadow"
apply plugin: "xyz.wagyourtail.jvmdowngrader"
java {
2024-08-21 08:53:45 +02:00
// Minecraft 1.17+ required Java 17 to compile,
// Minecraft 1.20.5+ required Java 21 to compile
toolchain.languageVersion = JavaLanguageVersion.of(21)
}
2024-08-21 09:17:41 +02:00
// Configuration used to include dependencies to the final jars
configurations {
library
implementation.extendsFrom(library)
}
repositories {
2024-08-21 09:15:43 +02:00
maven {
url = "https://maven.minecraftforge.net/"
}
maven {
url = "https://repo.spongepowered.org/repository/maven-public"
}
maven {
url = "https://repo.viaversion.com"
metadataSources {
2024-08-21 09:17:41 +02:00
// Prevent Gradle from checking against correct Java version, needed since we downgrade libraries
// on include
mavenPom()
artifact()
}
}
}
dependencies {
// For common source code
compileOnly "io.netty:netty-all:4.1.114.Final"
library "com.viaversion:viaversion-common:5.1.1-SNAPSHOT"
library "com.viaversion:viabackwards-common:5.1.1-SNAPSHOT"
library "com.viaversion:viarewind-common:4.0.3"
library ("net.raphimc:ViaLegacy:3.0.5-SNAPSHOT") {
exclude group: "com.google.code.gson", module: "gson"
}
library "net.raphimc:viaaprilfools-common:3.0.4-SNAPSHOT"
library ("net.raphimc:ViaLoader:3.0.5-SNAPSHOT") {
exclude group: "com.google.guava"
exclude group: "org.slf4j"
}
}
}
subprojects {
apply plugin: "net.minecraftforge.gradle"
apply plugin: "org.spongepowered.mixin"
// Define the jar output attributes for all platforms
2024-08-05 18:43:36 +02:00
base {
group = project.maven_group
2024-08-05 19:43:31 +02:00
archivesName = project.name
2024-08-05 18:43:36 +02:00
version = project.maven_version
description = project.maven_description
2024-08-05 18:43:36 +02:00
}
2024-08-05 19:43:31 +02:00
def mcVersion = project.forge_version.split("-")[0]
// Used to execute code only for specific submodules
2024-08-05 19:43:31 +02:00
def versionId = Integer.parseInt(mcVersion.replace(".", ""))
compileJava.options.encoding = "UTF-8"
minecraft {
2024-08-05 19:43:31 +02:00
if (versionId >= 1_16_5) {
mappings channel: "official", version: mcVersion
}
runs {
client {
workingDirectory project.file("run")
property "forge.logging.markers", "REGISTRIES"
property "forge.logging.console.level", "debug"
// mixin
property "mixin.debug.export", "true"
property "mixin.hotSwap", "true"
property "fml.coreMods.load", "de.florianmichael.viaforge.mixin.MixinLoader" // Only required for MC 1.12, but modern Forges skips this anyway
2024-08-05 19:43:31 +02:00
args "-mixin.config=" + "mixins." + project.getProperty('name') + ".json"
// source set
mods {
2024-08-05 19:43:31 +02:00
"${project.name}" {
source sourceSets.main
}
}
}
}
}
sourceSets.main.resources {
srcDir "src/generated/resources"
}
dependencies {
2024-08-05 19:43:31 +02:00
minecraft "net.minecraftforge:forge:${forge_version}"
2024-04-28 18:54:38 +02:00
if (versionId >= 1_17_1) {
// Minecraft 1.17+ already includes slf4j, so we don't need to include it
compileOnly "org.slf4j:slf4j-api:${slf4j_version}"
} else {
library "org.slf4j:slf4j-api:${slf4j_version}"
}
library "org.spongepowered:mixin:${mixin_version}"
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"
library project(":") // Include the base project, to get Common-ViaForge
}
// Replace the version in the mcmod.info and mods.toml files with the project version
// Since this depends on the platform version, we can't define it in the global scope :(
tasks {
processResources {
for (final def file in ["mcmod.info", "META-INF/mods.toml"]) {
filesMatching(file) {
expand (
"version": project.version,
"description": project.description
)
}
}
}
}
mixin {
2024-08-05 19:43:31 +02:00
add sourceSets.main, "mixins.${project.name}.refmap.json"
}
jar {
manifest.attributes(
"Specification-Title": "viaforge",
"Specification-Vendor": "viaforge",
2023-12-08 16:24:17 +01:00
"Specification-Version": project.version,
"Implementation-Title": project.name,
2023-12-08 16:24:17 +01:00
"Implementation-Version": project.version,
"Implementation-Vendor" :"viaforge",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd"-"HH:mm:ssZ"),
"TweakClass": "org.spongepowered.asm.launch.MixinTweaker",
"TweakOrder": "0",
"FMLCorePluginContainsFMLMod": "true", // Only required for MC 1.12, but modern Forges skips this anyway
"FMLCorePlugin": "de.florianmichael.viaforge.mixin.MixinLoader", // Counterpart to the above
2024-08-05 19:43:31 +02:00
"MixinConfigs": "mixins.${project.name}.json",
"ForceLoadAsMod": "true"
)
enabled = false
}
shadowJar {
2024-04-28 18:54:38 +02:00
if (versionId >= 1_17_1) {
archiveFileName = jar.archiveFileName
2024-06-05 03:53:57 +02:00
} else {
destinationDirectory = temporaryDir
}
configurations = [project.configurations.library] // Include the dependencies from the include configuration
duplicatesStrategy DuplicatesStrategy.EXCLUDE
// Prevent conflicts with Forge's weird service loading
exclude("META-INF/maven/**")
exclude("META-INF/versions/**")
2024-04-28 18:54:38 +02:00
if (versionId >= 1_13_2) {
// We don't need to package mixins into Forge 1.13+ jars, since Forge already has it
exclude("org/spongepowered/**")
}
2024-04-28 18:54:38 +02:00
if (versionId >= 1_16_5) {
// Get rid of the services folder, since Forge 1.16+ would conflict with some of the ForgeDev Environment's services
// And since we don't need them for Mixins anyway, we can just exclude them from the shadowJar
exclude("META-INF/services/**")
}
}
downgradeJar {
inputFile = shadowJar.archiveFile
destinationDirectory = temporaryDir
}
shadeDowngradedApi {
archiveFileName = jar.archiveFileName
}
reobf {
shadowJar {}
}
jar.dependsOn("shadowJar")
if (versionId < 1_17_1) {
// Downgrade the jar to Java 8 for Minecraft 1.16.5 and below
jar.dependsOn("shadeDowngradedApi")
}
}