From d53cc32ac0ace3e75359d02ddcaa8c651048c847 Mon Sep 17 00:00:00 2001 From: Yeregorix Date: Sat, 30 Nov 2024 17:04:16 +0100 Subject: [PATCH 1/9] Fix SpongeVanilla IDE run configurations --- .gitignore | 1 - gradle/libs.versions.toml | 1 + modlauncher-transformers/build.gradle.kts | 9 +- .../src/main/resources/META-INF/MANIFEST.MF | 1 + vanilla/build.gradle.kts | 111 +++++------ .../applaunch/resources/META-INF/MANIFEST.MF | 1 + vanilla/src/devlaunch/java/module-info.java | 6 + .../vanilla/devlaunch/SourceSet.java | 87 ++++++++ .../devlaunch/SpongeDevClasspathFixer.java | 186 ++++++++++++++++++ ...e.bootstrap.api.BootstrapClasspathModifier | 1 + 10 files changed, 340 insertions(+), 64 deletions(-) create mode 100644 modlauncher-transformers/src/main/resources/META-INF/MANIFEST.MF create mode 100644 vanilla/src/applaunch/resources/META-INF/MANIFEST.MF create mode 100644 vanilla/src/devlaunch/java/module-info.java create mode 100644 vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java create mode 100644 vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java create mode 100644 vanilla/src/devlaunch/resources/META-INF/services/net.minecraftforge.bootstrap.api.BootstrapClasspathModifier diff --git a/.gitignore b/.gitignore index 7d364aaea03..3a3482d3059 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ # Build # ######### -MANIFEST.MF dependency-reduced-pom.xml # Compiled # diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 37be89a71b0..867ada7f2fe 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -31,6 +31,7 @@ log4j-api = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4 log4j-core = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j" } log4j-jpl = { module = "org.apache.logging.log4j:log4j-jpl", version.ref = "log4j" } log4j-slf4j2 = { module = "org.apache.logging.log4j:log4j-slf4j2-impl", version.ref = "log4j" } +bootstrap-api = { module = "net.minecraftforge:bootstrap-api", version.ref = "bootstrap" } bootstrap = { module = "net.minecraftforge:bootstrap", version.ref = "bootstrap" } modlauncher = { module = "net.minecraftforge:modlauncher", version.ref = "modlauncher" } neo-modlauncher = { module = "cpw.mods:modlauncher", version.ref = "neo-modlauncher" } diff --git a/modlauncher-transformers/build.gradle.kts b/modlauncher-transformers/build.gradle.kts index 02437728dcb..1398d3d3d44 100644 --- a/modlauncher-transformers/build.gradle.kts +++ b/modlauncher-transformers/build.gradle.kts @@ -18,7 +18,6 @@ indraSpotlessLicenser { property("url", projectUrl) } - dependencies { // AccessWidener transformer implementation(libs.accessWidener) { @@ -48,3 +47,11 @@ dependencies { // And finally, compile only annotations compileOnly(apiLibs.checkerQual) } + +tasks { + jar { + manifest { + attributes("Automatic-Module-Name" to "sponge.modlauncher.transformers") + } + } +} diff --git a/modlauncher-transformers/src/main/resources/META-INF/MANIFEST.MF b/modlauncher-transformers/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..0a1e1f7343d --- /dev/null +++ b/modlauncher-transformers/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1 @@ +Automatic-Module-Name: sponge.modlauncher.transformers diff --git a/vanilla/build.gradle.kts b/vanilla/build.gradle.kts index 13c93224650..3674eb350af 100644 --- a/vanilla/build.gradle.kts +++ b/vanilla/build.gradle.kts @@ -24,6 +24,7 @@ description = "The SpongeAPI implementation for Vanilla Minecraft" version = spongeImpl.generatePlatformBuildVersionString(apiVersion, minecraftVersion, recommendedVersion) // SpongeVanilla libraries +val devlaunchLibrariesConfig: NamedDomainObjectProvider = configurations.register("devlaunchLibraries") val installerLibrariesConfig: NamedDomainObjectProvider = configurations.register("installerLibraries") val initLibrariesConfig: NamedDomainObjectProvider = configurations.register("initLibraries") // JVM initial classpath val bootLibrariesConfig: NamedDomainObjectProvider = configurations.register("bootLibraries") @@ -54,37 +55,44 @@ val mixins: NamedDomainObjectProvider = commonProject.sourceSets.name val main: NamedDomainObjectProvider = commonProject.sourceSets.named("main") // SpongeVanilla source sets +// Dev launch +val vanillaDevLaunch by sourceSets.register("devlaunch") { + configurations.named(implementationConfigurationName) { + extendsFrom(devlaunchLibrariesConfig.get()) + } +} + +// Prod launch val vanillaInstaller by sourceSets.register("installer") { configurations.named(implementationConfigurationName) { extendsFrom(installerLibrariesConfig.get()) } } -val vanillaMain by sourceSets.named("main") { +// Boot layer +val vanillaAppLaunch by sourceSets.register("applaunch") { // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) configurations.named(implementationConfigurationName) { - extendsFrom(gameLayerConfig.get()) + extendsFrom(bootLayerConfig.get()) } } + +// Game layer val vanillaLaunch by sourceSets.register("launch") { // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, this, vanillaMain, project, vanillaMain.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, vanillaAppLaunch, this, project, this.implementationConfigurationName) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) } } val vanillaAccessors by sourceSets.register("accessors") { - spongeImpl.applyNamedDependencyOnOutput(commonProject, mixins.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, this, vanillaLaunch, project, vanillaLaunch.implementationConfigurationName) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) @@ -92,31 +100,42 @@ val vanillaAccessors by sourceSets.register("accessors") { } val vanillaMixins by sourceSets.register("mixins") { // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, mixins.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, mixins.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, vanillaMain, this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, vanillaAccessors, this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, vanillaAppLaunch, this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(project, vanillaLaunch, this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, vanillaAccessors, this, project, this.implementationConfigurationName) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) } } -val vanillaLang by sourceSets.register("lang") { - configurations.named(implementationConfigurationName) { - extendsFrom(bootLayerConfig.get()) - } -} -val vanillaAppLaunch by sourceSets.register("applaunch") { +val vanillaMain by sourceSets.named("main") { // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, this, vanillaLaunch, project, vanillaLaunch.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, vanillaLaunch, this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, vanillaAccessors, this, project, this.implementationConfigurationName) + + spongeImpl.applyNamedDependencyOnOutput(project, this, vanillaMixins, project, vanillaMixins.implementationConfigurationName) configurations.named(implementationConfigurationName) { - extendsFrom(bootLayerConfig.get()) + extendsFrom(gameLayerConfig.get()) + } + + // runtime dependencies - the rest of the project because we want everything in the initial classpath + spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.runtimeOnlyConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, mixins.get(), this, project, this.runtimeOnlyConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, vanillaDevLaunch, this, project, this.runtimeOnlyConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, vanillaAppLaunch, this, project, this.runtimeOnlyConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, vanillaMixins, this, project, this.runtimeOnlyConfigurationName) + + configurations.named(runtimeOnlyConfigurationName) { + extendsFrom(devlaunchLibrariesConfig.get()) } } @@ -143,11 +162,8 @@ configurations.configureEach { } dependencies { - api(project(":", configuration = "launch")) - implementation(project(":", configuration = "accessors")) - implementation(project(commonProject.path)) - - vanillaMixins.implementationConfigurationName(project(commonProject.path)) + val devlaunch = devlaunchLibrariesConfig.name + devlaunch(libs.bootstrap.api) val installer = installerLibrariesConfig.name installer(apiLibs.gson) @@ -260,8 +276,10 @@ dependencies { spongeImpl.copyModulesExcludingProvided(gameLibrariesConfig.get(), bootLayerConfig.get(), gameManagedLibrariesConfig.get()) - // Allow boot layer manipulation such as merging applaunch sourcesets - vanillaAppLaunch.runtimeOnlyConfigurationName("net.minecraftforge:bootstrap-dev:2.1.1") + val runOnly = vanillaMain.runtimeOnlyConfigurationName + testPluginsProject?.also { + runOnly(project(it.path)) + } } minecraft { @@ -315,40 +333,9 @@ minecraft { // jvmArgs("-Dbsl.debug=true") // Uncomment to debug bootstrap classpath mainClass("net.minecraftforge.bootstrap.ForgeBootstrap") - // Put modules in boot layer - sourceSet = vanillaAppLaunch - - // Merge applaunch sourcesets in a single module - val applaunchOutputs = files(applaunch.get().output, vanillaAppLaunch.output) - environment("MOD_CLASSES", applaunchOutputs.joinToString(";") { "applaunch%%$it" }) - // Configure resources - val gameResources = mutableListOf() - gameResources.addAll(gameManagedLibrariesConfig.get().files.map { files(it) }) - - 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() - )) - - jvmArgs("-Dsponge.gameResources=" + gameResources.joinToString(";") { it.joinToString("&") }) - - val runTask = tasks.named(this.name) { - dependsOn(applaunchOutputs) - dependsOn(gameResources) - } - - testPluginsProject?.also { - val plugins: FileCollection = it.sourceSets.getByName("main").output - environment("SPONGE_PLUGINS", plugins.joinToString("&")) - - runTask.configure { - dependsOn(plugins) - } - } + jvmArgs("-Dsponge.dev.gameManaged=" + gameManagedLibrariesConfig.get().resolvedConfiguration.resolvedArtifacts.joinToString(";") { it.file.name }) + jvmArgs("-Dsponge.dev.gameShaded=" + gameShadedLibrariesConfig.get().resolvedConfiguration.resolvedArtifacts.joinToString(";") { it.file.name }) } } } diff --git a/vanilla/src/applaunch/resources/META-INF/MANIFEST.MF b/vanilla/src/applaunch/resources/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..c6c2338865d --- /dev/null +++ b/vanilla/src/applaunch/resources/META-INF/MANIFEST.MF @@ -0,0 +1 @@ +Automatic-Module-Name: spongevanilla.boot diff --git a/vanilla/src/devlaunch/java/module-info.java b/vanilla/src/devlaunch/java/module-info.java new file mode 100644 index 00000000000..3328ffb314e --- /dev/null +++ b/vanilla/src/devlaunch/java/module-info.java @@ -0,0 +1,6 @@ +module org.spongepowered.vanilla.devlaunch { + requires net.minecraftforge.bootstrap.api; + exports org.spongepowered.vanilla.devlaunch; + + provides net.minecraftforge.bootstrap.api.BootstrapClasspathModifier with org.spongepowered.vanilla.devlaunch.SpongeDevClasspathFixer; +} diff --git a/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java b/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java new file mode 100644 index 00000000000..d58fd9a1387 --- /dev/null +++ b/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java @@ -0,0 +1,87 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.vanilla.devlaunch; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +public record SourceSet(String project, String name, String format) { + + @Override + public String toString() { + return this.project + ":" + this.name + ":" + this.format; + } + + /** + * Identify source sets from output dirs in the following formats: + * + *

