Skip to content

Commit

Permalink
Configure Mojang repository to only include MC artiffacts
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Jun 15, 2024
1 parent 7a5aaee commit 4cfdf13
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 6 deletions.
56 changes: 56 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import groovy.json.JsonSlurper
import groovy.transform.EqualsAndHashCode
import groovy.transform.TupleConstructor

plugins {
id 'java-gradle-plugin'
id 'maven-publish'
Expand Down Expand Up @@ -54,6 +58,9 @@ repositories {
sourceSets {
java8
main {
java {
srcDirs += project.file('src/generated/java')
}
compileClasspath += java8.output
runtimeClasspath += java8.output
}
Expand Down Expand Up @@ -187,3 +194,52 @@ publishing {
tasks.withType(PluginUnderTestMetadata).configureEach {
it.pluginClasspath.from(sourceSets.java8.output.classesDirs)
}

abstract class GenerateRepoFilter extends DefaultTask {
@OutputFile
abstract RegularFileProperty getOutput()

@EqualsAndHashCode
@TupleConstructor
static class Artifact implements Comparable<Artifact> {
String group, module

@Override
int compareTo(Artifact o) {
final groups = this.group <=> o.group
if (groups) return groups
return this.module <=> o.module
}
}

@TaskAction
void run() {
final Set<Artifact> artifacts = []
final json = new JsonSlurper()
final manifest = json.parse('https://piston-meta.mojang.com/mc/game/version_manifest_v2.json'.toURL())
manifest.versions.each { ver ->
final version = json.parse((ver.url as String).toURL())
version.libraries.each { lib ->
final location = (lib.name as String).split(':', 3)
artifacts.add(new Artifact(location[0], location[1]))
}
}
final artifactList = artifacts.toList()
Collections.sort(artifactList)
final clazz = """
package net.neoforged.moddevgradle.internal.generated;
public class MojangRepositoryFilter {
public static void filter(org.gradle.api.artifacts.repositories.RepositoryContentDescriptor filter) {
${artifactList.collect { " filter.includeModule(\"${it.group}\", \"${it.module}\");" }.join('\n')}
}
}"""
output.get().asFile.write(clazz)
}
}

tasks.register('generateMojangRepositoryFilter', GenerateRepoFilter) {
output = project.file('src/generated/java/net/neoforged/moddevgradle/internal/generated/MojangRepositoryFilter.java')
group = 'build'
description = "Generates a repository filter for Mojang's libraries maven"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

package net.neoforged.moddevgradle.internal.generated;

public class MojangRepositoryFilter {
public static void filter(org.gradle.api.artifacts.repositories.RepositoryContentDescriptor filter) {
filter.includeModule("argo", "argo");
filter.includeModule("ca.weblite", "java-objc-bridge");
filter.includeModule("com.github.oshi", "oshi-core");
filter.includeModule("com.google.code.gson", "gson");
filter.includeModule("com.google.guava", "failureaccess");
filter.includeModule("com.google.guava", "guava");
filter.includeModule("com.ibm.icu", "icu4j");
filter.includeModule("com.ibm.icu", "icu4j-core-mojang");
filter.includeModule("com.mojang", "authlib");
filter.includeModule("com.mojang", "blocklist");
filter.includeModule("com.mojang", "brigadier");
filter.includeModule("com.mojang", "datafixerupper");
filter.includeModule("com.mojang", "javabridge");
filter.includeModule("com.mojang", "logging");
filter.includeModule("com.mojang", "netty");
filter.includeModule("com.mojang", "patchy");
filter.includeModule("com.mojang", "realms");
filter.includeModule("com.mojang", "text2speech");
filter.includeModule("com.paulscode", "codecjorbis");
filter.includeModule("com.paulscode", "codecwav");
filter.includeModule("com.paulscode", "libraryjavasound");
filter.includeModule("com.paulscode", "librarylwjglopenal");
filter.includeModule("com.paulscode", "soundsystem");
filter.includeModule("commons-codec", "commons-codec");
filter.includeModule("commons-io", "commons-io");
filter.includeModule("commons-logging", "commons-logging");
filter.includeModule("io.netty", "netty-all");
filter.includeModule("io.netty", "netty-buffer");
filter.includeModule("io.netty", "netty-codec");
filter.includeModule("io.netty", "netty-common");
filter.includeModule("io.netty", "netty-handler");
filter.includeModule("io.netty", "netty-resolver");
filter.includeModule("io.netty", "netty-transport");
filter.includeModule("io.netty", "netty-transport-classes-epoll");
filter.includeModule("io.netty", "netty-transport-native-epoll");
filter.includeModule("io.netty", "netty-transport-native-unix-common");
filter.includeModule("it.unimi.dsi", "fastutil");
filter.includeModule("java3d", "vecmath");
filter.includeModule("net.java.dev.jna", "jna");
filter.includeModule("net.java.dev.jna", "jna-platform");
filter.includeModule("net.java.dev.jna", "platform");
filter.includeModule("net.java.jinput", "jinput");
filter.includeModule("net.java.jinput", "jinput-platform");
filter.includeModule("net.java.jutils", "jutils");
filter.includeModule("net.minecraft", "launchwrapper");
filter.includeModule("net.sf.jopt-simple", "jopt-simple");
filter.includeModule("net.sf.trove4j", "trove4j");
filter.includeModule("org.apache.commons", "commons-compress");
filter.includeModule("org.apache.commons", "commons-lang3");
filter.includeModule("org.apache.httpcomponents", "httpclient");
filter.includeModule("org.apache.httpcomponents", "httpcore");
filter.includeModule("org.apache.logging.log4j", "log4j-api");
filter.includeModule("org.apache.logging.log4j", "log4j-core");
filter.includeModule("org.apache.logging.log4j", "log4j-slf4j18-impl");
filter.includeModule("org.apache.logging.log4j", "log4j-slf4j2-impl");
filter.includeModule("org.bouncycastle", "bcprov-jdk15on");
filter.includeModule("org.jcraft", "jorbis");
filter.includeModule("org.joml", "joml");
filter.includeModule("org.lwjgl", "lwjgl");
filter.includeModule("org.lwjgl", "lwjgl-freetype");
filter.includeModule("org.lwjgl", "lwjgl-glfw");
filter.includeModule("org.lwjgl", "lwjgl-jemalloc");
filter.includeModule("org.lwjgl", "lwjgl-openal");
filter.includeModule("org.lwjgl", "lwjgl-opengl");
filter.includeModule("org.lwjgl", "lwjgl-stb");
filter.includeModule("org.lwjgl", "lwjgl-tinyfd");
filter.includeModule("org.lwjgl.lwjgl", "lwjgl");
filter.includeModule("org.lwjgl.lwjgl", "lwjgl-platform");
filter.includeModule("org.lwjgl.lwjgl", "lwjgl_util");
filter.includeModule("org.lz4", "lz4-java");
filter.includeModule("org.ow2.asm", "asm-all");
filter.includeModule("org.slf4j", "slf4j-api");
filter.includeModule("oshi-project", "oshi-core");
filter.includeModule("tv.twitch", "twitch");
filter.includeModule("tv.twitch", "twitch-external-platform");
filter.includeModule("tv.twitch", "twitch-platform");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.neoforged.moddevgradle.dsl.InternalModelHelper;
import net.neoforged.moddevgradle.dsl.NeoForgeExtension;
import net.neoforged.moddevgradle.dsl.RunModel;
import net.neoforged.moddevgradle.internal.generated.MojangRepositoryFilter;
import net.neoforged.moddevgradle.internal.utils.ExtensionUtils;
import net.neoforged.moddevgradle.internal.utils.FileUtils;
import net.neoforged.moddevgradle.internal.utils.IdeDetection;
Expand Down Expand Up @@ -129,16 +130,13 @@ public void apply(Project project) {
});
}));

repositories.addLast(repositories.maven(repo -> {
repo.setName("NeoForged Releases");
repo.setUrl(URI.create("https://maven.neoforged.net/releases/"));
}));
repositories.addLast(repositories.maven(repo -> {
repositories.add(0, repositories.maven(repo -> {
repo.setName("Mojang Minecraft Libraries");
repo.setUrl(URI.create("https://libraries.minecraft.net/"));
repo.metadataSources(sources -> sources.mavenPom());
// TODO: Filter known groups that they ship and dont just run everything against it
repo.content(MojangRepositoryFilter::filter);
}));

repositories.maven(repo -> {
repo.setName("Mojang Meta");
repo.setUrl("https://maven.neoforged.net/mojang-meta/");
Expand All @@ -147,6 +145,10 @@ public void apply(Project project) {
content.includeModule("net.neoforged", "minecraft-dependencies");
});
});
repositories.addLast(repositories.maven(repo -> {
repo.setName("NeoForged Releases");
repo.setUrl(URI.create("https://maven.neoforged.net/releases/"));
}));

project.getDependencies().attributesSchema(attributesSchema -> {
attributesSchema.attribute(ATTRIBUTE_DISTRIBUTION).getDisambiguationRules().add(DistributionDisambiguation.class);
Expand Down

0 comments on commit 4cfdf13

Please sign in to comment.