gradle 5.0 support, fix #38

dev/0.11
Adrian Siekierka 2018-12-30 12:03:25 +01:00
parent da03fd2827
commit 6a77b5deaa
5 changed files with 86 additions and 16 deletions

View File

@ -38,6 +38,7 @@ import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.UnknownTaskException;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginConvention;
@ -235,6 +236,10 @@ public class AbstractPlugin implements Plugin<Project> {
SetupIntelijRunConfigs.setup(project1);
}
// add dependencies for mixin annotation processor
DependencyHandler handler = project1.getDependencies();
handler.add("annotationProcessor", "net.fabricmc:sponge-mixin:" + extension.getMixinVersion());
handler.add("annotationProcessor", "net.fabricmc:fabric-loom:" + extension.getLoomVersion());
// Enables the default mod remapper
if (extension.remapMod) {

View File

@ -31,14 +31,14 @@ import net.fabricmc.loom.providers.MinecraftProvider;
import net.fabricmc.loom.util.LoomDependencyManager;
import org.cadixdev.lorenz.MappingSet;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.artifacts.Dependency;
import javax.annotation.Nullable;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.function.BiPredicate;
import java.util.function.Supplier;
public class LoomGradleExtension {
@ -109,18 +109,85 @@ public class LoomGradleExtension {
}
@Nullable
public String getMixinVersion() {
for (Dependency dependency : project.getConfigurations().getByName("compile").getDependencies()) {
if (dependency.getName().equalsIgnoreCase("mixin") && dependency.getGroup().equals("org.spongepowered")) {
return dependency.getVersion();
private Dependency findDependency(Collection<String> configs, BiPredicate<String, String> groupNameFilter) {
for (String s : configs) {
for (Dependency dependency : project.getConfigurations().getByName(s).getDependencies()) {
if (groupNameFilter.test(dependency.getGroup(), dependency.getName())) {
return dependency;
}
}
}
if (dependency.getName().equals("sponge-mixin") && dependency.getGroup().equals("net.fabricmc")) {
return null;
}
@Nullable
private Dependency findBuildscriptDependency(BiPredicate<String, String> groupNameFilter) {
for (Configuration config : project.getBuildscript().getConfigurations().getAsMap().values()) {
for (Dependency dependency : config.getDependencies()) {
if (groupNameFilter.test(dependency.getGroup(), dependency.getName())) {
return dependency;
}
}
}
return null;
}
@Nullable
public String getLoomVersion() {
Dependency dependency = findBuildscriptDependency((group, name) -> {
if (name.equalsIgnoreCase("fabric-loom")) {
return group.equalsIgnoreCase("net.fabricmc");
}
if (name.equalsIgnoreCase("fabric-loom.gradle.plugin")) {
return group.equalsIgnoreCase("fabric-loom");
}
return false;
});
return dependency != null ? dependency.getVersion() : null;
}
@Nullable
private Dependency getMixinDependency() {
return findDependency(Collections.singletonList("compile"), (group, name) -> {
if (name.equalsIgnoreCase("mixin") && group.equalsIgnoreCase("org.spongepowered")) {
return true;
}
if (name.equalsIgnoreCase("sponge-mixin") && group.equalsIgnoreCase("net.fabricmc")) {
return true;
}
return false;
});
}
@Nullable
public String getMixinVersion() {
Dependency dependency = getMixinDependency();
if (dependency != null) {
return dependency.getVersion();
} else {
return null;
}
}
@Nullable
public String getMixinJsonVersion() {
Dependency dependency = getMixinDependency();
if (dependency != null) {
if (dependency.getGroup().equalsIgnoreCase("net.fabricmc")) {
if (Objects.requireNonNull(dependency.getVersion()).split("\\.").length >= 4) {
return dependency.getVersion().substring(0, dependency.getVersion().lastIndexOf('.')) + "-SNAPSHOT";
}
return dependency.getVersion();
}
return dependency.getVersion();
}
return null;

View File

@ -25,7 +25,6 @@
package net.fabricmc.loom.mixin;
import com.google.common.io.ByteStreams;
import com.strobel.collections.ImmutableList;
import org.spongepowered.asm.lib.ClassReader;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.mixin.MixinEnvironment;
@ -146,7 +145,7 @@ public class MixinServiceGradle implements IClassBytecodeProvider, IClassProvide
@Override
public Collection<String> getPlatformAgents() {
return ImmutableList.of("org.spongepowered.asm.launch.platform.MixinPlatformAgentDefault");
return Collections.singletonList("org.spongepowered.asm.launch.platform.MixinPlatformAgentDefault");
}
public byte[] getClassBytes(String name, String transformedName) throws IOException {

View File

@ -32,7 +32,6 @@ import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.TinyUtils;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Dependency;
import java.io.File;
import java.io.IOException;
@ -103,7 +102,7 @@ public class ModRemapper {
}
if (extension.refmapName != null && extension.refmapName.length() > 0) {
if (MixinRefmapHelper.addRefmapName(extension.refmapName, extension.getMixinVersion(), modJarOutput)) {
if (MixinRefmapHelper.addRefmapName(extension.refmapName, extension.getMixinJsonVersion(), modJarOutput)) {
project.getLogger().debug("Transformed mixin reference maps in output JAR!");
}
}

View File

@ -25,10 +25,10 @@
package net.fabricmc.loom.util;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.strobel.collections.ImmutableList;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MinecraftProvider;
import org.apache.commons.io.IOUtils;