Update to Gradle 7 (#380)

* Gradle 7 part 1

* Fix actions?

* Update actions

* Fix tests not running

* Fix some broken tests

* Update kotlin to try and fix JDK 16 support

* Disable KotlinTest on j16

* exclude kotlin test from actions...
This commit is contained in:
modmuss50
2021-04-04 23:02:00 +01:00
committed by GitHub
parent 98731532d5
commit c8df12cf0f
18 changed files with 48 additions and 111 deletions

View File

@@ -27,9 +27,6 @@ package net.fabricmc.loom.configuration;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.plugins.JavaPlugin;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.gradle.GradleSupport;
public class RemappedConfigurationEntry {
private final String sourceConfiguration;
private final String targetConfiguration;
@@ -65,7 +62,7 @@ public class RemappedConfigurationEntry {
public String getTargetConfiguration(ConfigurationContainer container) {
if (container.findByName(targetConfiguration) == null) {
return GradleSupport.IS_GRADLE_7_OR_NEWER ? JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME : Constants.Configurations.COMPILE;
return JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME;
}
return targetConfiguration;

View File

@@ -61,7 +61,6 @@ import net.fabricmc.loom.configuration.accesswidener.AccessWidenerJarProcessor;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.TinyRemapperMappingsHelper;
import net.fabricmc.loom.util.gradle.GradleSupport;
import net.fabricmc.loom.util.ZipReprocessorUtil;
import net.fabricmc.stitch.util.Pair;
import net.fabricmc.tinyremapper.TinyRemapper;
@@ -79,7 +78,7 @@ public class RemapJarTask extends Jar {
public RemapJarTask() {
super();
input = GradleSupport.getfileProperty(getProject());
input = getProject().getObjects().fileProperty();
addNestedDependencies = getProject().getObjects().property(Boolean.class);
addDefaultNestedDependencies = getProject().getObjects().property(Boolean.class);
remapAccessWidener = getProject().getObjects().property(Boolean.class);

View File

@@ -31,7 +31,6 @@ import org.gradle.api.plugins.JavaPlugin;
import org.objectweb.asm.Opcodes;
import net.fabricmc.loom.configuration.RemappedConfigurationEntry;
import net.fabricmc.loom.util.gradle.GradleSupport;
public class Constants {
public static final String LIBRARIES_BASE = "https://libraries.minecraft.net/";
@@ -42,23 +41,13 @@ public class Constants {
public static final int ASM_VERSION = Opcodes.ASM9;
private static final List<RemappedConfigurationEntry> LEGACY_MOD_COMPILE_ENTRIES = ImmutableList.of(
new RemappedConfigurationEntry("modCompile", Configurations.COMPILE, true, "compile"),
public static final List<RemappedConfigurationEntry> MOD_COMPILE_ENTRIES = ImmutableList.of(
new RemappedConfigurationEntry("modApi", JavaPlugin.API_CONFIGURATION_NAME, true, "compile"),
new RemappedConfigurationEntry("modImplementation", JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, true, "runtime"),
new RemappedConfigurationEntry("modRuntime", JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME, false, ""),
new RemappedConfigurationEntry("modCompileOnly", JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, true, "")
);
private static final List<RemappedConfigurationEntry> MODERN_MOD_COMPILE_ENTRIES = ImmutableList.of(
new RemappedConfigurationEntry("modApi", JavaPlugin.API_CONFIGURATION_NAME, true, "compile"),
new RemappedConfigurationEntry("modImplementation", JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, true, "runtime"),
new RemappedConfigurationEntry("modRuntime", JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME, false, ""),
new RemappedConfigurationEntry("modCompileOnly", JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, true, "")
);
public static final List<RemappedConfigurationEntry> MOD_COMPILE_ENTRIES = GradleSupport.IS_GRADLE_7_OR_NEWER ? MODERN_MOD_COMPILE_ENTRIES : LEGACY_MOD_COMPILE_ENTRIES;
private Constants() {
}
@@ -77,8 +66,6 @@ public class Constants {
public static final String MAPPINGS_FINAL = "mappingsFinal";
public static final String LOADER_DEPENDENCIES = "loaderLibraries";
public static final String LOOM_DEVELOPMENT_DEPENDENCIES = "loomDevelopmentDependencies";
@Deprecated // Not to be used in gradle 7+
public static final String COMPILE = "compile";
public static final String MAPPING_CONSTANTS = "mappingsConstants";
public static final String UNPICK_CLASSPATH = "unpick";

View File

@@ -31,8 +31,6 @@ import java.util.stream.Stream;
import groovy.util.Node;
import groovy.xml.QName;
import net.fabricmc.loom.util.gradle.GradleSupport;
public final class GroovyXmlUtil {
private GroovyXmlUtil() { }
@@ -66,18 +64,13 @@ public final class GroovyXmlUtil {
}
// New groovy 3 (gradle 7) class
if (GradleSupport.IS_GRADLE_7_OR_NEWER && nodeName.getClass().getName().equals("groovy.namespace.QName")) {
return isSameNameGroovy3(nodeName, givenName);
if (nodeName instanceof groovy.namespace.QName) {
return ((groovy.namespace.QName) nodeName).matches(givenName);
}
throw new UnsupportedOperationException("Cannot determine if " + nodeName.getClass() + " is the same as a String");
}
// TODO Move out of its own method when requiring gradle 7
private static boolean isSameNameGroovy3(Object nodeName, String givenName) {
return ((groovy.namespace.QName) nodeName).matches(givenName);
}
public static Stream<Node> childrenNodesStream(Node node) {
//noinspection unchecked
return (Stream<Node>) (Stream) (((List<Object>) node.children()).stream().filter((i) -> i instanceof Node));

View File

@@ -24,45 +24,12 @@
package net.fabricmc.loom.util.gradle;
import java.lang.reflect.Method;
import org.gradle.api.Project;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.util.GradleVersion;
// This is used to bridge the gap over large gradle api changes.
public class GradleSupport {
public static final boolean IS_GRADLE_7_OR_NEWER = isIsGradle7OrNewer();
public static RegularFileProperty getfileProperty(Project project) {
try {
// First try the new method, if that fails fall back.
return getfilePropertyModern(project);
} catch (Exception e) {
// Nope
}
try {
return getfilePropertyLegacy(project);
} catch (Exception e) {
throw new RuntimeException("Failed to find file property", e);
}
}
private static RegularFileProperty getfilePropertyModern(Project project) throws Exception {
return getfilePropertyLegacyFromObject(project.getObjects());
}
private static RegularFileProperty getfilePropertyLegacy(Project project) throws Exception {
return getfilePropertyLegacyFromObject(project.getLayout());
}
private static RegularFileProperty getfilePropertyLegacyFromObject(Object object) throws Exception {
Method method = object.getClass().getDeclaredMethod("fileProperty");
method.setAccessible(true);
return (RegularFileProperty) method.invoke(object);
}
public static boolean isIsGradle7OrNewer() {
String version = GradleVersion.current().getVersion();
return Integer.parseInt(version.substring(0, version.indexOf("."))) >= 7;