diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 290de54..b8745e5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,7 +15,7 @@ jobs: uses: actions/setup-java@v4 with: distribution: 'temurin' - java-version: '21' + java-version: '25' - name: 'Build' run: | ./gradlew \ diff --git a/build.gradle b/build.gradle index 8c45cc2..5baf674 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'org.moddingx' -java.toolchain.languageVersion = JavaLanguageVersion.of(21) +java.toolchain.languageVersion = JavaLanguageVersion.of(25) repositories { mavenCentral() @@ -16,7 +16,7 @@ repositories { dependencies { api('jakarta.annotation:jakarta.annotation-api') { version { strictly '[3.0.0,)'; prefer '3.0.0' } } api('net.neoforged:srgutils') { version { strictly '[1.0.9,)'; prefer '1.0.9' } } - api('net.neoforged.gradle:userdev') { version { strictly "[7.0.180,8.0.0)"; prefer '7.0.180' } } + api('net.neoforged.gradle:userdev') { version { strictly "[7.1.16,8.0.0)"; prefer '7.1.16' } } api('org.moddingx:LauncherLib') { version { strictly '[2.1.0,2.2.0)'; prefer '2.1.0' } } api('com.google.code.gson:gson') { version { strictly '[2.12.1,)'; prefer '2.12.1' } } api('commons-io:commons-io') { version { strictly '[2.18.0,)'; prefer '2.18.0' } } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927..f8e1ee3 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9a0a0e2..6954be8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ 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-9.2.0-all.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787..adff685 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +82,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -114,7 +114,6 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -133,22 +132,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -165,7 +171,6 @@ fi # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) JAVACMD=$( cygpath --unix "$JAVACMD" ) @@ -193,18 +198,27 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd3..c4bdd3a 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,8 +13,10 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +27,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +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 @@ -56,32 +59,33 @@ 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 :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/src/main/java/org/moddingx/modgradle/plugins/meta/delegate/ModRunsConfig.java b/src/main/java/org/moddingx/modgradle/plugins/meta/delegate/ModRunsConfig.java index 6487cb3..e44dd62 100644 --- a/src/main/java/org/moddingx/modgradle/plugins/meta/delegate/ModRunsConfig.java +++ b/src/main/java/org/moddingx/modgradle/plugins/meta/delegate/ModRunsConfig.java @@ -3,6 +3,7 @@ import groovy.lang.Closure; import groovy.lang.DelegatesTo; import net.neoforged.gradle.dsl.common.runs.run.Run; +import org.gradle.api.Action; import java.util.ArrayList; import java.util.List; @@ -10,11 +11,11 @@ public class ModRunsConfig { public boolean autoConfig = true; - public List> client = new ArrayList<>(); - public List> server = new ArrayList<>(); - public List> clientData = new ArrayList<>(); - public List> serverData = new ArrayList<>(); - public List> gameTestServer = new ArrayList<>(); + public List> client = new ArrayList<>(); + public List> server = new ArrayList<>(); + public List> clientData = new ArrayList<>(); + public List> serverData = new ArrayList<>(); + public List> gameTestServer = new ArrayList<>(); public Delegate delegate() { return new Delegate(); @@ -26,7 +27,7 @@ public void noAutoConfig() { ModRunsConfig.this.autoConfig = false; } - public void all(@DelegatesTo(Run.class) Closure closure) { + public void all(@DelegatesTo(Run.class) Action closure) { ModRunsConfig.this.client.add(closure); ModRunsConfig.this.server.add(closure); ModRunsConfig.this.clientData.add(closure); @@ -34,28 +35,28 @@ public void all(@DelegatesTo(Run.class) Closure closure) { ModRunsConfig.this.gameTestServer.add(closure); } - public void client(@DelegatesTo(Run.class) Closure closure) { + public void client(@DelegatesTo(Run.class) Action closure) { ModRunsConfig.this.client.add(closure); } - public void server(@DelegatesTo(Run.class) Closure closure) { + public void server(@DelegatesTo(Run.class) Action closure) { ModRunsConfig.this.server.add(closure); } - public void data(@DelegatesTo(Run.class) Closure closure) { + public void data(@DelegatesTo(Run.class) Action closure) { ModRunsConfig.this.clientData.add(closure); ModRunsConfig.this.serverData.add(closure); } - public void clientData(@DelegatesTo(Run.class) Closure closure) { + public void clientData(@DelegatesTo(Run.class) Action closure) { ModRunsConfig.this.clientData.add(closure); } - public void serverData(@DelegatesTo(Run.class) Closure closure) { + public void serverData(@DelegatesTo(Run.class) Action closure) { ModRunsConfig.this.serverData.add(closure); } - public void gameTestServer(@DelegatesTo(Run.class) Closure closure) { + public void gameTestServer(@DelegatesTo(Run.class) Action closure) { ModRunsConfig.this.gameTestServer.add(closure); } } diff --git a/src/main/java/org/moddingx/modgradle/plugins/meta/setup/ModMappingsSetup.java b/src/main/java/org/moddingx/modgradle/plugins/meta/setup/ModMappingsSetup.java index 81c40b1..f00832d 100644 --- a/src/main/java/org/moddingx/modgradle/plugins/meta/setup/ModMappingsSetup.java +++ b/src/main/java/org/moddingx/modgradle/plugins/meta/setup/ModMappingsSetup.java @@ -26,7 +26,6 @@ public static void configureBuild(ModContext mod, ModMappingsConfig config) { Subsystems subsystems = mod.project().getExtensions().getByType(Subsystems.class); subsystems.parchment(parchment -> { if (parchmentConfig.artifact() != null) { - parchment.enabled(true); parchment.addRepository(true); parchment.parchmentArtifact(parchmentConfig.artifact().getDescriptor()); } else { @@ -34,7 +33,6 @@ public static void configureBuild(ModContext mod, ModMappingsConfig config) { String parchmentVersion = parchmentConfig.version(); if (parchmentVersion == null) parchmentVersion = latestParchmentVersion(mod.project(), minecraftVersion, parchmentConfig.minecraft() == null); if (parchmentVersion != null) { - parchment.enabled(true); parchment.addRepository(true); parchment.minecraftVersion(minecraftVersion); parchment.mappingsVersion(parchmentVersion); diff --git a/src/main/java/org/moddingx/modgradle/plugins/meta/setup/ModRunsSetup.java b/src/main/java/org/moddingx/modgradle/plugins/meta/setup/ModRunsSetup.java index 2a0a9af..dab3523 100644 --- a/src/main/java/org/moddingx/modgradle/plugins/meta/setup/ModRunsSetup.java +++ b/src/main/java/org/moddingx/modgradle/plugins/meta/setup/ModRunsSetup.java @@ -3,6 +3,7 @@ import groovy.lang.Closure; import net.neoforged.gradle.dsl.common.runs.run.Run; import net.neoforged.gradle.dsl.common.runs.run.RunManager; +import org.gradle.api.Action; import org.gradle.api.tasks.SourceSet; import org.moddingx.modgradle.plugins.meta.delegate.ModRunsConfig; import org.moddingx.modgradle.util.JavaGradlePluginUtils; @@ -25,7 +26,7 @@ public static void configureBuild(ModContext mod, ModRunsConfig config) { JavaGradlePluginUtils.getJavaSources(mod.project()).get().resources(dirs -> dirs.srcDir(mod.project().file("src/generated/resources"))); } - private static void configure(ModContext mod, Run run, boolean autoConfig, List> actions) { + private static void configure(ModContext mod, Run run, boolean autoConfig, List> actions) { if (autoConfig) { run.workingDirectory(mod.project().file("runs").toPath().resolve(run.getName()).toFile()); run.systemProperty("forge.logging.console.level", "debug"); @@ -46,7 +47,7 @@ private static void configure(ModContext mod, Run run, boolean autoConfig, List< ); } } - for (Closure action : actions) { + for (Action action : actions) { run.configure(action); } } diff --git a/src/main/java/org/moddingx/modgradle/util/ExecUtils.java b/src/main/java/org/moddingx/modgradle/util/ExecUtils.java new file mode 100644 index 0000000..c1ae2ba --- /dev/null +++ b/src/main/java/org/moddingx/modgradle/util/ExecUtils.java @@ -0,0 +1,20 @@ +package org.moddingx.modgradle.util; + +import org.gradle.api.Project; +import org.gradle.process.ExecOperations; + +import javax.inject.Inject; + +public class ExecUtils { + + private ExecUtils() {} + + public static ExecOperations execOps(Project project) { + return project.getObjects().newInstance(Services.class).getExec(); + } + + public static abstract class Services { + @Inject + protected abstract ExecOperations getExec(); + } +} diff --git a/src/main/java/org/moddingx/modgradle/util/GitChangelogGenerator.java b/src/main/java/org/moddingx/modgradle/util/GitChangelogGenerator.java index aa483b2..da260d6 100644 --- a/src/main/java/org/moddingx/modgradle/util/GitChangelogGenerator.java +++ b/src/main/java/org/moddingx/modgradle/util/GitChangelogGenerator.java @@ -18,7 +18,7 @@ public static String generateChangelog(Project project, @Nullable String commitF String commitRange = getCommitRange(project); errorDiagnostic.append(" commits=").append(commitRange); ByteArrayOutputStream output = new ByteArrayOutputStream(); - project.exec(spec -> { + ExecUtils.execOps(project).exec(spec -> { spec.commandLine("git", "log", logFormat, commitRange); spec.setStandardOutput(output); spec.setErrorOutput(System.err); @@ -58,7 +58,7 @@ private static String getCommitRange(Project project) throws IOException { // Git tag-based versioning: if a tag points to the HEAD commit, take all commits since the last tag. ByteArrayOutputStream currentTagOut = new ByteArrayOutputStream(); - ExecResult currentTagResult = project.exec(spec -> { + ExecResult currentTagResult = ExecUtils.execOps(project).exec(spec -> { spec.commandLine("git", "describe", "--tags", "--exact-match", "HEAD"); spec.setStandardOutput(currentTagOut); spec.setErrorOutput(NullOutputStream.nullOutputStream()); @@ -68,7 +68,7 @@ private static String getCommitRange(Project project) throws IOException { if (currentTagResult.getExitValue() == 0) { String currentTag = currentTagOut.toString(StandardCharsets.UTF_8).strip(); ByteArrayOutputStream lastTagOut = new ByteArrayOutputStream(); - ExecResult lastTagResult = project.exec(spec -> { + ExecResult lastTagResult = ExecUtils.execOps(project).exec(spec -> { spec.commandLine("git", "describe", "--tags", "--abbrev=0", "HEAD^"); spec.setStandardOutput(lastTagOut); spec.setErrorOutput(NullOutputStream.nullOutputStream()); diff --git a/src/main/java/org/moddingx/modgradle/util/GitTagVersionResolver.java b/src/main/java/org/moddingx/modgradle/util/GitTagVersionResolver.java index 000595a..4639a63 100644 --- a/src/main/java/org/moddingx/modgradle/util/GitTagVersionResolver.java +++ b/src/main/java/org/moddingx/modgradle/util/GitTagVersionResolver.java @@ -36,7 +36,7 @@ public static String getVersion(Project project, @Nullable String defaultVersion private static Optional getVersionFromDescribe(Project project) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); - ExecResult result = project.exec(spec -> { + ExecResult result = ExecUtils.execOps(project).exec(spec -> { spec.commandLine("git", "describe", "--tags", "--exact-match", "HEAD"); spec.setStandardOutput(output); spec.setErrorOutput(System.err); @@ -51,7 +51,7 @@ private static Optional getVersionFromDescribe(Project project) throws I private static Set listAllTags(Project project) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); - ExecResult result = project.exec(spec -> { + ExecResult result = ExecUtils.execOps(project).exec(spec -> { spec.commandLine("git", "tag", "--list"); spec.setStandardOutput(output); spec.setErrorOutput(System.err); diff --git a/src/main/java/org/moddingx/modgradle/util/GitTimestampUtils.java b/src/main/java/org/moddingx/modgradle/util/GitTimestampUtils.java index 60f7e9d..b09c139 100644 --- a/src/main/java/org/moddingx/modgradle/util/GitTimestampUtils.java +++ b/src/main/java/org/moddingx/modgradle/util/GitTimestampUtils.java @@ -16,7 +16,7 @@ public static String tryGetCommitTimestamp(Project project) { String commitEnv = System.getenv("GIT_COMMIT"); String ref = (commitEnv == null || commitEnv.isEmpty()) ? "HEAD" : commitEnv; ByteArrayOutputStream output = new ByteArrayOutputStream(); - ExecResult result = project.exec(spec -> { + ExecResult result = ExecUtils.execOps(project).exec(spec -> { spec.commandLine("git", "show", "-s", "--format=%cd", "--date=iso-strict", ref); spec.setStandardOutput(output); spec.setErrorOutput(System.err);