From 70a8663605afa6b41781c8480ddb0f4954ab9928 Mon Sep 17 00:00:00 2001 From: SizableShrimp Date: Sun, 5 Jun 2022 09:40:26 -0500 Subject: [PATCH] [1.18.x] Add checkJarCompatibility task (#8644) Signed-off-by: SizableShrimp --- build.gradle | 58 +++++++++++++++++-- ...DownloadBaseCompatibilityBinPatches.groovy | 39 +++++++++++++ 2 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 buildSrc/src/main/groovy/net/minecraftforge/forge/tasks/DownloadBaseCompatibilityBinPatches.groovy diff --git a/build.gradle b/build.gradle index 1d944207c4..d085d742ea 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:[5.1.26,)' + classpath 'net.minecraftforge.gradle:ForgeGradle:[5.1.39,)' } } @@ -17,6 +17,7 @@ import java.util.LinkedHashMap import net.minecraftforge.forge.tasks.* import static net.minecraftforge.forge.tasks.Util.* import net.minecraftforge.gradle.common.tasks.ApplyBinPatches +import net.minecraftforge.gradle.common.tasks.CheckJarCompatibility import net.minecraftforge.gradle.common.tasks.DownloadMavenArtifact import net.minecraftforge.gradle.common.tasks.ExtractInheritance import net.minecraftforge.gradle.common.tasks.SignJar @@ -69,6 +70,7 @@ ext { JAR_SPLITTER = 'net.minecraftforge:jarsplitter:1.1.4' FART = 'net.minecraftforge:ForgeAutoRenamingTool:0.1.22:all' MIN_TAG_FOR_CHANGELOG = "39.0" + LAST_RB = GIT_INFO.tag.rsplit('.', 1)[1] as int >= 1 ? GIT_INFO.tag + '.0' : null } println('Version: ' + VERSION + @@ -486,7 +488,7 @@ def sharedFmlonlyForge = { Project prj -> IGNORE_LIST: Util.getArtifacts(prj, prj.configurations.moduleonly, false).values().collect{it.downloads.artifact.path.rsplit('/', 1)[1]}.join(','), MODULES: 'ALL-MODULE-PATH' ] - + prj.task([dependsOn: rootProject.downloadServerRaw], 'makeClasspathFiles') { doLast { def CLASS_PATH = Util.getArtifacts(prj, prj.configurations.installer, false).values().collect{"libraries/${it.downloads.artifact.path}"} + @@ -845,7 +847,7 @@ project(':fmlonly') { } // Since we need the modules in the bootstrap, we need to make sure they are compiled before we do each run - afterEvaluate { prepareRuns.dependsOn(':fmlcore:jar', ':fmlloader:jar', ':javafmllanguage:jar', ':mclanguage:jar') } + afterEvaluate { prepareRuns.dependsOn(PACKED_DEPS) } } project(':forge') { @@ -1176,6 +1178,54 @@ project(':forge') { lineEnding = '\n' } + def baseForgeVersion = LAST_RB == null ? null : "${MC_VERSION}-${LAST_RB}" + + task downloadBaseCompatibilityBinPatches(type: DownloadBaseCompatibilityBinPatches) { + inputVersion = baseForgeVersion + } + + task applyBaseCompatibilityJarBinPatches(type: ApplyBinPatches) { + group = 'jar compatibility' + onlyIf { + baseForgeVersion != null + } + inputs.property 'baseForgeVersion', baseForgeVersion + + clean = createJoinedSRG.output + patch = downloadBaseCompatibilityBinPatches.output + output = project.layout.buildDirectory.dir(name).map { it.file('output.jar') } + } + + task checkJarCompatibility(type: CheckJarCompatibility) { + group = 'jar compatibility' + onlyIf { + baseForgeVersion != null + } + inputs.property 'baseForgeVersion', baseForgeVersion + + if (baseForgeVersion != null) { + def baseForgeUniversal = project.configurations.detachedConfiguration(project.dependencies.create("net.minecraftforge:forge:${baseForgeVersion}:universal")) + def fmlLibs = project.configurations.detachedConfiguration(PACKED_DEPS.collect { + def artifactId = it.split(':')[1] + return project.dependencies.create("net.minecraftforge:${artifactId}:${baseForgeVersion}") + }.toArray(Dependency[]::new)) + + baseJar = project.tasks.applyBaseCompatibilityJarBinPatches.output + baseLibraries.from(project.file(project.provider { + baseForgeUniversal.resolve().iterator().next() + })) + baseLibraries.from(project.tasks.createJoinedSRG.output) + baseLibraries.from(fmlLibs) + + inputJar = project.tasks.reobfJar.output + concreteLibraries.from(PACKED_DEPS.collect { rootProject.tasks.getByPath(it).archiveFile }) + + commonLibraries.from(project.configurations.minecraftImplementation) + commonLibraries.from(project.configurations.installer) + commonLibraries.from(project.configurations.moduleonly) + } + } + task launcherJson(type: LauncherJson) { packedDependencies = [':fmlloader:jar'] doFirst { @@ -1539,7 +1589,7 @@ project(':forge') { } } // Since we need the modules in the bootstrap, we need to make sure they are compiled before we do each run - afterEvaluate { prepareRuns.dependsOn(':fmlcore:jar', ':fmlloader:jar', ':javafmllanguage:jar', ':mclanguage:jar') } + afterEvaluate { prepareRuns.dependsOn(PACKED_DEPS) } tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation diff --git a/buildSrc/src/main/groovy/net/minecraftforge/forge/tasks/DownloadBaseCompatibilityBinPatches.groovy b/buildSrc/src/main/groovy/net/minecraftforge/forge/tasks/DownloadBaseCompatibilityBinPatches.groovy new file mode 100644 index 0000000000..9f1f1326c4 --- /dev/null +++ b/buildSrc/src/main/groovy/net/minecraftforge/forge/tasks/DownloadBaseCompatibilityBinPatches.groovy @@ -0,0 +1,39 @@ +package net.minecraftforge.forge.tasks + +import org.gradle.api.DefaultTask +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.Property +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction + +import java.nio.file.Files + +abstract class DownloadBaseCompatibilityBinPatches extends DefaultTask { + DownloadBaseCompatibilityBinPatches() { + group = 'jar compatibility' + onlyIf { + inputVersion.getOrNull() != null + } + + output.convention(project.layout.buildDirectory.dir(name).map { it.file('joined.lzma') }) + } + + @TaskAction + void run() { + def dep = project.dependencies.create("net.minecraftforge:forge:${inputVersion.get()}:userdev") + def baseForgeUserdev = project.configurations.detachedConfiguration(dep).resolve().iterator().next() + + def joinedLzma = project.zipTree(baseForgeUserdev).matching { it.include('joined.lzma') }.singleFile + + Files.copy(joinedLzma.toPath(), output.get().asFile.toPath()) + } + + @Input + @Optional + abstract Property getInputVersion() + + @OutputFile + abstract RegularFileProperty getOutput() +}