Update deps, suppress 8.11 warnings, remove self resolving dependency code (#1180)

* Update a handful of deps

* Fully remove deprecated SelfResolvingDependency support

* Work around Gradle 8.11 deprecation, lets deal with it later.
This commit is contained in:
modmuss
2024-09-26 22:29:43 +01:00
committed by GitHub
parent 567f978578
commit e4d4503e2a
12 changed files with 28 additions and 219 deletions

View File

@@ -46,7 +46,6 @@ import net.fabricmc.loom.configuration.providers.minecraft.library.LibraryProces
import net.fabricmc.loom.configuration.providers.minecraft.mapped.IntermediaryMinecraftProvider;
import net.fabricmc.loom.configuration.providers.minecraft.mapped.NamedMinecraftProvider;
import net.fabricmc.loom.extension.LoomFiles;
import net.fabricmc.loom.extension.LoomProblemReporter;
import net.fabricmc.loom.extension.MixinExtension;
import net.fabricmc.loom.extension.RemapperExtensionHolder;
import net.fabricmc.loom.util.download.DownloadBuilder;
@@ -116,7 +115,5 @@ public interface LoomGradleExtension extends LoomGradleExtensionAPI {
Collection<LayeredMappingsFactory> getLayeredMappingFactories();
LoomProblemReporter getProblemReporter();
boolean isConfigurationCacheActive();
}

View File

@@ -37,9 +37,6 @@ import org.gradle.api.artifacts.ResolvedDependency;
import org.gradle.api.artifacts.component.ComponentIdentifier;
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.gradle.SelfResolvingDependencyUtils;
public class DependencyInfo {
final Project project;
final Dependency dependency;
@@ -66,10 +63,7 @@ public class DependencyInfo {
}
public static DependencyInfo create(Project project, Dependency dependency, Configuration sourceConfiguration) {
if (SelfResolvingDependencyUtils.isExplicitSRD(dependency)) {
LoomGradleExtension.get(project).getProblemReporter().reportSelfResolvingDependencyUsage();
return FileDependencyInfo.createForDeprecatedSRD(project, dependency, sourceConfiguration);
} else if (dependency instanceof FileCollectionDependency fileCollectionDependency) {
if (dependency instanceof FileCollectionDependency fileCollectionDependency) {
return new FileDependencyInfo(project, fileCollectionDependency, sourceConfiguration);
} else {
return new DependencyInfo(project, dependency, sourceConfiguration);

View File

@@ -46,7 +46,6 @@ import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.FileCollectionDependency;
import net.fabricmc.loom.util.ZipUtils;
import net.fabricmc.loom.util.gradle.SelfResolvingDependencyUtils;
public class FileDependencyInfo extends DependencyInfo {
protected final Map<String, File> classifierToFile = new HashMap<>();
@@ -131,15 +130,6 @@ public class FileDependencyInfo extends DependencyInfo {
}
}
@Deprecated // Remove in Gradle 9
public static FileDependencyInfo createForDeprecatedSRD(Project project, Dependency dependency, Configuration configuration) {
if (!SelfResolvingDependencyUtils.isExplicitSRD(dependency)) {
throw new IllegalArgumentException("Dependency is a FileCollectionDependency");
}
return new FileDependencyInfo(project, dependency, configuration, SelfResolvingDependencyUtils.resolve(dependency));
}
@Override
public String getResolvedVersion() {
return version;

View File

@@ -166,7 +166,7 @@ public record SpecContextImpl(List<FabricModJson> modDependencies, List<FabricMo
return configuration.getAllDependencies()
.withType(ProjectDependency.class)
.stream()
.map(ProjectDependency::getDependencyProject)
.map(GradleUtils::getDependencyProject)
.filter(GradleUtils::isLoomProject);
}

View File

@@ -34,27 +34,11 @@ import org.gradle.api.artifacts.FileCollectionDependency;
import net.fabricmc.loom.api.mappings.layered.MappingContext;
import net.fabricmc.loom.api.mappings.layered.spec.FileSpec;
import net.fabricmc.loom.configuration.providers.mappings.GradleMappingContext;
import net.fabricmc.loom.util.gradle.SelfResolvingDependencyUtils;
public record DependencyFileSpec(Dependency dependency) implements FileSpec {
@Override
public Path get(MappingContext context) {
if (SelfResolvingDependencyUtils.isExplicitSRD(dependency)) {
if (context instanceof GradleMappingContext gradleMappingContext) {
gradleMappingContext.getExtension().getProblemReporter().reportSelfResolvingDependencyUsage();
}
Set<File> files = SelfResolvingDependencyUtils.resolve(dependency);
if (files.isEmpty()) {
throw new RuntimeException("SelfResolvingDependency (%s) resolved no files".formatted(dependency.toString()));
} else if (files.size() > 1) {
throw new RuntimeException("SelfResolvingDependency (%s) resolved too many files (%d) only 1 is expected".formatted(dependency.toString(), files.size()));
}
return files.iterator().next().toPath();
} else if (dependency instanceof FileCollectionDependency fileCollectionDependency) {
if (dependency instanceof FileCollectionDependency fileCollectionDependency) {
Set<File> files = fileCollectionDependency.getFiles().getFiles();
if (files.isEmpty()) {

View File

@@ -73,7 +73,6 @@ public abstract class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl
private InstallerData installerData;
private boolean refreshDeps;
private final ListProperty<LibraryProcessorManager.LibraryProcessorFactory> libraryProcessorFactories;
private final LoomProblemReporter problemReporter;
private final boolean configurationCacheActive;
private final boolean isolatedProjectsActive;
@@ -113,8 +112,6 @@ public abstract class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl
if (refreshDeps) {
project.getLogger().lifecycle("Refresh dependencies is in use, loom will be significantly slower.");
}
problemReporter = project.getObjects().newInstance(LoomProblemReporter.class);
}
@Override
@@ -288,11 +285,6 @@ public abstract class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl
provider.getIsLegacyMinecraft().disallowChanges();
}
@Override
public LoomProblemReporter getProblemReporter() {
return problemReporter;
}
@Override
public boolean isConfigurationCacheActive() {
return configurationCacheActive;

View File

@@ -1,51 +0,0 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2024 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
* 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 net.fabricmc.loom.extension;
import javax.inject.Inject;
import org.gradle.api.problems.ProblemReporter;
import org.gradle.api.problems.Problems;
import org.gradle.api.problems.Severity;
public abstract class LoomProblemReporter {
private final ProblemReporter problemReporter;
@Inject
public LoomProblemReporter(Problems problems) {
this.problemReporter = problems.forNamespace("net.fabricmc.loom");
}
public void reportSelfResolvingDependencyUsage() {
problemReporter.reporting(spec -> spec
.id("loom-deprecated-selfresolvingdependency", "SelfResolvingDependency is deprecated")
.details("SelfResolvingDependency has been deprecated for removal in Gradle 9")
.solution("Please replace usages of SelfResolvingDependency")
.documentedAt("https://github.com/gradle/gradle/pull/27420")
.severity(Severity.WARNING)
.stackLocation()
);
}
}

View File

@@ -25,10 +25,13 @@
package net.fabricmc.loom.util.gradle;
import java.io.File;
import java.lang.reflect.Field;
import java.util.function.Consumer;
import org.gradle.api.Project;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency;
import org.gradle.api.invocation.Gradle;
import org.gradle.api.provider.Provider;
@@ -88,4 +91,18 @@ public final class GradleUtils {
property.set(file);
return property.getAsFile().get();
}
// Get the project from the field with reflection to suppress the deprecation warning.
// If you hate it find a solution yourself and make a PR, I'm getting a bit tired of chasing Gradle updates
public static Project getDependencyProject(ProjectDependency projectDependency) {
try {
final Class<DefaultProjectDependency> clazz = DefaultProjectDependency.class;
final Field dependencyProject = clazz.getDeclaredField("dependencyProject");
dependencyProject.setAccessible(true);
return (Project) dependencyProject.get(projectDependency);
} catch (NoSuchFieldException | IllegalAccessException ignored) {
// Just fallback and trigger the warning, this will break in Gradle 9
return projectDependency.getDependencyProject();
}
}
}

View File

@@ -1,114 +0,0 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2024 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
* 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 net.fabricmc.loom.util.gradle;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Set;
import javax.annotation.Nullable;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.FileCollectionDependency;
import org.gradle.api.artifacts.ProjectDependency;
// SelfResolvingDependency is deprecated for removal, use reflection to ensure backwards compat.
@Deprecated
public class SelfResolvingDependencyUtils {
// Set this system prop to disable SRD support before Gradle does.
public static final boolean DISABLE_SRD_SUPPORT = System.getProperty("fabric.loom.disable.srd") != null;
private static final String SELF_RESOLVING_DEPENDENCY_CLASS_NAME = "org.gradle.api.artifacts.SelfResolvingDependency";
@Nullable
private static final Class<?> SELF_RESOLVING_DEPENDENCY_CLASS = getSelfResolvingDependencyOrNull();
@Nullable
private static final Method RESOLVE_METHOD = getResolveMethod(SELF_RESOLVING_DEPENDENCY_CLASS);
/**
* @return true when dependency is a SelfResolvingDependency but NOT a FileCollectionDependency.
*/
public static boolean isExplicitSRD(Dependency dependency) {
// FileCollectionDependency is usually the replacement for SelfResolvingDependency
if (dependency instanceof FileCollectionDependency) {
return false;
} else if (dependency instanceof ProjectDependency) {
return false;
}
return isSRD(dependency);
}
private static boolean isSRD(Dependency dependency) {
if (SELF_RESOLVING_DEPENDENCY_CLASS == null) {
return false;
}
return dependency.getClass().isAssignableFrom(SELF_RESOLVING_DEPENDENCY_CLASS);
}
public static Set<File> resolve(Dependency dependency) {
if (!isSRD(dependency)) {
throw new IllegalStateException("dependency is not a SelfResolvingDependency");
}
try {
return (Set<File>) RESOLVE_METHOD.invoke(dependency);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Failed to resolve SelfResolvingDependency", e);
}
}
@Nullable
private static Class<?> getSelfResolvingDependencyOrNull() {
if (DISABLE_SRD_SUPPORT) {
// Lets pretend SRD doesnt exist.
return null;
}
try {
return Class.forName(SELF_RESOLVING_DEPENDENCY_CLASS_NAME);
} catch (ClassNotFoundException e) {
// Gradle 9+
return null;
}
}
@Nullable
private static Method getResolveMethod(Class<?> clazz) {
if (clazz == null) {
// Gradle 9+
return null;
}
try {
var method = clazz.getDeclaredMethod("resolve");
method.setAccessible(true);
return method;
} catch (NoSuchMethodException e) {
throw new IllegalStateException("Failed to get SelfResolvingDependency.resolve() method", e);
}
}
}