Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Gradle 8.11 #1214

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
@SuppressWarnings("unused")
public class LoomGradlePluginBootstrap implements Plugin<PluginAware> {
private static final String MIN_SUPPORTED_GRADLE_VERSION = "8.10";
private static final String MIN_SUPPORTED_GRADLE_VERSION = "8.11";
private static final int MIN_SUPPORTED_MAJOR_JAVA_VERSION = 17;
private static final int MIN_SUPPORTED_MAJOR_IDEA_VERSION = 2022;

Expand Down
30 changes: 2 additions & 28 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,11 @@ plugins {
id 'groovy'
id 'checkstyle'
id 'codenarc'
alias(libs.plugins.kotlin) apply false // Delay this so we can perform magic 🪄 first.
alias(libs.plugins.kotlin)
alias(libs.plugins.spotless)
alias(libs.plugins.retry)
}

/**
* Haha this is fun :) The Kotlin gradle plugin triggers deprecation warnings for custom configurations (https://youtrack.jetbrains.com/issue/KT-60879)
* We need to make DefaultConfiguration.isSpecialCaseOfChangingUsage think that our configurstion is a special case and not deprecated.
* We do this by setting DefaultConfiguration.roleAtCreation to LEGACY, thus isInLegacyRole will now return true.
*
* Yeah I know we can just ignore the deprecation warning, but doing so wouldn't alert us to issues when testing against pre-release Gradle versions. Also this is more fun :)
*/
def brokenConfigurations = [
"commonDecompilerRuntimeClasspath",
"fernflowerRuntimeClasspath",
"cfrRuntimeClasspath",
"vineflowerRuntimeClasspath"
]

configurations.configureEach {
if (brokenConfigurations.contains(it.name)) {
// For some reason Gradle stops us from using Groovy magic to do this, so lets do it the boring way.
def field = org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.class.getDeclaredField("roleAtCreation")
field.setAccessible(true)
field.set(it, ConfigurationRoles.LEGACY)
}
}

// Ensure we apply the Kotlin plugin after, to allow for the above configuration to take place first
apply plugin: libs.plugins.kotlin.get().pluginId

tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
}
Expand All @@ -49,7 +23,7 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
}

group = 'net.fabricmc'
def baseVersion = '1.8'
def baseVersion = '1.9'

