diff --git a/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java index eea3de0bd..93c34b56a 100644 --- a/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java +++ b/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java @@ -26,6 +26,7 @@ import static net.fabricmc.loom.util.Constants.Configurations; +import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; @@ -34,6 +35,7 @@ import java.time.Duration; import java.util.Optional; import java.util.function.Consumer; +import java.util.stream.Collectors; import javax.inject.Inject; @@ -47,6 +49,7 @@ import org.gradle.api.tasks.TaskContainer; import org.gradle.api.tasks.compile.JavaCompile; import org.gradle.api.tasks.javadoc.Javadoc; +import org.gradle.api.tasks.testing.Test; import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.api.InterfaceInjectionExtensionAPI; @@ -128,6 +131,7 @@ public void run() { } configureDecompileTasks(configContext); + configureTestTask(); }); finalizedBy("eclipse", "genEclipseRuns"); @@ -244,6 +248,26 @@ private void configureDecompileTasks(ConfigContext configContext) { .afterEvaluation(); } + private void configureTestTask() { + final LoomGradleExtension extension = LoomGradleExtension.get(getProject()); + + if (extension.getMods().isEmpty()) { + return; + } + + getProject().getTasks().named(JavaPlugin.TEST_TASK_NAME, Test.class, test -> { + String classPathGroups = extension.getMods().stream() + .map(modSettings -> + SourceSetHelper.getClasspath(modSettings, getProject()).stream() + .map(File::getAbsolutePath) + .collect(Collectors.joining(File.pathSeparator)) + ) + .collect(Collectors.joining(File.pathSeparator+File.pathSeparator));; + + test.systemProperty("fabric.classPathGroups", classPathGroups); + }); + } + private LockFile getLockFile() { final LoomGradleExtension extension = LoomGradleExtension.get(getProject()); final Path cacheDirectory = extension.getFiles().getUserCache().toPath(); diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/FabricAPITest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/FabricAPITest.groovy index 76186f0c1..3ddf503ab 100644 --- a/src/test/groovy/net/fabricmc/loom/test/integration/FabricAPITest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/integration/FabricAPITest.groovy @@ -44,7 +44,7 @@ class FabricAPITest extends Specification implements GradleProjectTestTrait { setup: def gradle = gradleProject( repo: "https://github.com/FabricMC/fabric.git", - commit: "41bc64cd617f03d49ecc4a4f7788cb65d465415c", + commit: "70277babddfaf52ee30013af94764da19473b3b1", version: version, patch: "fabric_api" ) @@ -58,7 +58,7 @@ class FabricAPITest extends Specification implements GradleProjectTestTrait { """.stripIndent() } - def minecraftVersion = "1.21" + def minecraftVersion = "1.21.4-pre3" def server = ServerRunner.create(gradle.projectDir, minecraftVersion) .withMod(gradle.getOutputFile("fabric-api-999.0.0.jar")) diff --git a/src/test/resources/patches/fabric_api.patch b/src/test/resources/patches/fabric_api.patch index 5e8c24763..c51f6f161 100644 --- a/src/test/resources/patches/fabric_api.patch +++ b/src/test/resources/patches/fabric_api.patch @@ -1,15 +1,6 @@ diff --git a/build.gradle b/build.gradle ---- a/build.gradle (revision 41bc64cd617f03d49ecc4a4f7788cb65d465415c) -+++ b/build.gradle (date 1718312645477) -@@ -13,7 +13,7 @@ - - def ENV = System.getenv() - --version = project.version + "+" + (ENV.GITHUB_RUN_NUMBER ? "" : "local-") + getBranch() -+version = "999.0.0" - logger.lifecycle("Building Fabric: " + version) - - def metaProjects = [ +--- a/build.gradle (revision 70277babddfaf52ee30013af94764da19473b3b1) ++++ b/build.gradle (date 1732874605816) @@ -34,24 +34,7 @@ import org.apache.commons.codec.digest.DigestUtils @@ -34,5 +25,25 @@ diff --git a/build.gradle b/build.gradle - return version + "+" + latestCommits.get(0).id.substring(0, 8) + DigestUtils.sha256Hex(project.rootProject.minecraft_version).substring(0, 2) + return "999.0.0" } - + def getBranch() { +@@ -247,19 +230,6 @@ + + test { + useJUnitPlatform() +- +- afterEvaluate { +- // See: https://github.com/FabricMC/fabric-loader/pull/585 +- def classPathGroups = loom.mods.stream() +- .map { modSettings -> +- SourceSetHelper.getClasspath(modSettings, getProject()).stream() +- .map(File.&getAbsolutePath) +- .collect(Collectors.joining(File.pathSeparator)) +- } +- .collect(Collectors.joining(File.pathSeparator+File.pathSeparator)) +- +- systemProperty("fabric.classPathGroups", classPathGroups) +- } + } + + tasks.withType(ProcessResources).configureEach {