Skip to content
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
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ dependencies {
compileOnlyApi libs.accesstransformers.gradle

// Utils
implementation libs.maven.artifact
implementation libs.bundles.utils
}

Expand Down Expand Up @@ -92,6 +93,7 @@ tasks.named('shadowJar', ShadowJar) {
archiveClassifier = null
relocationPrefix = 'net.minecraftforge.gradle.shadow'

minimize()
dependencies {
exclude dependency(projects.runtimeEnvironmentCheck)
exclude dependency(libs.annotations.jspecify)
Expand Down
5 changes: 4 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ gradle.beforeProject { Project project ->

//@formatter:off
dependencyResolutionManagement.versionCatalogs.register('libs') {
version 'gradleutils', '3.3.39'
version 'gradleutils', '3.3.40'

plugin 'licenser', 'net.minecraftforge.licenser' version '1.2.0' // https://plugins.gradle.org/plugin/net.minecraftforge.licenser
plugin 'gradleutils', 'net.minecraftforge.gradleutils' versionRef 'gradleutils'
Expand All @@ -49,6 +49,9 @@ dependencyResolutionManagement.versionCatalogs.register('libs') {
// https://plugins.gradle.org/plugin/net.minecraftforge.accesstransformers
library 'accesstransformers-gradle', 'net.minecraftforge.accesstransformers', 'net.minecraftforge.accesstransformers.gradle.plugin' version '5.0.1'

// Artifact Versioning
library 'maven-artifact', 'org.apache.maven', 'maven-artifact' version '3.9.11'

library 'utils-data', 'net.minecraftforge', 'json-data-utils' version '0.4.1' // https://files.minecraftforge.net/net/minecraftforge/json-data-utils/index.html
library 'utils-os', 'net.minecraftforge', 'os-utils' version '0.1.0' // https://files.minecraftforge.net/net/minecraftforge/os-utils/index.html
library 'utils-hash', 'net.minecraftforge', 'hash-utils' version '0.1.12' // https://files.minecraftforge.net/net/minecraftforge/hash-utils/index.html
Expand Down
33 changes: 32 additions & 1 deletion src/main/java/net/minecraftforge/gradle/MinecraftDependency.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@
*/
package net.minecraftforge.gradle;

import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import groovy.transform.stc.ClosureParams;
import groovy.transform.stc.FromString;
import net.minecraftforge.gradleutils.shared.Closures;
import org.gradle.api.Action;
import org.gradle.api.NamedDomainObjectContainer;

/// The Minecraft dependency contains information essential for how the
/// {@linkplain MinecraftExtensionForProject minecraft extension} processes Minecraft dependencies.
public interface MinecraftDependency extends MinecraftMappingsContainer { }
public interface MinecraftDependency extends MinecraftMappingsContainer {
/// The collection of Slime Launcher options with which to create the launcher tasks.
///
/// @return The collection of run task options
NamedDomainObjectContainer<? extends SlimeLauncherOptions> getRuns();

/// Configures the Slime Launcher options for this project, which will be used to create the launcher tasks.
///
/// @param closure The configuring closure
default void runs(
@DelegatesTo(NamedDomainObjectContainer.class)
@ClosureParams(value = FromString.class, options = "org.gradle.api.NamedDomainObjectContainer<net.minecraftforge.gradle.SlimeLauncherOptions>")
Closure<?> closure
) {
this.getRuns().configure(closure);
}

/// Configures the Slime Launcher options for this project, which will be used to create the launcher tasks.
///
/// @param action The configuring action
default void runs(Action<? super NamedDomainObjectContainer<? extends SlimeLauncherOptions>> action) {
this.runs(Closures.action(this, action));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ public interface MinecraftExtensionForProject<T extends ClosureOwner> extends Mi
/// Configures the Slime Launcher options for this project, which will be used to create the launcher tasks.
///
/// @param closure The configuring closure
void runs(
default void runs(
@DelegatesTo(NamedDomainObjectContainer.class)
@ClosureParams(value = FromString.class, options = "org.gradle.api.NamedDomainObjectContainer<net.minecraftforge.gradle.SlimeLauncherOptions>")
Closure<?> closure
);
) {
this.getRuns().configure(closure);
}

/// Configures the Slime Launcher options for this project, which will be used to create the launcher tasks.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import groovy.transform.NamedParams;
import net.minecraftforge.gradle.ClosureOwner;
import net.minecraftforge.gradle.MinecraftMappings;
import net.minecraftforge.gradle.SlimeLauncherOptions;
import org.gradle.api.Action;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.artifacts.DependencyArtifact;
import org.gradle.api.artifacts.ExcludeRule;
import org.gradle.api.artifacts.ExternalModuleDependency;
Expand Down Expand Up @@ -82,6 +84,11 @@ default void mappings(
this.getOwnerDelegate().mappings(namedArgs);
}

@Override
default NamedDomainObjectContainer<? extends SlimeLauncherOptions> getRuns() {
return this.getOwnerDelegate().getRuns();
}

@Override
default boolean isChanging() {
throw stub();
Expand Down Expand Up @@ -288,6 +295,11 @@ default void mappings(
this.getOwnerDelegate().mappings(namedArgs);
}

@Override
default NamedDomainObjectContainer<? extends SlimeLauncherOptions> getRuns() {
return this.getOwnerDelegate().getRuns();
}

@Override
default boolean isChanging() {
throw stub();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class Constants {
static final String SLIMELAUNCHER_MAIN = "net.minecraftforge.launcher.Main";

static final String MAVENIZER_NAME = "mavenizer";
static final String MAVENIZER_VERSION = "0.4.14";
static final String MAVENIZER_VERSION = "0.4.15";
static final String MAVENIZER_DL_URL = "https://maven.minecraftforge.net/net/minecraftforge/minecraft-mavenizer/" + MAVENIZER_VERSION + "/minecraft-mavenizer-" + MAVENIZER_VERSION + ".jar";
static final int MAVENIZER_JAVA_VERSION = 25;
static final String MAVENIZER_MAIN = "net.minecraftforge.mcmaven.cli.Main";
Expand Down
103 changes: 103 additions & 0 deletions src/main/java/net/minecraftforge/gradle/internal/ForgeAttributes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package net.minecraftforge.gradle.internal;

import net.minecraftforge.util.os.OS;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.gradle.api.Action;
import org.gradle.api.attributes.Attribute;
import org.gradle.api.attributes.AttributeDisambiguationRule;
import org.gradle.api.attributes.MultipleCandidatesDetails;
import org.gradle.api.provider.SetProperty;
import org.gradle.api.provider.ValueSource;
import org.gradle.api.provider.ValueSourceParameters;
import org.gradle.api.provider.ValueSourceSpec;
import org.jspecify.annotations.NullUnmarked;
import org.jspecify.annotations.Nullable;

import javax.inject.Inject;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.Set;

final class ForgeAttributes {
static final class OperatingSystem {
static final Attribute<String> ATTRIBUTE = Attribute.of("net.minecraftforge.native.operatingSystem", String.class);

static abstract class DisambiguationRule implements AttributeDisambiguationRule<String> {
private final OS current;

@Inject
public DisambiguationRule(OS current) {
this.current = current;
}

@Override
public void execute(MultipleCandidatesDetails<String> details) {
var options = details.getCandidateValues().stream().map(OS::byKey).toList();

if (options.contains(current)) {
details.closestMatch(current.key());
return;
}

for (var os : options) {
var fallback = execute(current, os);
if (fallback != null) {
details.closestMatch(fallback);
return;
}
}
}

@NullUnmarked
private String execute(OS current, OS os) {
return current == os
? os.key()
: os != null ? execute(current, os.fallback()) : null;
}
}

abstract static class CurrentValue implements ValueSource<OS, CurrentValue.Parameters> {
interface Parameters extends ValueSourceParameters {
Action<? super ValueSourceSpec<Parameters>> DEFAULT = spec -> spec.getParameters().getAllowedOperatingSystems().set(Set.of(OS.WINDOWS, OS.MACOS, OS.LINUX));

SetProperty<OS> getAllowedOperatingSystems();
}

@Inject
public CurrentValue() { }

@Override
public @Nullable OS obtain() {
var allowed = getParameters().getAllowedOperatingSystems().getOrElse(EnumSet.noneOf(OS.class)).toArray(new OS[0]);
return allowed.length > 0
? OS.current(allowed)
: OS.current();
}
}
}

static final class MappingsChannel {
static final Attribute<String> ATTRIBUTE = Attribute.of("net.minecraftforge.mappings.channel", String.class);

static abstract class DisambiguationRule implements AttributeDisambiguationRule<String> {
@Inject
public DisambiguationRule() { }

@Override
public void execute(MultipleCandidatesDetails<String> details) {
var options = details.getCandidateValues();
if (options.contains("official")) {
details.closestMatch("official");
} else if (options.contains("parchment")) {
details.closestMatch("parchment");
}
}
}
}

static final class MappingsVersion {
static final Attribute<String> ATTRIBUTE = Attribute.of("net.minecraftforge.mappings.version", String.class);

static final Comparator<String> COMPARATOR = Comparator.comparing(DefaultArtifactVersion::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ void mavenizerOutOfDate(boolean throwIt, Object dependency) {
this.report(name, displayName, problemSpec);
}

void reportCannotAccessSettingsRepos(Exception e) {
this.report("cannot-access-settings-repos", "Cannot access Settings repositories", spec -> spec
.details("""
ForgeGradle is unable to access the repositories defined by the Settings' dependency resolution management.
This is a ForgeGradle bug and needs to be reported to the ForgeGradle issue tracker on GitHub.""")
.severity(Severity.ERROR)
.withException(e)
.solution("For now, only declare repositories in the project.")
.solution(HELP_MESSAGE));
}

void reportMcMavenNotDeclared() {
if (!this.test("net.minecraftforge.gradle.warnings.repository.missing.mavenizer")) return;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.minecraftforge.gradle.internal;

import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import org.jspecify.annotations.Nullable;

import java.util.List;

record ForgeGradleSharedData(
@Nullable MinecraftMappingsImpl mappings
) {
static final String NAME = "__fg_shared_data";
}
Loading