mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 21:05:58 -05:00
gradle 5.0 support, fix #38
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 (dependency.getName().equals("sponge-mixin") && dependency.getGroup().equals("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;
|
||||
|
||||
Reference in New Issue
Block a user