Update to Gradle 5.3, add dependencies transformation

Signed-off-by: shedaniel <daniel@shedaniel.me>
This commit is contained in:
shedaniel
2021-07-29 22:32:28 +08:00
parent d5324c2c14
commit e1f38b2c91
8 changed files with 60 additions and 13 deletions

View File

@@ -13,7 +13,7 @@ A [Gradle](https://gradle.org/) plugin to setup a deobfuscated development envir
* Designed to support modern versions of Minecraft (Tested with 1.14.4 and upwards)
* ~~Built in support for IntelliJ IDEA, Eclipse and Visual Studio Code to generate run configurations for Minecraft.~~
- Currently, only IntelliJ IDEA and Visual Studio Code work with Forge Loom.
* Loom targets a wide range of Gradle versions. _Tested with 4.9 up to 6.7_
* Loom targets a wide range of Gradle versions. _Tested with 5.3 up to 6.7_
* Supports the latest version of Java all the way down to Java 8
## Usage

Binary file not shown.

View File

@@ -1,6 +1,5 @@
#Mon Jun 24 11:09:08 BST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip

2
gradlew vendored
View File

@@ -28,7 +28,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$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"'
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

2
gradlew.bat vendored
View File

@@ -14,7 +14,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m"
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

View File

@@ -46,14 +46,22 @@ import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.codehaus.groovy.runtime.ExceptionUtils;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.artifacts.transform.InputArtifact;
import org.gradle.api.artifacts.transform.TransformAction;
import org.gradle.api.artifacts.transform.TransformOutputs;
import org.gradle.api.artifacts.transform.TransformParameters;
import org.gradle.api.artifacts.type.ArtifactTypeDefinition;
import org.gradle.api.attributes.Attribute;
import net.fabricmc.loom.configuration.DependencyProvider;
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
import net.fabricmc.loom.configuration.launch.LaunchProviderSettings;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.DependencyDownloader;
import net.fabricmc.loom.util.FileSystemUtil;
public class ForgeUserdevProvider extends DependencyProvider {
private File userdevJar;
@@ -65,6 +73,17 @@ public class ForgeUserdevProvider extends DependencyProvider {
@Override
public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws Exception {
Attribute<Boolean> transformed = Attribute.of("architectury-loom-forge-dependencies-transformed", Boolean.class);
getProject().getDependencies().registerTransform(RemoveNameProvider.class, spec -> {
spec.getFrom().attribute(transformed, false);
spec.getTo().attribute(transformed, true);
});
for (ArtifactTypeDefinition type : getProject().getDependencies().getArtifactTypes()) {
type.getAttributes().attribute(transformed, false);
}
userdevJar = new File(getExtension().getProjectPersistentCache(), "forge-" + dependency.getDependency().getVersion() + "-userdev.jar");
Path configJson = getExtension()
@@ -90,14 +109,21 @@ public class ForgeUserdevProvider extends DependencyProvider {
addDependency(json.get("universal").getAsString(), Constants.Configurations.FORGE_UNIVERSAL);
for (JsonElement lib : json.get("libraries").getAsJsonArray()) {
Dependency dep = null;
if (lib.getAsString().startsWith("org.spongepowered:mixin:")) {
if (getExtension().useFabricMixin) {
addDependency("net.fabricmc:sponge-mixin:0.8.2+build.24", Constants.Configurations.FORGE_DEPENDENCIES);
continue;
dep = addDependency("net.fabricmc:sponge-mixin:0.8.2+build.24", Constants.Configurations.FORGE_DEPENDENCIES);
}
}
addDependency(lib.getAsString(), Constants.Configurations.FORGE_DEPENDENCIES);
if (dep == null) {
dep = addDependency(lib.getAsString(), Constants.Configurations.FORGE_DEPENDENCIES);
}
((ModuleDependency) dep).attributes(attributes -> {
attributes.attribute(transformed, true);
});
}
// TODO: Read launch configs from the JSON too
@@ -135,6 +161,28 @@ public class ForgeUserdevProvider extends DependencyProvider {
}
}
public abstract static class RemoveNameProvider implements TransformAction<TransformParameters.None> {
@InputArtifact
public abstract File getInput();
@Override
public void transform(TransformOutputs outputs) {
try {
File input = getInput();
//architectury-loom-forge-dependencies-transformed
File output = outputs.file(input.getName() + "-alfd-transformed.jar");
Files.copy(input.toPath(), output.toPath(), StandardCopyOption.REPLACE_EXISTING);
try (FileSystemUtil.FileSystemDelegate fs = FileSystemUtil.getJarFileSystem(output, false)) {
Path path = fs.get().getPath("META-INF/services/cpw.mods.modlauncher.api.INameMappingService");
Files.deleteIfExists(path);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
public String processTemplates(String string) {
if (string.startsWith("{")) {
String key = string.substring(1, string.length() - 1);
@@ -157,7 +205,7 @@ public class ForgeUserdevProvider extends DependencyProvider {
.collect(Collectors.joining("\n")).getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException e) {
ExceptionUtils.sneakyThrow(e);
throw new RuntimeException(e);
}
string = path.toAbsolutePath().toString();
@@ -170,7 +218,7 @@ public class ForgeUserdevProvider extends DependencyProvider {
.collect(Collectors.joining("\n")).getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException e) {
ExceptionUtils.sneakyThrow(e);
throw new RuntimeException(e);
}
string = path.toAbsolutePath().toString();

View File

@@ -30,7 +30,7 @@ import spock.lang.Unroll
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
// This test uses gradle 4.9 and 1.14.4 v1 mappings
// This test uses gradle 5.3 and 1.14.4 v1 mappings
class LegacyProjectTest extends Specification implements ProjectTestTrait {
@Override
String name() {

View File

@@ -28,7 +28,7 @@ import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
trait ProjectTestTrait {
final static String LEGACY_GRADLE = "4.9"
final static String LEGACY_GRADLE = "5.3"
final static String DEFAULT_GRADLE = "6.8.3"
final static String PRE_RELEASE_GRADLE = "7.0"