diff --git a/src/main/java/net/fabricmc/loom/LoomRepositoryPlugin.java b/src/main/java/net/fabricmc/loom/LoomRepositoryPlugin.java index 1aed10a2..8b89642c 100644 --- a/src/main/java/net/fabricmc/loom/LoomRepositoryPlugin.java +++ b/src/main/java/net/fabricmc/loom/LoomRepositoryPlugin.java @@ -28,6 +28,7 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.artifacts.dsl.RepositoryHandler; import org.gradle.api.artifacts.repositories.IvyArtifactRepository; +import org.gradle.api.artifacts.repositories.MavenArtifactRepository; import org.gradle.api.initialization.Settings; import org.gradle.api.invocation.Gradle; import org.gradle.api.plugins.ExtensionAware; @@ -92,4 +93,15 @@ public class LoomRepositoryPlugin implements Plugin { repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact); }); } + + public static void setupForLegacyVersions(Project project) { + // 1.4.7 contains an LWJGL version with an invalid maven pom, set the metadata sources to not use the pom for this version. + project.getRepositories().named("Mojang", MavenArtifactRepository.class, repo -> { + repo.metadataSources(sources -> { + // Only use the maven artifact and not the pom or gradle metadata. + sources.artifact(); + sources.ignoreGradleMetadataRedirection(); + }); + }); + } } diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftLibraryProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftLibraryProvider.java index e62785fe..f7834c69 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftLibraryProvider.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftLibraryProvider.java @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2018-2021 FabricMC + * Copyright (c) 2018-2022 FabricMC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -31,12 +31,13 @@ import org.gradle.api.Project; import org.gradle.api.artifacts.ExternalModuleDependency; import net.fabricmc.loom.LoomGradleExtension; +import net.fabricmc.loom.LoomRepositoryPlugin; import net.fabricmc.loom.configuration.providers.BundleMetadata; import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.OperatingSystem; public class MinecraftLibraryProvider { - private static final Pattern NATIVES_PATTERN = Pattern.compile("^(?.*)/(.*?)/(?.*)/((?.*?)-([0-9].*?)-)(?.*).jar$"); + private static final Pattern NATIVES_PATTERN = Pattern.compile("^(?.*)/(.*?)/(?.*)/((?.*?)-(\\k)-)(?.*).jar$"); public void provide(MinecraftProvider minecraftProvider, Project project) { final LoomGradleExtension extension = LoomGradleExtension.get(project); @@ -58,6 +59,11 @@ public class MinecraftLibraryProvider { } if (library.isValidForOS() && !library.hasNatives() && library.artifact() != null) { + // 1.4.7 contains an LWJGL version with an invalid maven pom, set the metadata sources to not use the pom for this version. + if ("org.lwjgl.lwjgl:lwjgl:2.9.1-nightly-20130708-debug3".equals(library.name())) { + LoomRepositoryPlugin.setupForLegacyVersions(project); + } + if (runtimeOnlyLog4j && library.name().startsWith("org.apache.logging.log4j")) { // Make log4j a runtime only dep to force slf4j. project.getDependencies().add(Constants.Configurations.MINECRAFT_RUNTIME_DEPENDENCIES, library.name()); @@ -74,10 +80,15 @@ public class MinecraftLibraryProvider { if (library.hasNativesForOS()) { MinecraftVersionMeta.Download nativeDownload = library.classifierForOS(); - Matcher matcher = NATIVES_PATTERN.matcher(nativeDownload.path()); + if (nativeDownload == null) { + continue; + } + + final String path = nativeDownload.path(); + final Matcher matcher = NATIVES_PATTERN.matcher(path); if (!matcher.find()) { - project.getLogger().warn("Failed to match regex for natives path : " + nativeDownload.path()); + project.getLogger().warn("Failed to match regex for natives path : " + path); continue; } diff --git a/src/test/groovy/net/fabricmc/loom/test/LoomTestConstants.groovy b/src/test/groovy/net/fabricmc/loom/test/LoomTestConstants.groovy index 28bcc7f8..64ce9495 100644 --- a/src/test/groovy/net/fabricmc/loom/test/LoomTestConstants.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/LoomTestConstants.groovy @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2021 FabricMC + * Copyright (c) 2021-2022 FabricMC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,7 +28,7 @@ import org.gradle.util.GradleVersion class LoomTestConstants { public final static String DEFAULT_GRADLE = GradleVersion.current().getVersion() - public final static String PRE_RELEASE_GRADLE = "7.5-20220122232041+0000" + public final static String PRE_RELEASE_GRADLE = "7.5-20220124231322+0000" public final static String[] STANDARD_TEST_VERSIONS = [DEFAULT_GRADLE, PRE_RELEASE_GRADLE] } diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/DecompileTest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/DecompileTest.groovy index e4666f69..9e93097a 100644 --- a/src/test/groovy/net/fabricmc/loom/test/integration/DecompileTest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/integration/DecompileTest.groovy @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2016-2021 FabricMC + * Copyright (c) 2016-2022 FabricMC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -45,9 +45,7 @@ class DecompileTest extends Specification implements GradleProjectTestTrait { where: decompiler | task | version - 'fernflower' | "genSourcesWithFernFlower" | DEFAULT_GRADLE 'fernflower' | "genSourcesWithFernFlower" | PRE_RELEASE_GRADLE - 'cfr' | "genSourcesWithCfr" | DEFAULT_GRADLE 'cfr' | "genSourcesWithCfr" | PRE_RELEASE_GRADLE } diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/LegacyProjectTest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/LegacyProjectTest.groovy index d8eeb66b..75259a17 100644 --- a/src/test/groovy/net/fabricmc/loom/test/integration/LegacyProjectTest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/integration/LegacyProjectTest.groovy @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2018-2021 FabricMC + * Copyright (c) 2018-2022 FabricMC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,7 +28,8 @@ import net.fabricmc.loom.test.util.GradleProjectTestTrait import spock.lang.Specification import spock.lang.Unroll -import static net.fabricmc.loom.test.LoomTestConstants.* +import static net.fabricmc.loom.test.LoomTestConstants.PRE_RELEASE_GRADLE +import static net.fabricmc.loom.test.LoomTestConstants.STANDARD_TEST_VERSIONS import static org.gradle.testkit.runner.TaskOutcome.SUCCESS // This test uses gradle 4.9 and 1.14.4 v1 mappings @@ -47,4 +48,40 @@ class LegacyProjectTest extends Specification implements GradleProjectTestTrait where: version << STANDARD_TEST_VERSIONS } + + @Unroll + def "Unsupported minecraft (minecraft #version)"() { + setup: + def gradle = gradleProject(project: "minimalBase", version: PRE_RELEASE_GRADLE) + gradle.buildGradle << """ + loom { + intermediaryUrl = 'https://s.modm.us/intermediary-empty-v2.jar' + } + + dependencies { + minecraft "com.mojang:minecraft:${version}" + mappings loom.layered() { + // No names + } + + modImplementation "net.fabricmc:fabric-loader:0.12.12" + } + """ + + when: + def result = gradle.run(task: "configureClientLaunch") + + then: + result.task(":configureClientLaunch").outcome == SUCCESS + + where: + version | _ + '1.13.2' | _ + '1.12.2' | _ + '1.8.9' | _ + '1.7.10' | _ + '1.6.4' | _ + '1.4.7' | _ + '1.3.2' | _ + } }