Gradle: + *

{@code {project}/build/classes/java/{name}/} + *

{@code {project}/build/resources/{name}/} + * + *

IntelliJ: + *

{@code {project}/out/{name}/classes/} + *

{@code {project}/out/{name}/resources/} + * + *

Eclipse: + *

{@code {project}/bin/{name}/} + */ + public static SourceSet identify(Path path) { + if (!Files.isDirectory(path)) { + return null; + } + + // from right to left + final List parts = new ArrayList<>(); + while (path != null) { + parts.add(path.getFileName().toString()); + if (parts.size() >= 5) { + break; + } + path = path.getParent(); + } + + if (parts.size() >= 4 && (parts.get(0).equals("classes") || parts.get(0).equals("resources"))) { + final String name = parts.get(1); + return new SourceSet(parts.get(3), name.equals("production") ? "main" : name, "IntelliJ"); + } + + if (parts.size() >= 4 && parts.get(1).equals("resources")) { + return new SourceSet(parts.get(3), parts.get(0), "Gradle"); + } + + if (parts.size() >= 5 && parts.get(2).equals("classes")) { + return new SourceSet(parts.get(4), parts.get(0), "Gradle"); + } + + if (parts.size() >= 3 && parts.get(1).equals("bin")) { + return new SourceSet(parts.get(2), parts.get(0), "Eclipse"); + } + + return new SourceSet("", parts.get(0), "Unknown"); + } +} diff --git a/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java b/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java new file mode 100644 index 00000000000..ad78a97836b --- /dev/null +++ b/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java @@ -0,0 +1,186 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.vanilla.devlaunch; + +import net.minecraftforge.bootstrap.api.BootstrapClasspathModifier; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; + +public class SpongeDevClasspathFixer implements BootstrapClasspathModifier { + private static final boolean DEBUG = Boolean.getBoolean("bsl.debug"); + + @Override + public String name() { + return "sponge-dev"; + } + + /** + * IntelliJ only builds source sets that are explicitly on the classpath. + * So we declare everything into the initial classpath then we sort things and put them back in the right classloaders. + * Since different IDEs might want to put things in different locations, we sadly have to identify the resources by their filenames. + */ + @Override + public boolean process(final List classpath) { + final Set gameManagedNames = Set.of(System.getProperty("sponge.dev.gameManaged").split(";")); + final Set gameShadedNames = Set.of(System.getProperty("sponge.dev.gameShaded").split(";")); + + final List transformersSourceSets = new ArrayList<>(); + final List appLaunchSourceSets = new ArrayList<>(); + final List gameSourceSets = new ArrayList<>(); + + final List gameManagedResources = new ArrayList<>(); + final List gameShadedResources = new ArrayList<>(); + final List testResources = new ArrayList<>(); + + final AtomicBoolean hasAPISourceSet = new AtomicBoolean(false); + + final boolean modified = classpath.removeIf((paths) -> { + if (paths.length != 1) { // empty or already merged by another service + return false; + } + + final Path path = paths[0]; + final SourceSet sourceSet = SourceSet.identify(path); + if (sourceSet != null) { + if (DEBUG) { + System.out.println("SourceSet (" + sourceSet + "): " + path); + } + + switch (sourceSet.project()) { + case "testplugins": + testResources.add(path); + break; + case "modlauncher-transformers": + transformersSourceSets.add(path); + break; + default: + switch (sourceSet.name()) { + case "devlaunch", "ap": + // ignore + break; + case "applaunch": + appLaunchSourceSets.add(path); + break; + case "main": + if (sourceSet.project().equals("SpongeAPI")) { + hasAPISourceSet.set(true); + } + // no break, on purpose + default: + gameSourceSets.add(path); + break; + } + break; + } + return true; + } + + final String fileName = path.getFileName().toString(); + + if (gameManagedNames.contains(fileName)) { + if (DEBUG) { + System.out.println("Game (managed): " + path); + } + gameManagedResources.add(path); + return true; + } + + if (gameShadedNames.contains(fileName)) { + if (DEBUG) { + System.out.println("Game (shaded): " + path); + } + gameShadedResources.add(path); + return true; + } + + if (fileName.equals("testplugins.jar")) { + if (DEBUG) { + System.out.println("TestPlugins jar: " + path); + } + testResources.add(path); + return true; + } + + if (DEBUG) { + System.out.println("Bootstrap: " + path); + } + return false; + }); + + if (!modified) { + return false; + } + + if (!transformersSourceSets.isEmpty()) { + classpath.add(transformersSourceSets.toArray(Path[]::new)); + } + + classpath.add(appLaunchSourceSets.toArray(Path[]::new)); + + gameShadedResources.addAll(gameSourceSets); + + if (hasAPISourceSet.get()) { + gameShadedResources.removeIf((path) -> { + if (Files.isRegularFile(path)) { + final String fileName = path.getFileName().toString(); + if (fileName.startsWith("spongeapi") && fileName.endsWith(".jar")) { + if (DEBUG) { + System.out.println("Removing spongeapi jar in favor of sourceset: " + path); + } + return true; + } + } + return false; + }); + } + + final StringBuilder gameResourcesEnvBuilder = new StringBuilder(); + for (final Path resource : gameManagedResources) { + gameResourcesEnvBuilder.append(resource).append(';'); + } + for (final Path resource : gameShadedResources) { + gameResourcesEnvBuilder.append(resource).append('&'); + } + gameResourcesEnvBuilder.setCharAt(gameResourcesEnvBuilder.length() - 1, ';'); + for (final Path resource : testResources) { + gameResourcesEnvBuilder.append(resource).append('&'); + } + gameResourcesEnvBuilder.setLength(gameResourcesEnvBuilder.length() - 1); + final String gameResourcesEnv = gameResourcesEnvBuilder.toString(); + + if (DEBUG) { + System.out.println("Game resources env: " + gameResourcesEnv); + } + System.setProperty("sponge.gameResources", gameResourcesEnv); + return true; + } + + +} diff --git a/vanilla/src/devlaunch/resources/META-INF/services/net.minecraftforge.bootstrap.api.BootstrapClasspathModifier b/vanilla/src/devlaunch/resources/META-INF/services/net.minecraftforge.bootstrap.api.BootstrapClasspathModifier new file mode 100644 index 00000000000..8351cd09f4e --- /dev/null +++ b/vanilla/src/devlaunch/resources/META-INF/services/net.minecraftforge.bootstrap.api.BootstrapClasspathModifier @@ -0,0 +1 @@ +org.spongepowered.vanilla.devlaunch.SpongeDevClasspathFixer From 6aa1e148ef56db79d9b413039011336603bf429c Mon Sep 17 00:00:00 2001 From: Yeregorix Date: Tue, 10 Dec 2024 21:28:53 +0100 Subject: [PATCH 2/9] Load plugins from classpath in dev environment --- vanilla/build.gradle.kts | 2 +- .../vanilla/devlaunch/SourceSet.java | 3 +- .../devlaunch/SpongeDevClasspathFixer.java | 101 +++++++++--------- 3 files changed, 52 insertions(+), 54 deletions(-) diff --git a/vanilla/build.gradle.kts b/vanilla/build.gradle.kts index 3674eb350af..d7606ecb18e 100644 --- a/vanilla/build.gradle.kts +++ b/vanilla/build.gradle.kts @@ -334,7 +334,7 @@ minecraft { mainClass("net.minecraftforge.bootstrap.ForgeBootstrap") // Configure resources - jvmArgs("-Dsponge.dev.gameManaged=" + gameManagedLibrariesConfig.get().resolvedConfiguration.resolvedArtifacts.joinToString(";") { it.file.name }) + jvmArgs("-Dsponge.dev.boot=" + bootLayerConfig.get().resolvedConfiguration.resolvedArtifacts.joinToString(";") { it.file.name }) jvmArgs("-Dsponge.dev.gameShaded=" + gameShadedLibrariesConfig.get().resolvedConfiguration.resolvedArtifacts.joinToString(";") { it.file.name }) } } diff --git a/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java b/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java index d58fd9a1387..a4fa3b1b537 100644 --- a/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java +++ b/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java @@ -42,6 +42,7 @@ public String toString() { *

Gradle: *

{@code {project}/build/classes/java/{name}/} *

{@code {project}/build/resources/{name}/} + *

{@code {project}/build/generated/{name}/} * *

IntelliJ: *

{@code {project}/out/{name}/classes/} @@ -70,7 +71,7 @@ public static SourceSet identify(Path path) { return new SourceSet(parts.get(3), name.equals("production") ? "main" : name, "IntelliJ"); } - if (parts.size() >= 4 && parts.get(1).equals("resources")) { + if (parts.size() >= 4 && (parts.get(1).equals("resources") || parts.get(1).equals("generated"))) { return new SourceSet(parts.get(3), parts.get(0), "Gradle"); } diff --git a/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java b/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java index ad78a97836b..47c8f979594 100644 --- a/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java +++ b/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java @@ -29,7 +29,10 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; @@ -48,16 +51,14 @@ public String name() { */ @Override public boolean process(final List classpath) { - final Set gameManagedNames = Set.of(System.getProperty("sponge.dev.gameManaged").split(";")); - final Set gameShadedNames = Set.of(System.getProperty("sponge.dev.gameShaded").split(";")); + final Set bootLibs = Set.of(System.getProperty("sponge.dev.boot").split(";")); + final Set gameShadedLibs = Set.of(System.getProperty("sponge.dev.gameShaded").split(";")); - final List transformersSourceSets = new ArrayList<>(); - final List appLaunchSourceSets = new ArrayList<>(); - final List gameSourceSets = new ArrayList<>(); + final Map> bootSourceSets = new HashMap<>(); + final Map> unknownProjects = new HashMap<>(); - final List gameManagedResources = new ArrayList<>(); - final List gameShadedResources = new ArrayList<>(); - final List testResources = new ArrayList<>(); + final List spongeImplUnion = new ArrayList<>(); + final List gameLibs = new ArrayList<>(); final AtomicBoolean hasAPISourceSet = new AtomicBoolean(false); @@ -74,80 +75,76 @@ public boolean process(final List classpath) { } switch (sourceSet.project()) { - case "testplugins": - testResources.add(path); - break; case "modlauncher-transformers": - transformersSourceSets.add(path); + bootSourceSets.computeIfAbsent("transformers", k -> new LinkedList<>()).add(path); break; - default: + case "SpongeAPI": + switch (sourceSet.name()) { + case "ap": + // ignore + break; + case "main": + hasAPISourceSet.set(true); + // no break + default: + spongeImplUnion.add(path); + break; + } + break; + case "Sponge", "vanilla": switch (sourceSet.name()) { - case "devlaunch", "ap": + case "devlaunch": // ignore break; case "applaunch": - appLaunchSourceSets.add(path); + bootSourceSets.computeIfAbsent("applaunch", k -> new LinkedList<>()).add(path); break; - case "main": - if (sourceSet.project().equals("SpongeAPI")) { - hasAPISourceSet.set(true); - } - // no break, on purpose default: - gameSourceSets.add(path); + spongeImplUnion.add(path); break; } break; + default: + unknownProjects.computeIfAbsent(sourceSet.project(), k -> new LinkedList<>()).add(path); + break; } return true; } final String fileName = path.getFileName().toString(); - if (gameManagedNames.contains(fileName)) { + if (bootLibs.contains(fileName)) { if (DEBUG) { - System.out.println("Game (managed): " + path); + System.out.println("Boot: " + path); } - gameManagedResources.add(path); - return true; - } - - if (gameShadedNames.contains(fileName)) { - if (DEBUG) { - System.out.println("Game (shaded): " + path); - } - gameShadedResources.add(path); - return true; + return false; } - if (fileName.equals("testplugins.jar")) { + if (gameShadedLibs.contains(fileName)) { if (DEBUG) { - System.out.println("TestPlugins jar: " + path); + System.out.println("Sponge: " + path); } - testResources.add(path); + spongeImplUnion.add(path); return true; } if (DEBUG) { - System.out.println("Bootstrap: " + path); + System.out.println("Game: " + path); } - return false; + gameLibs.add(path); + return true; }); if (!modified) { return false; } - if (!transformersSourceSets.isEmpty()) { - classpath.add(transformersSourceSets.toArray(Path[]::new)); + for (final List sourceSets : bootSourceSets.values()) { + classpath.add(sourceSets.toArray(Path[]::new)); } - classpath.add(appLaunchSourceSets.toArray(Path[]::new)); - - gameShadedResources.addAll(gameSourceSets); - if (hasAPISourceSet.get()) { - gameShadedResources.removeIf((path) -> { + spongeImplUnion.removeIf((path) -> { if (Files.isRegularFile(path)) { final String fileName = path.getFileName().toString(); if (fileName.startsWith("spongeapi") && fileName.endsWith(".jar")) { @@ -162,14 +159,16 @@ public boolean process(final List classpath) { } final StringBuilder gameResourcesEnvBuilder = new StringBuilder(); - for (final Path resource : gameManagedResources) { + for (final Path resource : gameLibs) { gameResourcesEnvBuilder.append(resource).append(';'); } - for (final Path resource : gameShadedResources) { - gameResourcesEnvBuilder.append(resource).append('&'); + for (final List project : unknownProjects.values()) { + for (final Path resource : project) { + gameResourcesEnvBuilder.append(resource).append('&'); + } + gameResourcesEnvBuilder.setCharAt(gameResourcesEnvBuilder.length() - 1, ';'); } - gameResourcesEnvBuilder.setCharAt(gameResourcesEnvBuilder.length() - 1, ';'); - for (final Path resource : testResources) { + for (final Path resource : spongeImplUnion) { gameResourcesEnvBuilder.append(resource).append('&'); } gameResourcesEnvBuilder.setLength(gameResourcesEnvBuilder.length() - 1); @@ -181,6 +180,4 @@ public boolean process(final List classpath) { System.setProperty("sponge.gameResources", gameResourcesEnv); return true; } - - } From 603a27ee773b3cdcec3d8cfe83f133e84e5c6d22 Mon Sep 17 00:00:00 2001 From: Yeregorix Date: Wed, 18 Dec 2024 21:17:55 +0100 Subject: [PATCH 3/9] Properly order sourcesets dependencies declaration --- forge/build.gradle.kts | 62 ++++++++++++++++++--------------------- neoforge/build.gradle.kts | 62 ++++++++++++++++++--------------------- vanilla/build.gradle.kts | 4 +-- 3 files changed, 60 insertions(+), 68 deletions(-) diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index ead70d976fa..8a42e413002 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -80,31 +80,37 @@ val mixins: NamedDomainObjectProvider = commonProject.sourceSets.name val main: NamedDomainObjectProvider = commonProject.sourceSets.named("main") // SpongeForge source sets -val forgeMain by sourceSets.named("main") { +// Service layer +val forgeAppLaunch by sourceSets.register("applaunch") { // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) configurations.named(implementationConfigurationName) { - extendsFrom(gameLayerConfig.get()) + extendsFrom(serviceLayerConfig.get()) + } +} + +// Lang layer +val forgeLang by sourceSets.register("lang") { + configurations.named(implementationConfigurationName) { + extendsFrom(langLayerConfig.get()) } } + +// Game layer val forgeLaunch by sourceSets.register("launch") { // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, this, forgeMain, project, forgeMain.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, forgeAppLaunch, this, project, this.implementationConfigurationName) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) } } val forgeAccessors by sourceSets.register("accessors") { - spongeImpl.applyNamedDependencyOnOutput(commonProject, mixins.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, this, forgeLaunch, project, forgeLaunch.implementationConfigurationName) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) @@ -112,31 +118,33 @@ val forgeAccessors by sourceSets.register("accessors") { } val forgeMixins by sourceSets.register("mixins") { // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, mixins.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, mixins.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeMain, this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeAccessors, this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, forgeAppLaunch, this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(project, forgeLaunch, this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, forgeAccessors, this, project, this.implementationConfigurationName) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) } } -val forgeLang by sourceSets.register("lang") { - configurations.named(implementationConfigurationName) { - extendsFrom(langLayerConfig.get()) - } -} -val forgeAppLaunch by sourceSets.register("applaunch") { +val forgeMain by sourceSets.named("main") { // implementation (compile) dependencies spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, this, forgeLaunch, project, forgeLaunch.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, forgeAppLaunch, this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, forgeLaunch, this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, forgeAccessors, this, project, this.implementationConfigurationName) + + spongeImpl.applyNamedDependencyOnOutput(project, this, forgeMixins, project, forgeMixins.implementationConfigurationName) configurations.named(implementationConfigurationName) { - extendsFrom(serviceLayerConfig.get()) + extendsFrom(gameLayerConfig.get()) } } @@ -195,18 +203,6 @@ dependencies { } }) - api(project(":", configuration = "launch")) { - exclude(group = "org.spongepowered", module = "mixin") - } - implementation(project(":", configuration = "accessors")) { - exclude(group = "org.spongepowered", module = "mixin") - } - implementation(project(commonProject.path)) { - exclude(group = "org.spongepowered", module = "mixin") - } - - forgeMixins.implementationConfigurationName(project(commonProject.path)) - val service = serviceLibrariesConfig.name service(apiLibs.pluginSpi) service(project(transformersProject.path)) { diff --git a/neoforge/build.gradle.kts b/neoforge/build.gradle.kts index f0cbddbc02c..70e310cfd75 100644 --- a/neoforge/build.gradle.kts +++ b/neoforge/build.gradle.kts @@ -81,31 +81,37 @@ val mixins: NamedDomainObjectProvider = commonProject.sourceSets.name val main: NamedDomainObjectProvider = commonProject.sourceSets.named("main") // SpongeNeo source sets -val forgeMain by sourceSets.named("main") { +// Service layer +val forgeAppLaunch by sourceSets.register("applaunch") { // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) configurations.named(implementationConfigurationName) { - extendsFrom(gameLayerConfig.get()) + extendsFrom(serviceLayerConfig.get()) + } +} + +// Lang layer +val forgeLang by sourceSets.register("lang") { + configurations.named(implementationConfigurationName) { + extendsFrom(langLayerConfig.get()) } } + +// Game layer val forgeLaunch by sourceSets.register("launch") { // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, this, forgeMain, project, forgeMain.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, forgeAppLaunch, this, project, this.implementationConfigurationName) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) } } val forgeAccessors by sourceSets.register("accessors") { - spongeImpl.applyNamedDependencyOnOutput(commonProject, mixins.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, this, forgeLaunch, project, forgeLaunch.implementationConfigurationName) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) @@ -113,31 +119,33 @@ val forgeAccessors by sourceSets.register("accessors") { } val forgeMixins by sourceSets.register("mixins") { // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, mixins.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, mixins.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeMain, this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeAccessors, this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, forgeAppLaunch, this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(project, forgeLaunch, this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, forgeAccessors, this, project, this.implementationConfigurationName) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) } } -val forgeLang by sourceSets.register("lang") { - configurations.named(implementationConfigurationName) { - extendsFrom(langLayerConfig.get()) - } -} -val forgeAppLaunch by sourceSets.register("applaunch") { +val forgeMain by sourceSets.named("main") { // implementation (compile) dependencies spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, this, forgeLaunch, project, forgeLaunch.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, forgeAppLaunch, this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, forgeLaunch, this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, forgeAccessors, this, project, this.implementationConfigurationName) + + spongeImpl.applyNamedDependencyOnOutput(project, this, forgeMixins, project, forgeMixins.implementationConfigurationName) configurations.named(implementationConfigurationName) { - extendsFrom(serviceLayerConfig.get()) + extendsFrom(gameLayerConfig.get()) } } @@ -182,18 +190,6 @@ dependencies { } }) - api(project(":", configuration = "launch")) { - exclude(group = "org.spongepowered", module = "mixin") - } - implementation(project(":", configuration = "accessors")) { - exclude(group = "org.spongepowered", module = "mixin") - } - implementation(project(commonProject.path)) { - exclude(group = "org.spongepowered", module = "mixin") - } - - forgeMixins.implementationConfigurationName(project(commonProject.path)) - val service = serviceLibrariesConfig.name service(apiLibs.pluginSpi) service(project(transformersProject.path)) { diff --git a/vanilla/build.gradle.kts b/vanilla/build.gradle.kts index d7606ecb18e..7203bca6935 100644 --- a/vanilla/build.gradle.kts +++ b/vanilla/build.gradle.kts @@ -115,9 +115,11 @@ val vanillaMixins by sourceSets.register("mixins") { } val vanillaMain by sourceSets.named("main") { // implementation (compile) dependencies + spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) + spongeImpl.applyNamedDependencyOnOutput(project, vanillaAppLaunch, this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(project, vanillaLaunch, this, project, this.implementationConfigurationName) spongeImpl.applyNamedDependencyOnOutput(project, vanillaAccessors, this, project, this.implementationConfigurationName) @@ -128,10 +130,8 @@ val vanillaMain by sourceSets.named("main") { } // runtime dependencies - the rest of the project because we want everything in the initial classpath - spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.runtimeOnlyConfigurationName) spongeImpl.applyNamedDependencyOnOutput(commonProject, mixins.get(), this, project, this.runtimeOnlyConfigurationName) spongeImpl.applyNamedDependencyOnOutput(project, vanillaDevLaunch, this, project, this.runtimeOnlyConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, vanillaAppLaunch, this, project, this.runtimeOnlyConfigurationName) spongeImpl.applyNamedDependencyOnOutput(project, vanillaMixins, this, project, this.runtimeOnlyConfigurationName) configurations.named(runtimeOnlyConfigurationName) { From 677e57f52de2ad631346afbdb8993943e960be26 Mon Sep 17 00:00:00 2001 From: Yeregorix Date: Wed, 18 Dec 2024 21:40:27 +0100 Subject: [PATCH 4/9] Simplify sourcesets dependencies declaration --- .../impl/SpongeImplementationExtension.java | 22 ++++---- build.gradle.kts | 18 +++--- forge/build.gradle.kts | 50 ++++++++--------- neoforge/build.gradle.kts | 50 ++++++++--------- vanilla/build.gradle.kts | 56 +++++++++---------- 5 files changed, 91 insertions(+), 105 deletions(-) diff --git a/build-logic/src/main/java/org/spongepowered/gradle/impl/SpongeImplementationExtension.java b/build-logic/src/main/java/org/spongepowered/gradle/impl/SpongeImplementationExtension.java index ca43cbd7d60..09dc131237a 100644 --- a/build-logic/src/main/java/org/spongepowered/gradle/impl/SpongeImplementationExtension.java +++ b/build-logic/src/main/java/org/spongepowered/gradle/impl/SpongeImplementationExtension.java @@ -93,18 +93,16 @@ public void copyModulesExcludingProvided(final Configuration source, final Confi } } - public void applyNamedDependencyOnOutput(final Project originProject, final SourceSet sourceAdding, final SourceSet targetSource, final Project implProject, final String dependencyConfigName) { - implProject.getLogger().lifecycle( - "[{}] Adding {}({}) to {}({}).{}", - implProject.getName(), - originProject.getPath(), - sourceAdding.getName(), - implProject.getPath(), - targetSource.getName(), - dependencyConfigName - ); - - implProject.getDependencies().add(dependencyConfigName, sourceAdding.getOutput()); + public void addDependencyToRuntimeOnly(final SourceSet source, final SourceSet target) { + this.addDependencyTo(source, target.getRuntimeOnlyConfigurationName()); + } + + public void addDependencyToImplementation(final SourceSet source, final SourceSet target) { + this.addDependencyTo(source, target.getImplementationConfigurationName()); + } + + public void addDependencyTo(final SourceSet source, final String targetConfig) { + this.project.getDependencies().add(targetConfig, source.getOutput()); } public String generateImplementationVersionString(final String apiVersion, final String minecraftVersion, final String implRecommendedVersion) { diff --git a/build.gradle.kts b/build.gradle.kts index 1b8dae2ce14..7db73e468ba 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -57,33 +57,33 @@ val mixinsConfig by configurations.register("mixins") { val main by sourceSets val applaunch by sourceSets.registering { - spongeImpl.applyNamedDependencyOnOutput(project, this, main, project, main.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(this, main) configurations.named(implementationConfigurationName) { extendsFrom(applaunchConfig) } } val launch by sourceSets.registering { - spongeImpl.applyNamedDependencyOnOutput(project, applaunch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, this, main, project, main.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(applaunch.get(), this) + spongeImpl.addDependencyToImplementation(this, main) configurations.named(implementationConfigurationName) { extendsFrom(launchConfig) } } val accessors by sourceSets.registering { - spongeImpl.applyNamedDependencyOnOutput(project, launch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, this, main, project, main.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(launch.get(), this) + spongeImpl.addDependencyToImplementation(this, main) configurations.named(implementationConfigurationName) { extendsFrom(accessorsConfig) } } val mixins by sourceSets.registering { - spongeImpl.applyNamedDependencyOnOutput(project, launch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, applaunch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, accessors.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, main, this, project, this.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(launch.get(), this) + spongeImpl.addDependencyToImplementation(applaunch.get(), this) + spongeImpl.addDependencyToImplementation(accessors.get(), this) + spongeImpl.addDependencyToImplementation(main, this) configurations.named(implementationConfigurationName) { extendsFrom(mixinsConfig) diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index 8a42e413002..f25aea2f1aa 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -82,8 +82,7 @@ val main: NamedDomainObjectProvider = commonProject.sourceSets.named( // SpongeForge source sets // Service layer val forgeAppLaunch by sourceSets.register("applaunch") { - // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(applaunch.get(), this) configurations.named(implementationConfigurationName) { extendsFrom(serviceLayerConfig.get()) @@ -99,49 +98,46 @@ val forgeLang by sourceSets.register("lang") { // Game layer val forgeLaunch by sourceSets.register("launch") { - // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeAppLaunch, this, project, this.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(applaunch.get(), this) + spongeImpl.addDependencyToImplementation(launch.get(), this) + spongeImpl.addDependencyToImplementation(main.get(), this) + spongeImpl.addDependencyToImplementation(forgeAppLaunch, this) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) } } val forgeAccessors by sourceSets.register("accessors") { - spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(accessors.get(), this) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) } } val forgeMixins by sourceSets.register("mixins") { - // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, mixins.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeAppLaunch, this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeLaunch, this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeAccessors, this, project, this.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(applaunch.get(), this) + spongeImpl.addDependencyToImplementation(launch.get(), this) + spongeImpl.addDependencyToImplementation(accessors.get(), this) + spongeImpl.addDependencyToImplementation(mixins.get(), this) + spongeImpl.addDependencyToImplementation(main.get(), this) + spongeImpl.addDependencyToImplementation(forgeAppLaunch, this) + spongeImpl.addDependencyToImplementation(forgeLaunch, this) + spongeImpl.addDependencyToImplementation(forgeAccessors, this) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) } } val forgeMain by sourceSets.named("main") { - // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeAppLaunch, this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeLaunch, this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeAccessors, this, project, this.implementationConfigurationName) - - spongeImpl.applyNamedDependencyOnOutput(project, this, forgeMixins, project, forgeMixins.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(applaunch.get(), this) + spongeImpl.addDependencyToImplementation(launch.get(), this) + spongeImpl.addDependencyToImplementation(accessors.get(), this) + spongeImpl.addDependencyToImplementation(main.get(), this) + spongeImpl.addDependencyToImplementation(forgeAppLaunch, this) + spongeImpl.addDependencyToImplementation(forgeLaunch, this) + spongeImpl.addDependencyToImplementation(forgeAccessors, this) + + spongeImpl.addDependencyToImplementation(this, forgeMixins) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) diff --git a/neoforge/build.gradle.kts b/neoforge/build.gradle.kts index 70e310cfd75..1cb8d3937c3 100644 --- a/neoforge/build.gradle.kts +++ b/neoforge/build.gradle.kts @@ -83,8 +83,7 @@ val main: NamedDomainObjectProvider = commonProject.sourceSets.named( // SpongeNeo source sets // Service layer val forgeAppLaunch by sourceSets.register("applaunch") { - // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(applaunch.get(), this) configurations.named(implementationConfigurationName) { extendsFrom(serviceLayerConfig.get()) @@ -100,49 +99,46 @@ val forgeLang by sourceSets.register("lang") { // Game layer val forgeLaunch by sourceSets.register("launch") { - // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeAppLaunch, this, project, this.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(applaunch.get(), this) + spongeImpl.addDependencyToImplementation(launch.get(), this) + spongeImpl.addDependencyToImplementation(main.get(), this) + spongeImpl.addDependencyToImplementation(forgeAppLaunch, this) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) } } val forgeAccessors by sourceSets.register("accessors") { - spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(accessors.get(), this) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) } } val forgeMixins by sourceSets.register("mixins") { - // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, mixins.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeAppLaunch, this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeLaunch, this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeAccessors, this, project, this.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(applaunch.get(), this) + spongeImpl.addDependencyToImplementation(launch.get(), this) + spongeImpl.addDependencyToImplementation(accessors.get(), this) + spongeImpl.addDependencyToImplementation(mixins.get(), this) + spongeImpl.addDependencyToImplementation(main.get(), this) + spongeImpl.addDependencyToImplementation(forgeAppLaunch, this) + spongeImpl.addDependencyToImplementation(forgeLaunch, this) + spongeImpl.addDependencyToImplementation(forgeAccessors, this) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) } } val forgeMain by sourceSets.named("main") { - // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeAppLaunch, this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeLaunch, this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, forgeAccessors, this, project, this.implementationConfigurationName) - - spongeImpl.applyNamedDependencyOnOutput(project, this, forgeMixins, project, forgeMixins.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(applaunch.get(), this) + spongeImpl.addDependencyToImplementation(launch.get(), this) + spongeImpl.addDependencyToImplementation(accessors.get(), this) + spongeImpl.addDependencyToImplementation(main.get(), this) + spongeImpl.addDependencyToImplementation(forgeAppLaunch, this) + spongeImpl.addDependencyToImplementation(forgeLaunch, this) + spongeImpl.addDependencyToImplementation(forgeAccessors, this) + + spongeImpl.addDependencyToImplementation(this, forgeMixins) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) diff --git a/vanilla/build.gradle.kts b/vanilla/build.gradle.kts index 7203bca6935..def019b0dc9 100644 --- a/vanilla/build.gradle.kts +++ b/vanilla/build.gradle.kts @@ -71,8 +71,7 @@ val vanillaInstaller by sourceSets.register("installer") { // Boot layer val vanillaAppLaunch by sourceSets.register("applaunch") { - // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(applaunch.get(), this) configurations.named(implementationConfigurationName) { extendsFrom(bootLayerConfig.get()) @@ -81,58 +80,55 @@ val vanillaAppLaunch by sourceSets.register("applaunch") { // Game layer val vanillaLaunch by sourceSets.register("launch") { - // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, vanillaAppLaunch, this, project, this.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(applaunch.get(), this) + spongeImpl.addDependencyToImplementation(launch.get(), this) + spongeImpl.addDependencyToImplementation(main.get(), this) + spongeImpl.addDependencyToImplementation(vanillaAppLaunch, this) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) } } val vanillaAccessors by sourceSets.register("accessors") { - spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(accessors.get(), this) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) } } val vanillaMixins by sourceSets.register("mixins") { - // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, mixins.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, vanillaAppLaunch, this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, vanillaLaunch, this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, vanillaAccessors, this, project, this.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(applaunch.get(), this) + spongeImpl.addDependencyToImplementation(launch.get(), this) + spongeImpl.addDependencyToImplementation(accessors.get(), this) + spongeImpl.addDependencyToImplementation(mixins.get(), this) + spongeImpl.addDependencyToImplementation(main.get(), this) + spongeImpl.addDependencyToImplementation(vanillaAppLaunch, this) + spongeImpl.addDependencyToImplementation(vanillaLaunch, this) + spongeImpl.addDependencyToImplementation(vanillaAccessors, this) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) } } val vanillaMain by sourceSets.named("main") { - // implementation (compile) dependencies - spongeImpl.applyNamedDependencyOnOutput(commonProject, applaunch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, launch.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, accessors.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(commonProject, main.get(), this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, vanillaAppLaunch, this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, vanillaLaunch, this, project, this.implementationConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, vanillaAccessors, this, project, this.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(applaunch.get(), this) + spongeImpl.addDependencyToImplementation(launch.get(), this) + spongeImpl.addDependencyToImplementation(accessors.get(), this) + spongeImpl.addDependencyToImplementation(main.get(), this) + spongeImpl.addDependencyToImplementation(vanillaAppLaunch, this) + spongeImpl.addDependencyToImplementation(vanillaLaunch, this) + spongeImpl.addDependencyToImplementation(vanillaAccessors, this) - spongeImpl.applyNamedDependencyOnOutput(project, this, vanillaMixins, project, vanillaMixins.implementationConfigurationName) + spongeImpl.addDependencyToImplementation(this, vanillaMixins) configurations.named(implementationConfigurationName) { extendsFrom(gameLayerConfig.get()) } - // runtime dependencies - the rest of the project because we want everything in the initial classpath - spongeImpl.applyNamedDependencyOnOutput(commonProject, mixins.get(), this, project, this.runtimeOnlyConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, vanillaDevLaunch, this, project, this.runtimeOnlyConfigurationName) - spongeImpl.applyNamedDependencyOnOutput(project, vanillaMixins, this, project, this.runtimeOnlyConfigurationName) + // The rest of the project because we want everything in the initial classpath + spongeImpl.addDependencyToRuntimeOnly(mixins.get(), this) + spongeImpl.addDependencyToRuntimeOnly(vanillaDevLaunch, this) + spongeImpl.addDependencyToRuntimeOnly(vanillaMixins, this) configurations.named(runtimeOnlyConfigurationName) { extendsFrom(devlaunchLibrariesConfig.get()) From 7758e35244bb8ed9af9844a0bf02463a026f5840 Mon Sep 17 00:00:00 2001 From: Yeregorix Date: Thu, 19 Dec 2024 18:02:08 +0100 Subject: [PATCH 5/9] Remove build tasks on sync --- build.gradle.kts | 11 ----------- modlauncher-transformers/build.gradle.kts | 9 --------- 2 files changed, 20 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 7db73e468ba..8b9efa756d7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -184,17 +184,6 @@ indraSpotlessLicenser { property("url", projectUrl) } -idea { - if (project != null) { - (project as ExtensionAware).extensions["settings"].run { - (this as ExtensionAware).extensions.getByType(org.jetbrains.gradle.ext.TaskTriggersConfig::class).run { - afterSync(":modlauncher-transformers:build") - afterSync(":library-manager:build") - } - } - } -} - allprojects { configurations.configureEach { resolutionStrategy.dependencySubstitution { diff --git a/modlauncher-transformers/build.gradle.kts b/modlauncher-transformers/build.gradle.kts index 1398d3d3d44..b9afded8cc1 100644 --- a/modlauncher-transformers/build.gradle.kts +++ b/modlauncher-transformers/build.gradle.kts @@ -1,12 +1,3 @@ -plugins { - eclipse - idea -} -// Make sure jar is present for other projects -eclipse { - synchronizationTasks(tasks.jar) -} - val organization: String by project val projectUrl: String by project From 9791af551c62e8455aa8f76544cc0b00ffd2da86 Mon Sep 17 00:00:00 2001 From: Yeregorix Date: Thu, 19 Dec 2024 18:24:46 +0100 Subject: [PATCH 6/9] Move indraSpotlessLicenser to allprojects section --- build.gradle.kts | 16 ++++++++-------- forge/build.gradle.kts | 9 --------- generator/build.gradle.kts | 12 ------------ library-manager/build.gradle.kts | 11 ----------- modlauncher-transformers/build.gradle.kts | 11 ----------- neoforge/build.gradle.kts | 9 --------- testplugins/build.gradle.kts | 10 ---------- vanilla/build.gradle.kts | 9 --------- 8 files changed, 8 insertions(+), 79 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8b9efa756d7..936320ff20b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -176,14 +176,6 @@ dependencies { } } -indraSpotlessLicenser { - licenseHeaderFile(rootProject.file("HEADER.txt")) - - property("name", "Sponge") - property("organization", organization) - property("url", projectUrl) -} - allprojects { configurations.configureEach { resolutionStrategy.dependencySubstitution { @@ -274,6 +266,14 @@ allprojects { } } + indraSpotlessLicenser { + licenseHeaderFile(rootProject.file("HEADER.txt")) + + property("name", "Sponge") + property("organization", organization) + property("url", projectUrl) + } + val spongeSnapshotRepo: String? by project val spongeReleaseRepo: String? by project tasks { diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index f25aea2f1aa..7aeb4a2e696 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -26,7 +26,6 @@ val apiVersion: String by project val minecraftVersion: String by project val forgeVersion: String by project val recommendedVersion: String by project -val organization: String by project val projectUrl: String by project description = "The SpongeAPI implementation for MinecraftForge" @@ -433,14 +432,6 @@ sourceSets { } } -indraSpotlessLicenser { - licenseHeaderFile(rootProject.file("HEADER.txt")) - - property("name", "Sponge") - property("organization", organization) - property("url", projectUrl) -} - publishing { publications { register("sponge", MavenPublication::class) { diff --git a/generator/build.gradle.kts b/generator/build.gradle.kts index d2a16fbe78f..6481b69c15c 100644 --- a/generator/build.gradle.kts +++ b/generator/build.gradle.kts @@ -2,10 +2,6 @@ plugins { id("org.spongepowered.gradle.vanilla") } -val apiVersion: String by project -val organization: String by project -val projectUrl: String by project - description = "Code generator for automatically producing API catalog classes based off of Vanilla MC data" minecraft { @@ -30,14 +26,6 @@ dependencies { runtimeOnly(libs.tinylog.slf4j) } -indraSpotlessLicenser { - licenseHeaderFile(rootProject.file("HEADER.txt")) - - property("name", "Sponge") - property("organization", organization) - property("url", projectUrl) -} - val apiBase = rootProject.file("SpongeAPI/src/main/java/") val temporaryLicenseHeader = project.layout.buildDirectory.file("api-gen-license-header.txt") tasks.register("generateApiData", JavaExec::class) { diff --git a/library-manager/build.gradle.kts b/library-manager/build.gradle.kts index 4e7759a828a..e2a23945059 100644 --- a/library-manager/build.gradle.kts +++ b/library-manager/build.gradle.kts @@ -1,14 +1,3 @@ -val organization: String by project -val projectUrl: String by project - -indraSpotlessLicenser { - licenseHeaderFile(rootProject.file("HEADER.txt")) - - property("name", "Sponge") - property("organization", organization) - property("url", projectUrl) -} - dependencies { implementation(apiLibs.gson) } diff --git a/modlauncher-transformers/build.gradle.kts b/modlauncher-transformers/build.gradle.kts index b9afded8cc1..390fab762bd 100644 --- a/modlauncher-transformers/build.gradle.kts +++ b/modlauncher-transformers/build.gradle.kts @@ -1,14 +1,3 @@ -val organization: String by project -val projectUrl: String by project - -indraSpotlessLicenser { - licenseHeaderFile(rootProject.file("HEADER.txt")) - - property("name", "Sponge") - property("organization", organization) - property("url", projectUrl) -} - dependencies { // AccessWidener transformer implementation(libs.accessWidener) { diff --git a/neoforge/build.gradle.kts b/neoforge/build.gradle.kts index 1cb8d3937c3..a7b86632259 100644 --- a/neoforge/build.gradle.kts +++ b/neoforge/build.gradle.kts @@ -26,7 +26,6 @@ val apiVersion: String by project val minecraftVersion: String by project val neoForgeVersion: String by project val recommendedVersion: String by project -val organization: String by project val projectUrl: String by project description = "The SpongeAPI implementation for NeoForge" @@ -417,14 +416,6 @@ sourceSets { } } -indraSpotlessLicenser { - licenseHeaderFile(rootProject.file("HEADER.txt")) - - property("name", "Sponge") - property("organization", organization) - property("url", projectUrl) -} - publishing { publications { register("sponge", MavenPublication::class) { diff --git a/testplugins/build.gradle.kts b/testplugins/build.gradle.kts index 10bd0a7c960..293ff49b8e4 100644 --- a/testplugins/build.gradle.kts +++ b/testplugins/build.gradle.kts @@ -1,15 +1,5 @@ val apiVersion: String by project -val organization: String by project -val projectUrl: String by project dependencies { annotationProcessor(implementation("org.spongepowered:spongeapi:$apiVersion")!!) } - -indraSpotlessLicenser { - licenseHeaderFile(rootProject.file("HEADER.txt")) - - property("name", "Sponge") - property("organization", organization) - property("url", projectUrl) -} diff --git a/vanilla/build.gradle.kts b/vanilla/build.gradle.kts index def019b0dc9..b936a70281c 100644 --- a/vanilla/build.gradle.kts +++ b/vanilla/build.gradle.kts @@ -17,7 +17,6 @@ val apiVersion: String by project val apiJavaTarget: String by project val minecraftVersion: String by project val recommendedVersion: String by project -val organization: String by project val projectUrl: String by project description = "The SpongeAPI implementation for Vanilla Minecraft" @@ -518,14 +517,6 @@ tasks { } } -indraSpotlessLicenser { - licenseHeaderFile(rootProject.file("HEADER.txt")) - - property("name", "Sponge") - property("organization", organization) - property("url", projectUrl) -} - val universalJar by tasks.existing val vanillaInstallerJar by tasks.existing val vanillaAppLaunchJar by tasks.existing From 06ebd1d3479b9edda29d7de58c036b49db3d0928 Mon Sep 17 00:00:00 2001 From: Yeregorix Date: Sun, 22 Dec 2024 22:33:02 +0100 Subject: [PATCH 7/9] Fix dev classpath when root directory is not "Sponge" --- vanilla/build.gradle.kts | 1 + .../vanilla/devlaunch/SourceSet.java | 30 ++++--- .../devlaunch/SpongeDevClasspathFixer.java | 85 +++++++++++-------- 3 files changed, 65 insertions(+), 51 deletions(-) diff --git a/vanilla/build.gradle.kts b/vanilla/build.gradle.kts index b936a70281c..3595ab06aab 100644 --- a/vanilla/build.gradle.kts +++ b/vanilla/build.gradle.kts @@ -329,6 +329,7 @@ minecraft { mainClass("net.minecraftforge.bootstrap.ForgeBootstrap") // Configure resources + jvmArgs("-Dsponge.dev.root=" + project.rootDir) jvmArgs("-Dsponge.dev.boot=" + bootLayerConfig.get().resolvedConfiguration.resolvedArtifacts.joinToString(";") { it.file.name }) jvmArgs("-Dsponge.dev.gameShaded=" + gameShadedLibrariesConfig.get().resolvedConfiguration.resolvedArtifacts.joinToString(";") { it.file.name }) } diff --git a/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java b/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java index a4fa3b1b537..6bc2ef07a88 100644 --- a/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java +++ b/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java @@ -29,7 +29,7 @@ import java.util.ArrayList; import java.util.List; -public record SourceSet(String project, String name, String format) { +public record SourceSet(Path project, String name, String format) { @Override public String toString() { @@ -57,32 +57,34 @@ public static SourceSet identify(Path path) { } // from right to left - final List parts = new ArrayList<>(); + final List names = new ArrayList<>(); + final List paths = new ArrayList<>(); while (path != null) { - parts.add(path.getFileName().toString()); - if (parts.size() >= 5) { + names.add(path.getFileName().toString()); + paths.add(path); + if (names.size() >= 5) { break; } path = path.getParent(); } - if (parts.size() >= 4 && (parts.get(0).equals("classes") || parts.get(0).equals("resources"))) { - final String name = parts.get(1); - return new SourceSet(parts.get(3), name.equals("production") ? "main" : name, "IntelliJ"); + if (names.size() >= 4 && (names.get(0).equals("classes") || names.get(0).equals("resources"))) { + final String name = names.get(1); + return new SourceSet(paths.get(3), name.equals("production") ? "main" : name, "IntelliJ"); } - if (parts.size() >= 4 && (parts.get(1).equals("resources") || parts.get(1).equals("generated"))) { - return new SourceSet(parts.get(3), parts.get(0), "Gradle"); + if (names.size() >= 4 && (names.get(1).equals("resources") || names.get(1).equals("generated"))) { + return new SourceSet(paths.get(3), names.get(0), "Gradle"); } - if (parts.size() >= 5 && parts.get(2).equals("classes")) { - return new SourceSet(parts.get(4), parts.get(0), "Gradle"); + if (names.size() >= 5 && names.get(2).equals("classes")) { + return new SourceSet(paths.get(4), names.get(0), "Gradle"); } - if (parts.size() >= 3 && parts.get(1).equals("bin")) { - return new SourceSet(parts.get(2), parts.get(0), "Eclipse"); + if (names.size() >= 3 && names.get(1).equals("bin")) { + return new SourceSet(paths.get(2), names.get(0), "Eclipse"); } - return new SourceSet("", parts.get(0), "Unknown"); + return new SourceSet(paths.get(0), "?", "Unknown"); } } diff --git a/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java b/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java index 47c8f979594..ba527b23e6b 100644 --- a/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java +++ b/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java @@ -28,6 +28,7 @@ import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; @@ -51,6 +52,7 @@ public String name() { */ @Override public boolean process(final List classpath) { + final Path spongeRoot = Paths.get(System.getProperty("sponge.dev.root")).toAbsolutePath(); final Set bootLibs = Set.of(System.getProperty("sponge.dev.boot").split(";")); final Set gameShadedLibs = Set.of(System.getProperty("sponge.dev.gameShaded").split(";")); @@ -67,46 +69,55 @@ public boolean process(final List classpath) { return false; } - final Path path = paths[0]; + final Path path = paths[0].toAbsolutePath(); final SourceSet sourceSet = SourceSet.identify(path); if (sourceSet != null) { - if (DEBUG) { - System.out.println("SourceSet (" + sourceSet + "): " + path); - } + if (sourceSet.project().startsWith(spongeRoot)) { + if (DEBUG) { + System.out.println("Sponge SourceSet (" + sourceSet + "): " + path); + } - switch (sourceSet.project()) { - case "modlauncher-transformers": - bootSourceSets.computeIfAbsent("transformers", k -> new LinkedList<>()).add(path); - break; - case "SpongeAPI": - switch (sourceSet.name()) { - case "ap": - // ignore - break; - case "main": - hasAPISourceSet.set(true); - // no break - default: - spongeImplUnion.add(path); - break; - } - break; - case "Sponge", "vanilla": - switch (sourceSet.name()) { - case "devlaunch": - // ignore - break; - case "applaunch": - bootSourceSets.computeIfAbsent("applaunch", k -> new LinkedList<>()).add(path); - break; - default: - spongeImplUnion.add(path); - break; - } - break; - default: - unknownProjects.computeIfAbsent(sourceSet.project(), k -> new LinkedList<>()).add(path); - break; + final String projectName = spongeRoot.relativize(sourceSet.project()).toString(); + switch (projectName) { + case "modlauncher-transformers": + bootSourceSets.computeIfAbsent("transformers", k -> new LinkedList<>()).add(path); + break; + case "SpongeAPI": + switch (sourceSet.name()) { + case "ap": + // ignore + break; + case "main": + hasAPISourceSet.set(true); + // no break + default: + spongeImplUnion.add(path); + break; + } + break; + case "", "vanilla": + switch (sourceSet.name()) { + case "devlaunch": + // ignore + break; + case "applaunch": + bootSourceSets.computeIfAbsent("applaunch", k -> new LinkedList<>()).add(path); + break; + default: + spongeImplUnion.add(path); + break; + } + break; + default: + unknownProjects.computeIfAbsent(projectName, k -> new LinkedList<>()).add(path); + break; + } + } else { + if (DEBUG) { + System.out.println("External SourceSet (" + sourceSet + "): " + path); + } + + unknownProjects.computeIfAbsent(sourceSet.project().toString(), k -> new LinkedList<>()).add(path); } return true; } From e5e0121efd81dd8d9921262a9e53800d91a7ca1a Mon Sep 17 00:00:00 2001 From: aromaa Date: Mon, 23 Dec 2024 00:45:33 +0200 Subject: [PATCH 8/9] Fix ExplosionEvent.Pre cancelling --- .../tracker/server/level/ServerLevelMixin_Tracker.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerLevelMixin_Tracker.java b/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerLevelMixin_Tracker.java index e1766cb999a..990a2389412 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerLevelMixin_Tracker.java +++ b/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerLevelMixin_Tracker.java @@ -373,6 +373,14 @@ public abstract class ServerLevelMixin_Tracker extends LevelMixin_Tracker implem this.tracker$apiExplosion = apiExplosion; } + @Inject(method = "explode", cancellable = true, at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/ServerExplosion;explode()V", shift = At.Shift.AFTER)) + private void tracker$onCancelled(final CallbackInfo ci) { + if (this.tracker$apiExplosion == null) { + ci.cancel(); + } + } + /** * See {@link net.minecraft.client.multiplayer.ClientPacketListener#handleExplosion} for client side handling */ From 707b3f1ac6fd309338d6affd9b60bd4a4938b45d Mon Sep 17 00:00:00 2001 From: aromaa Date: Mon, 23 Dec 2024 00:46:14 +0200 Subject: [PATCH 9/9] Implement tab list entry order --- SpongeAPI | 2 +- .../common/entity/player/tab/SpongeTabList.java | 4 ++-- .../entity/player/tab/SpongeTabListEntry.java | 16 +++++++++++++++- .../entity/player/tab/TabListEntryBuilder.java | 11 ++++++++++- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/SpongeAPI b/SpongeAPI index c0f65a12e41..f4245597d6d 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit c0f65a12e41afb4a6891efd0c6c00a7b0f2ddea4 +Subproject commit f4245597d6dc09becafbcff46a1afbc365ee2eca diff --git a/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabList.java b/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabList.java index 8d49e1212f2..072decba587 100644 --- a/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabList.java +++ b/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabList.java @@ -151,6 +151,7 @@ private void addEntry(final ClientboundPlayerInfoUpdatePacket.Entry entry) { entry.latency(), (GameMode) (Object) entry.gameMode(), entry.listed(), + entry.listOrder(), entry.chatSession() == null ? null : entry.chatSession().profilePublicKey() ), false); } @@ -190,11 +191,10 @@ public Optional removeEntry(final UUID uniqueId) { @SuppressWarnings("ConstantConditions") void sendUpdate(final TabListEntry entry, final EnumSet actions) { final ClientboundPlayerInfoUpdatePacket packet = new ClientboundPlayerInfoUpdatePacket(actions, List.of()); - int listOrder = 0; // TODO expose to API final RemoteChatSession.Data chatSessionData = ((SpongeTabListEntry) entry).profilePublicKey() == null ? null : new RemoteChatSession.Data(entry.profile().uuid(), ((SpongeTabListEntry) entry).profilePublicKey()); final net.minecraft.network.chat.Component displayName = entry.displayName().isPresent() ? SpongeAdventure.asVanilla(entry.displayName().get()) : null; final ClientboundPlayerInfoUpdatePacket.Entry data = new ClientboundPlayerInfoUpdatePacket.Entry(entry.profile().uniqueId(), SpongeGameProfile.toMcProfile(entry.profile()), - entry.listed(), entry.latency(), (GameType) (Object) entry.gameMode(), displayName, listOrder, chatSessionData); + entry.listed(), entry.latency(), (GameType) (Object) entry.gameMode(), displayName, entry.weight(), chatSessionData); ((ClientboundPlayerInfoUpdatePacketAccessor) packet).accessor$entries(List.of(data)); this.player.connection.send(packet); } diff --git a/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabListEntry.java b/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabListEntry.java index 355ada3d91b..566f25f008e 100644 --- a/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabListEntry.java +++ b/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabListEntry.java @@ -52,12 +52,13 @@ public final class SpongeTabListEntry implements TabListEntry { private int latency; private GameMode gameMode; private boolean listed; + private int weight; private boolean updateWithoutSend; private final ProfilePublicKey.Data profilePublicKey; public SpongeTabListEntry( final TabList list, final GameProfile profile, @Nullable final Component displayName, final int latency, final GameMode gameMode, - final boolean listed, final ProfilePublicKey.Data profilePublicKey) { + final boolean listed, final int weight, final ProfilePublicKey.Data profilePublicKey) { Preconditions.checkState(list instanceof SpongeTabList, "list is not a SpongeTabList"); this.list = (SpongeTabList) list; this.profile = Objects.requireNonNull(profile, "profile"); @@ -65,6 +66,7 @@ public SpongeTabListEntry( this.latency = latency; this.gameMode = Objects.requireNonNull(gameMode, "game mode"); this.listed = listed; + this.weight = weight; this.profilePublicKey = profilePublicKey; } @@ -126,6 +128,18 @@ public SpongeTabListEntry setListed(boolean listed) { return this; } + @Override + public int weight() { + return this.weight; + } + + @Override + public SpongeTabListEntry setWeight(int weight) { + this.weight = weight; + this.sendUpdate(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LIST_ORDER); + return this; + } + public ProfilePublicKey.Data profilePublicKey() { return this.profilePublicKey; } diff --git a/src/main/java/org/spongepowered/common/entity/player/tab/TabListEntryBuilder.java b/src/main/java/org/spongepowered/common/entity/player/tab/TabListEntryBuilder.java index cb974eb6caf..3c1e136d1cd 100644 --- a/src/main/java/org/spongepowered/common/entity/player/tab/TabListEntryBuilder.java +++ b/src/main/java/org/spongepowered/common/entity/player/tab/TabListEntryBuilder.java @@ -44,6 +44,7 @@ public final class TabListEntryBuilder implements TabListEntry.Builder { private int latency; private boolean listed = true; private @Nullable GameMode gameMode; + private int weight; @Override public TabListEntry.Builder list(TabList list) { @@ -81,13 +82,19 @@ public TabListEntry.Builder listed(boolean listed) { return this; } + @Override + public TabListEntry.Builder weight(int weight) { + this.weight = weight; + return this; + } + @Override public TabListEntry build() { Preconditions.checkState(this.list != null, "list must be set"); Preconditions.checkState(this.profile != null, "profile must be set"); Preconditions.checkState(this.gameMode != null, "game mode must be set"); - return new SpongeTabListEntry(this.list, this.profile, this.displayName, this.latency, this.gameMode, this.listed, null); + return new SpongeTabListEntry(this.list, this.profile, this.displayName, this.latency, this.gameMode, this.listed, this.weight, null); } @Override @@ -97,6 +104,7 @@ public TabListEntry.Builder from(TabListEntry value) { this.displayName = value.displayName().orElse(null); this.latency = value.latency(); this.gameMode = Objects.requireNonNull(value.gameMode(), "game mode"); + this.weight = value.weight(); return this; } @@ -107,6 +115,7 @@ public TabListEntry.Builder reset() { this.displayName = null; this.latency = 0; this.gameMode = null; + this.weight = 0; return this; }