Skip to content

Commit

Permalink
Fix duplicate mod errors in modern java run configs and replace the i…
Browse files Browse the repository at this point in the history
…c2 maven with cursemaven for more reliability (#13)

* Reorganize run*17/21 classpath to avoid duplicate mod conflicts for GTNHLib/Hodgepodge

* Update Hodgepodge, lwjgl3ify, unimixins, gradle

* Replace player maven with cursemaven ic2
  • Loading branch information
eigenraven authored Apr 5, 2024
1 parent 65eb018 commit 396274c
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 54 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {
annotationProcessor("net.java.dev.jna:jna-platform:5.13.0")

// All these plugins will be present in the classpath of the project using our plugin, but not activated until explicitly applied
api(pluginDep("com.gtnewhorizons.retrofuturagradle","1.3.33"))
api(pluginDep("com.gtnewhorizons.retrofuturagradle","1.3.34"))

// Settings plugins
api(pluginDep("com.diffplug.blowdryerSetup", "1.7.1"))
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,22 @@ Enables using modern Java syntax (up to version 17) via Jabel, while still targe
preferPopulated = true,
required = false,
docComment = """
Adds the GTNH maven, CurseMaven, IC2/Player maven, and some more well-known 1.7.10 repositories.
Adds the GTNH maven, CurseMaven, Modrinth, and some more well-known 1.7.10 repositories.
""")
public boolean includeWellKnownRepositories = true;

/** See annotation */
@Prop(
name = "useIC2FromCurseforge",
isSettings = false,
preferPopulated = false,
required = false,
hidden = true,
docComment = """
Adds a dependency override rule to use RFG-deobfuscated https://www.curseforge.com/minecraft/mc-mods/industrial-craft/files/2353971 instead of net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev
""")
public boolean useIC2FromCurseforge = true;

/** See annotation */
@Prop(
name = "usesMavenPublishing",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ public class UpdateableConstants {
/** Latest Gradle version to update to. */
// https://github.com/gradle/gradle/releases
@SuppressWarnings("unused") // Used via reflection
public static final @NotNull String NEWEST_GRADLE_VERSION = "8.6";
public static final @NotNull String NEWEST_GRADLE_VERSION = "8.7";

/** Latest tag of ExampleMod with blowdryer settings */
// https://github.com/GTNewHorizons/ExampleMod1.7.10/releases
public static final @NotNull String NEWEST_BLOWDRYER_TAG = "0.2.2";

/** Latest version of UniMixins */
public static final String NEWEST_UNIMIXINS = "io.github.legacymoddingmc:unimixins:0.1.16";
public static final String NEWEST_UNIMIXINS = "io.github.legacymoddingmc:unimixins:0.1.17";

/** Latest version of Jabel for modern Java support */
public static final @NotNull String NEWEST_JABEL = "com.github.bsideup.jabel:jabel-javac-plugin:1.0.1";
Expand All @@ -26,10 +26,10 @@ public class UpdateableConstants {
public static final @NotNull String NEWEST_GTNH_LIB = "com.github.GTNewHorizons:GTNHLib:0.2.10";
/** Latest version of GTNHLib for modern Java support */
// https://github.com/GTNewHorizons/lwjgl3ify/releases
public static final @NotNull String NEWEST_LWJGL3IFY = "com.github.GTNewHorizons:lwjgl3ify:2.0.0";
public static final @NotNull String NEWEST_LWJGL3IFY = "com.github.GTNewHorizons:lwjgl3ify:2.0.2";
/** Latest version of GTNHLib for modern Java support */
// https://github.com/GTNewHorizons/Hodgepodge/releases
public static final @NotNull String NEWEST_HODGEPODGE = "com.github.GTNewHorizons:Hodgepodge:2.4.35";
public static final @NotNull String NEWEST_HODGEPODGE = "com.github.GTNewHorizons:Hodgepodge:2.4.40";
/** Latest version of LWJGL3 for modern Java support */
// https://github.com/LWJGL/lwjgl3/releases - but check what latest Minecraft uses too
public static final @NotNull String NEWEST_LWJGL3 = "3.3.2";
Expand All @@ -47,4 +47,7 @@ public class UpdateableConstants {
/** Specifier for the latest GTNHGradle version to update to */
// Only update once a new major change is made, ensure a backport to the previous major's updater is released first.
public static final @NotNull String NEWEST_GTNHGRADLE_SPEC = "com.gtnewhorizons:gtnhgradle:1.+";

/** Latest Industrial Craft 2 version */
public static final @NotNull String NEWEST_IC2_SPEC = "curse.maven:ic2-242638:2353971";
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project
if (!gtnh.configuration.modId.equals("hodgepodge")) {
deps.add(java17DependenciesCfg.getName(), UpdateableConstants.NEWEST_HODGEPODGE);
}
deps.getConstraints()
.add(java17DependenciesCfg.getName(), UpdateableConstants.NEWEST_UNIMIXINS)
.because("Use latest UniMixins known to GTNHGradle.");

final List<String> java17JvmArgs = new ArrayList<>(Arrays.asList(JAVA_17_ARGS));
final List<String> hotswapJvmArgs = new ArrayList<>(Arrays.asList(HOTSWAP_JVM_ARGS));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gtnewhorizons.gtnhgradle.modules;

import com.gtnewhorizons.retrofuturagradle.modutils.ModUtils;
import com.gtnewhorizons.retrofuturagradle.shadow.com.google.common.collect.ImmutableMap;
import com.gtnewhorizons.retrofuturagradle.shadow.com.google.common.collect.ImmutableSet;
import com.gtnewhorizons.gtnhgradle.GTNHConstants;
Expand All @@ -15,6 +16,7 @@
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.artifacts.DependencySubstitutions;
import org.gradle.api.artifacts.ExternalModuleDependency;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.artifacts.ModuleVersionSelector;
Expand Down Expand Up @@ -218,6 +220,8 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project
.getByType(MinecraftExtension.class);
final MCPTasks mcpTasks = project.getExtensions()
.getByType(MCPTasks.class);
final ModUtils modUtils = project.getExtensions()
.getByType(ModUtils.class);

// Tag injection
if (!gtnh.configuration.replaceGradleTokenInFile.isEmpty()) {
Expand Down Expand Up @@ -287,23 +291,37 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project
minecraft.getGroupsToExcludeFromAutoReobfMapping()
.addAll("com.diffplug", "com.diffplug.durian", "net.industrial-craft");

// Ensure IC2 gets deobfed by RFG
if (gtnh.configuration.useIC2FromCurseforge) {
modUtils.deobfuscate(UpdateableConstants.NEWEST_IC2_SPEC);
}

// Custom reobfuscation auto-mappings
project.getConfigurations()
.configureEach(c -> {
c.getDependencies()
.configureEach(dep -> {
if (dep instanceof ExternalModuleDependency mdep) {
if ("net.industrial-craft".equals(mdep.getGroup())
&& "industrialcraft-2".equals(mdep.getName())) {
// https://www.curseforge.com/minecraft/mc-mods/industrial-craft/files/2353971
project.getDependencies()
.add(
mcpTasks.getReobfJarConfiguration()
.getName(),
"curse.maven:ic2-242638:2353971");
if (gtnh.configuration.useIC2FromCurseforge) {
final DependencySubstitutions ds = c.getResolutionStrategy()
.getDependencySubstitution();
ds.substitute(ds.module("net.industrial-craft:industrialcraft-2:2.2.828-experimental"))
.using(ds.module(UpdateableConstants.NEWEST_IC2_SPEC))
.withoutClassifier()
.because("Use a much more reliable Maven repository for IC2");
} else {
c.getDependencies()
.configureEach(dep -> {
if (dep instanceof ExternalModuleDependency mdep) {
if ("net.industrial-craft".equals(mdep.getGroup())
&& "industrialcraft-2".equals(mdep.getName())) {
// https://www.curseforge.com/minecraft/mc-mods/industrial-craft/files/2353971
project.getDependencies()
.add(
mcpTasks.getReobfJarConfiguration()
.getName(),
UpdateableConstants.NEWEST_IC2_SPEC);
}
}
}
});
});
}
final ObfuscationAttribute obfuscationAttr = c.getAttributes()
.getAttribute(ObfuscationAttribute.OBFUSCATION_ATTRIBUTE);
if (obfuscationAttr == null || !obfuscationAttr.getName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project
}));
ec.filter(f -> { f.includeGroup("maven.modrinth"); });
});
repos.maven(mvn -> {
mvn.setName("ic2");
mvn.setUrl(
modUtils.getLiveMirrorURL(10_000, "https://maven2.ic2.player.to/", "https://maven.ic2.player.to/"));
mvn.mavenContent(c -> { c.includeGroup("net.industrial-craft"); });
mvn.getMetadataSources()
.artifact();
mvn.getMetadataSources()
.mavenPom();
});
// MMD maven often goes down with a broken certificate
project.afterEvaluate(p -> {
repos.maven(mvn -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,16 @@ public void setup(Project project, GTNHGradlePlugin.GTNHExtension gtnh) {
enable -> enable ? (List<String>) project.property("hotswapJvmArgs") : Collections.emptyList()));

this.classpath(project.property("java17PatchDependenciesCfg"));
if (side == Distribution.CLIENT) {
this.classpath(mcTasks.getLwjgl3Configuration());
}
// Use a raw provider instead of map to not create a dependency on the task
this.classpath(mcpTasks.getTaskPackageMcLauncher());
this.classpath(mcpTasks.getTaskPackagePatchedMc());
this.classpath(mcpTasks.getPatchedConfiguration());
this.classpath(
project.provider(
() -> project.getTasks()
.named(superTask, RunMinecraftTask.class)
.get()
.getClasspath()));
project.getTasks()
.named("jar"));
this.classpath(project.property("java17DependenciesCfg"));

super.setup(project);

this.setClasspath(
this.getClasspath()
.filter(
file -> !file.getPath()
.contains("2.9.4-nightly-20150209")));

dependsOn(
mcpTasks.getLauncherSources()
.getClassesTaskName(),
Expand Down

0 comments on commit 396274c

Please sign in to comment.