Skip to content

Commit

Permalink
Vanilla production jar on modern ModLauncher
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeregorix committed Aug 31, 2024
1 parent 97cee47 commit 830d395
Show file tree
Hide file tree
Showing 16 changed files with 350 additions and 334 deletions.
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mixin = "0.8.7"
bootstrap = "2.1.1"
modlauncher = "10.2.1"
securemodules = "2.2.20"
jarjar = "0.3.26"
guava = "32.1.2-jre"
mockito = "5.11.0"
jline = "3.25.1"
Expand Down Expand Up @@ -55,6 +56,7 @@ mockito-junitJupiter = { module = "org.mockito:mockito-junit-jupiter", version.r

# vanilla
forgeAutoRenamingTool = { module = "net.minecraftforge:ForgeAutoRenamingTool", version.ref = "forgeAutoRenamingTool" }
jarjar-fs = { module = "net.minecraftforge:JarJarFileSystems", version.ref = "jarjar" }
jline-reader = { module = "org.jline:jline-reader", version.ref = "jline" }
jline-terminal = { module = "org.jline:jline-terminal", version.ref = "jline" }
jline-terminalJansi = { module = "org.jline:jline-terminal-jansi", version.ref = "jline" }
Expand Down
3 changes: 3 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2448,6 +2448,9 @@
<artifact name="JarJarFileSystems-0.3.26.jar">
<sha256 value="906f3b4f5402dfae04a78369f2964cb3985b3e80701e66430622af81f97896da" origin="Generated by Gradle"/>
</artifact>
<artifact name="JarJarFileSystems-0.3.26.module">
<sha256 value="0cad7d77d2a4eaa19cf371172030644d76277f523726a90f32a41ed5e07d7c3e" origin="Generated by Gradle"/>
</artifact>
<artifact name="JarJarFileSystems-0.3.26.pom">
<sha256 value="d4a66e3d462a7c9c146ee134a58b52f1fb19b2b91df06ff5346c8e0750442aaf" origin="Generated by Gradle"/>
</artifact>
Expand Down
179 changes: 112 additions & 67 deletions vanilla/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id("org.spongepowered.gradle.vanilla")
alias(libs.plugins.shadow)
Expand Down Expand Up @@ -30,6 +32,7 @@ val gameLibrariesConfig: NamedDomainObjectProvider<Configuration> = configuratio

val gameManagedLibrariesConfig: NamedDomainObjectProvider<Configuration> = configurations.register("spongeGameManagedLibraries")

val bootShadedLibrariesConfig: NamedDomainObjectProvider<Configuration> = configurations.register("spongeBootShadedLibraries")
val gameShadedLibrariesConfig: NamedDomainObjectProvider<Configuration> = configurations.register("spongeGameShadedLibraries")

val runTaskOnlyConfig: NamedDomainObjectProvider<Configuration> = configurations.register("runTaskOnly")
Expand Down Expand Up @@ -185,24 +188,26 @@ minecraft {
dependsOn(applaunchOutputs)
environment("MOD_CLASSES", applaunchOutputs.joinToString(";") { "applaunch%%$it" })

// Configure GAME and LANG resources
val resources = mutableListOf<FileCollection>()
resources.addAll(gameManagedLibrariesConfig.get().files.map { files(it) })
// Configure resources
val gameResources = mutableListOf<FileCollection>()
gameResources.addAll(gameManagedLibrariesConfig.get().files.map { files(it) })

resources.add(files(
gameResources.add(files(
main.get().output, vanillaMain.output,
mixins.get().output, vanillaMixins.output,
accessors.get().output, vanillaAccessors.output,
launch.get().output, vanillaLaunch.output,
gameShadedLibrariesConfig.get()
))

dependsOn(gameResources)
jvmArgs("-Dsponge.gameResources=" + gameResources.joinToString(";") { it.joinToString("&") })

testPluginsProject?.also {
resources.add(it.sourceSets.getByName("main").output)
val plugins: FileCollection = it.sourceSets.getByName("main").output
dependsOn(plugins)
environment("SPONGE_PLUGINS", plugins.joinToString("&"))
}

dependsOn(resources)
environment("SPONGE_PLUGINS", resources.joinToString(";") { it.joinToString("&") })
}
}
}
Expand Down Expand Up @@ -237,40 +242,36 @@ dependencies {
installer(platform(apiLibs.configurate.bom))
installer(apiLibs.configurate.hocon)
installer(apiLibs.configurate.core)
installer(libs.configurate.jackson)
installer(libs.joptSimple)
installer(libs.tinylog.api)
installer(libs.tinylog.impl)
// Override ASM versions, and explicitly declare dependencies so ASM is excluded from the manifest.
val asmExclusions = sequenceOf(libs.asm.asProvider(), libs.asm.commons, libs.asm.tree, libs.asm.analysis)
.onEach {
installer(it)
}.toSet()

installer(libs.asm.commons)
installer(libs.asm.tree)
installer(libs.forgeAutoRenamingTool) {
exclude(group = "net.sf.jopt-simple")
asmExclusions.forEach { exclude(group = it.get().group, module = it.get().name) } // Use our own ASM version
}

// Add the API as a runtime dependency, just so it gets shaded into the jar
add(vanillaInstaller.runtimeOnlyConfigurationName, "org.spongepowered:spongeapi:$apiVersion") {
isTransitive = false
exclude(group = "org.ow2.asm")
}

val init = initLibrariesConfig.name
init(libs.bootstrap)
init(libs.securemodules)
init(libs.asm.commons)
init(libs.asm.util)
init(libs.jarjar.fs)

val boot = bootLibrariesConfig.name
boot(libs.securemodules)
boot(libs.asm.commons)
boot(libs.asm.util)
boot(libs.bootstrap)

boot(libs.modlauncher) {
exclude(group = "org.apache.logging.log4j")
}
boot(apiLibs.pluginSpi) {
exclude(group = "org.checkerframework", module = "checker-qual")
// exclude(group = "com.google.code.gson", module = "gson")
exclude(group = "org.apache.logging.log4j", module = "log4j-api")
// exclude(group = "org.apache.commons", module = "commons-lang3")
}
boot(libs.lmaxDisruptor)
boot(apiLibs.checkerQual)
Expand All @@ -296,6 +297,10 @@ dependencies {
exclude(group = "org.spongepowered", module = "configurate-core")
exclude(group = "org.checkerframework", module = "checker-qual")
}
boot(libs.configurate.jackson) {
exclude(group = "org.spongepowered", module = "configurate-core")
exclude(group = "org.checkerframework", module = "checker-qual")
}

boot(libs.mixin)
boot(libs.asm.tree)
Expand All @@ -304,9 +309,11 @@ dependencies {
exclude(group = "org.checkerframework", module = "checker-qual")
}

boot("com.mojang:authlib:6.0.54") {
exclude(group = "com.google.guava", module = "guava")
}
// All minecraft deps except itself
configurations.minecraft.get().resolvedConfiguration.resolvedArtifacts
.map { it.id.componentIdentifier.toString() }
.filter { !it.startsWith("net.minecraft:joined") }
.forEach { boot(it) { isTransitive = false } }

boot(project(transformersProject.path))

Expand All @@ -319,15 +326,14 @@ dependencies {
exclude(group = "org.checkerframework", module = "checker-qual")
}
game(libs.javaxInject)
game(libs.configurate.jackson) {
exclude(group = "org.spongepowered", module = "configurate-core")
exclude(group = "org.checkerframework", module = "checker-qual")
}
game(libs.adventure.serializerAnsi) {
exclude(group = "org.jetbrains", module = "annotations")
exclude(group = "org.checkerframework", module = "checker-qual")
}

val bootShadedLibraries = bootShadedLibrariesConfig.name
bootShadedLibraries(project(transformersProject.path)) { isTransitive = false }

val gameShadedLibraries = gameShadedLibrariesConfig.name
gameShadedLibraries("org.spongepowered:spongeapi:$apiVersion") { isTransitive = false }

Expand Down Expand Up @@ -382,15 +388,12 @@ tasks {
manifest{
from(vanillaManifest)
attributes(
"Premain-Class" to "org.spongepowered.vanilla.installer.Agent",
"Agent-Class" to "org.spongepowered.vanilla.installer.Agent",
"Launcher-Agent-Class" to "org.spongepowered.vanilla.installer.Agent",
"Multi-Release" to true
"Main-Class" to "org.spongepowered.vanilla.installer.InstallerMain",
"Multi-Release" to true
)
}
from(vanillaInstaller.output)
}

val vanillaAppLaunchJar by registering(Jar::class) {
archiveClassifier.set("applaunch")
manifest.from(vanillaManifest)
Expand Down Expand Up @@ -420,66 +423,108 @@ tasks {
val installerResources = project.layout.buildDirectory.dir("generated/resources/installer")
vanillaInstaller.resources.srcDir(installerResources)

val downloadNotNeeded = configurations.register("downloadNotNeeded") {
extendsFrom(configurations.minecraft.get())
extendsFrom(gameShadedLibrariesConfig.get())
}

val emitDependencies by registering(org.spongepowered.gradle.impl.OutputDependenciesToJson::class) {
group = "sponge"
this.dependencies("bootstrap", bootLibrariesConfig)
this.dependencies("main", gameManagedLibrariesConfig)
this.excludedDependencies(gameShadedLibrariesConfig)
this.excludedDependencies(downloadNotNeeded)

outputFile.set(installerResources.map { it.file("libraries.json") })
}
named(vanillaInstaller.processResourcesTaskName).configure {
dependsOn(emitDependencies)
}

shadowJar {
val vanillaBootShadowJar by register("bootShadowJar", ShadowJar::class) {
group = "shadow"
archiveClassifier.set("boot")

mergeServiceFiles()
configurations = listOf(bootShadedLibrariesConfig.get())

manifest {
from(vanillaManifest)
attributes("Automatic-Module-Name" to "spongevanilla.boot")
}

configurations = listOf(project.configurations.getByName(vanillaInstaller.runtimeClasspathConfigurationName))
from(commonProject.sourceSets.named("applaunch").map { it.output })
from(vanillaAppLaunch.output)
}

val installerShadowJar by register("installerShadowJar", ShadowJar::class) {
group = "shadow"
archiveClassifier.set("installer-shadow")

mergeServiceFiles()
configurations = listOf(installerLibrariesConfig.get(), initLibrariesConfig.get())
exclude("META-INF/INDEX.LIST", "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "module-info.class")

archiveClassifier.set("universal")
manifest {
attributes(mapOf(
"Superclass-Transformer" to "common.superclasschange,vanilla.superclasschange",
"Access-Widener" to "common.accesswidener",
"MixinConfigs" to mixinConfigs.joinToString(","),
"Main-Class" to "org.spongepowered.vanilla.installer.InstallerMain",
"Launch-Target" to "sponge_server_prod",
"Multi-Release" to true,
"Premain-Class" to "org.spongepowered.vanilla.installer.Agent",
"Agent-Class" to "org.spongepowered.vanilla.installer.Agent",
"Launcher-Agent-Class" to "org.spongepowered.vanilla.installer.Agent"
))
from(vanillaManifest)
attributes(
mapOf("Implementation-Version" to libs.versions.asm.get()),
"org/objectweb/asm/"
"Main-Class" to "org.spongepowered.vanilla.installer.InstallerMain",
"Automatic-Module-Name" to "spongevanilla.installer",
"Launch-Target" to "sponge_server_prod",
"Multi-Release" to true
)
attributes(mapOf("Implementation-Version" to libs.versions.asm.get()), "org/objectweb/asm/")
}

from(vanillaInstaller.output)
}

shadowJar {
group = "shadow"
archiveClassifier.set("mod")

mergeServiceFiles()
configurations = listOf(gameShadedLibrariesConfig.get())

manifest {
from(vanillaManifest)
attributes(
"Superclass-Transformer" to "common.superclasschange,vanilla.superclasschange",
"Access-Widener" to "common.accesswidener",
"MixinConfigs" to mixinConfigs.joinToString(","),
"Multi-Release" to true
)
}

from(commonProject.sourceSets.main.map { it.output })
from(commonProject.sourceSets.named("mixins").map {it.output })
from(commonProject.sourceSets.named("accessors").map {it.output })
from(commonProject.sourceSets.named("launch").map {it.output })
from(commonProject.sourceSets.named("applaunch").map {it.output })
from(sourceSets.main.map {it.output })
from(vanillaInstaller.output)
from(vanillaAppLaunch.output)
from(commonProject.sourceSets.named("mixins").map { it.output })
from(commonProject.sourceSets.named("accessors").map { it.output })
from(commonProject.sourceSets.named("launch").map { it.output })

from(vanillaLaunch.output)
from(vanillaAccessors.output)
from(vanillaMixins.output)
/*dependencies {
// include(project(":"))
include("org.spongepowered:spongeapi:$apiVersion")
} */
}

val universalJar = register("universalJar", Jar::class) {
group = "build"
archiveClassifier.set("universal")

manifest.from(installerShadowJar.manifest)

from(installerShadowJar.archiveFile.map { zipTree(it) })

into("jars") {
from(shadowJar)
rename("spongevanilla-(.*)-mod.jar", "spongevanilla-mod.jar")

// We cannot have modules in a shaded jar
exclude("META-INF/versions/*/module-info.class")
exclude("module-info.class")
from(vanillaBootShadowJar)
rename("spongevanilla-(.*)-boot.jar", "spongevanilla-boot.jar")
}
}

assemble {
dependsOn(shadowJar)
dependsOn(universalJar)
}

}

indraSpotlessLicenser {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public final class Constants {

public static final class ManifestAttributes {
public static final String ACCESS_WIDENER = "Access-Widener";
public static final String LAUNCH_TARGET = "Launch-Target";
public static final String SUPERCLASS_CHANGE = "Superclass-Transformer";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.apache.logging.log4j.Logger;
import org.spongepowered.vanilla.applaunch.AppLaunchTarget;

import java.util.NoSuchElementException;

/**
* The common Sponge {@link ILaunchHandlerService launch handler} for development
* and production environments.
Expand All @@ -45,7 +47,10 @@ public String name() {
@Override
public ServiceRunner launchService(final String[] arguments, final ModuleLayer gameLayer) {
this.logger.info("Transitioning to Sponge launch, please wait...");
return () -> this.launchSponge(gameLayer.findModule("spongevanilla").orElseThrow(), arguments);
return () -> {
final Module module = gameLayer.findModule("spongevanilla").orElseThrow(() -> new NoSuchElementException("Module spongevanilla"));
this.launchSponge(module, arguments);
};
}

public abstract AppLaunchTarget target();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.spongepowered.plugin.blackboard.Keys;
import org.spongepowered.plugin.builtin.StandardEnvironment;
import org.spongepowered.plugin.builtin.jvm.JVMKeys;
import org.spongepowered.vanilla.applaunch.plugin.locator.SecureJarPluginResource;
import org.spongepowered.vanilla.applaunch.plugin.resource.SecureJarPluginResource;

import java.nio.file.Path;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import org.spongepowered.transformers.modlauncher.AccessWidenerTransformationService;
import org.spongepowered.transformers.modlauncher.SuperclassChanger;
import org.spongepowered.vanilla.applaunch.Constants;
import org.spongepowered.vanilla.applaunch.plugin.locator.SecureJarPluginResource;
import org.spongepowered.vanilla.applaunch.plugin.resource.SecureJarPluginResource;

import java.io.IOException;
import java.nio.file.Files;
Expand Down
Loading

0 comments on commit 830d395

Please sign in to comment.