def ENV = System.getenv()
if (ENV.BUILD_NUMBER) {
Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ name = fabric-loom
description = The Gradle plugin for Fabric
url = https://github.com/FabricMC/fabric-loom

kotlin.stdlib.default.dependency = false
kotlin.stdlib.default.dependency = false
# Suppress a deprecation warning within the Kotlin Gradle plugin
kotlin.mpp.keepMppDependenciesIntactInPoms = true
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
kotlin = "1.9.24"
kotlin = "2.0.20"
asm = "9.7.1"
commons-io = "2.15.1"
gson = "2.10.1"
Expand Down
6 changes: 3 additions & 3 deletions gradle/test.libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
spock = "2.3-groovy-3.0"
junit = "5.11.1"
junit = "5.11.3"
javalin = "6.3.0"
mockito = "5.13.0"
mockito = "5.14.2"
java-debug = "0.52.0"
mixin = "0.15.3+mixin.0.8.7"

gradle-nightly = "8.12-20241009055624+0000"
gradle-nightly = "8.12-20241110002642+0000"
fabric-loader = "0.16.5"
fabric-installer = "1.0.1"

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ private static List<FabricModJson> getDependentMods(Project project, Map<String,
}

private static Stream<Project> getDependentProjects(Project project) {
final Stream<Project> runtimeProjects = getLoomProjectDependencies(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
final Stream<Project> compileProjects = getLoomProjectDependencies(project.getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME));
final Stream<Project> runtimeProjects = getLoomProjectDependencies(project, project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
final Stream<Project> compileProjects = getLoomProjectDependencies(project, project.getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME));

return Stream.concat(runtimeProjects, compileProjects)
.distinct();
Expand Down Expand Up @@ -154,19 +154,19 @@ private static Function<RemapConfigurationSettings, Stream<Path>> resolveArtifac

// Returns a list of Loom Projects found in both the runtime and compile classpath
private static Stream<Project> getCompileRuntimeProjectDependencies(Project project) {
final Stream<Project> runtimeProjects = getLoomProjectDependencies(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
final List<Project> compileProjects = getLoomProjectDependencies(project.getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME)).toList();
final Stream<Project> runtimeProjects = getLoomProjectDependencies(project, project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
final List<Project> compileProjects = getLoomProjectDependencies(project, project.getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME)).toList();

return runtimeProjects
.filter(compileProjects::contains); // Use the intersection of the two configurations.
}

// Returns a list of Loom Projects found in the provided Configuration
private static Stream<Project> getLoomProjectDependencies(Configuration configuration) {
private static Stream<Project> getLoomProjectDependencies(Project project, Configuration configuration) {
return configuration.getAllDependencies()
.withType(ProjectDependency.class)
.stream()
.map(GradleUtils::getDependencyProject)
.map((d) -> project.project(d.getPath()))
.filter(GradleUtils::isLoomProject);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ public AbstractRemapJarTask() {
usesService(jarManifestServiceProvider);
}

@Override
protected void copy() {
// Skip the default copy behaviour of AbstractCopyTask.
}

public final <P extends AbstractRemapParams> void submitWork(Class<? extends AbstractRemapAction<P>> workAction, Action<P> action) {
final WorkQueue workQueue = getWorkerExecutor().noIsolation();

Expand Down
37 changes: 0 additions & 37 deletions src/main/java/net/fabricmc/loom/util/gradle/GradleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,14 @@
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.internal.catalog.DelegatingProjectDependency;
import org.gradle.api.invocation.Gradle;
import org.gradle.api.provider.Provider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class GradleUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(GradleUtils.class);

private GradleUtils() {
}

Expand Down Expand Up @@ -96,33 +88,4 @@ public static File configurationInputFile(Project project, File file) {
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) {
if (projectDependency instanceof DefaultProjectDependency) {
try {
final Class<DefaultProjectDependency> clazz = DefaultProjectDependency.class;
final Field dependencyProject = clazz.getDeclaredField("dependencyProject");
dependencyProject.setAccessible(true);
return (Project) dependencyProject.get(projectDependency);
} catch (NoSuchFieldException | IllegalAccessException e) {
LOGGER.warn("Failed to reflect DefaultProjectDependency", e);
}
} else if (projectDependency instanceof DelegatingProjectDependency) {
try {
final Class<DelegatingProjectDependency> clazz = DelegatingProjectDependency.class;
final Field delgeate = clazz.getDeclaredField("delegate");
delgeate.setAccessible(true);
return getDependencyProject((ProjectDependency) delgeate.get(projectDependency));
} catch (NoSuchFieldException | IllegalAccessException e) {
LOGGER.warn("Failed to reflect DelegatingProjectDependency", e);
}
}

// Just fallback and trigger the warning, this will break in Gradle 9
final Project project = projectDependency.getDependencyProject();
LOGGER.warn("Loom was unable to suppress the deprecation warning for ProjectDependency#getDependencyProject, if you are on the latest version of Loom please report this issue to the Loom developers and provide the error above, this WILL stop working in a future Gradle version.");
return project;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.concurrent.atomic.AtomicBoolean;

import org.gradle.api.Transformer;
import org.gradle.process.internal.JvmOptions;
import org.gradle.workers.internal.DaemonForkOptions;
import org.gradle.workers.internal.WorkerDaemonClientsManager;

Expand Down Expand Up @@ -88,8 +87,11 @@ private static Map<String, Object> getSystemProperties(DaemonForkOptions forkOpt
try {
Method getJvmOptions = forkOptions.getClass().getDeclaredMethod("getJvmOptions");
getJvmOptions.setAccessible(true);
JvmOptions jvmOptions = (JvmOptions) getJvmOptions.invoke(forkOptions);
return jvmOptions.getMutableSystemProperties();
Object jvmOptions = getJvmOptions.invoke(forkOptions);
Method getMutableSystemProperties = jvmOptions.getClass().getDeclaredMethod("getMutableSystemProperties");
getMutableSystemProperties.setAccessible(true);
//noinspection unchecked
return (Map<String, Object>) getMutableSystemProperties.invoke(jvmOptions);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException("Failed to daemon system properties", e);
}
Expand Down
59 changes: 0 additions & 59 deletions src/test/groovy/net/fabricmc/loom/test/unit/GradleUtilsTest.groovy

This file was deleted.