From d08ee39f1bb7368cafd02a6efb0fc57e755eab4c Mon Sep 17 00:00:00 2001 From: Su5eD Date: Sun, 28 Jan 2024 11:58:48 +0100 Subject: [PATCH] Improve testmods file format and resolution --- build.gradle.kts | 78 ++++++++++++++++++++++++++++++++---------------- testmods.txt | 4 --- testmods.yaml | 8 +++++ 3 files changed, 60 insertions(+), 30 deletions(-) delete mode 100644 testmods.txt create mode 100644 testmods.yaml diff --git a/build.gradle.kts b/build.gradle.kts index 4f8503f2..84dc700c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,15 +5,28 @@ import net.minecraftforge.gradle.common.util.MavenArtifactDownloader import net.minecraftforge.gradle.common.util.RunConfig import net.minecraftforge.gradle.userdev.tasks.JarJar import net.minecraftforge.gradle.userdev.util.MavenPomUtils -import net.minecraftforge.jarjar.metadata.* +import net.minecraftforge.jarjar.metadata.ContainedJarIdentifier +import net.minecraftforge.jarjar.metadata.ContainedJarMetadata +import net.minecraftforge.jarjar.metadata.ContainedVersion +import net.minecraftforge.jarjar.metadata.MetadataIOHandler import org.apache.maven.artifact.versioning.DefaultArtifactVersion import org.apache.maven.artifact.versioning.VersionRange +import org.yaml.snakeyaml.Yaml import java.nio.file.FileSystems import java.nio.file.Files import java.nio.file.StandardOpenOption import java.time.LocalDateTime import kotlin.io.path.inputStream +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath(group = "org.yaml", name = "snakeyaml", version = "2.2") + } +} + plugins { java `maven-publish` @@ -23,7 +36,6 @@ plugins { id("me.modmuss50.mod-publish-plugin") version "0.3.+" id("net.neoforged.gradleutils") version "2.0.+" id("org.parchmentmc.librarian.forgegradle") version "1.+" - id ("de.undercouch.download") version "5.5.0" } val versionConnector: String by project @@ -116,7 +128,7 @@ val modJar: JarJar by tasks.creating(JarJar::class) { false ) Files.deleteIfExists(metadataPath) - Files.write(metadataPath, MetadataIOHandler.toLines(metadata), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE) + Files.write(metadataPath, MetadataIOHandler.toLines(metadata), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE) } } manifest.attributes( @@ -284,6 +296,13 @@ repositories { name = "Su5eD" url = uri("https://maven.su5ed.dev/releases") } + exclusiveRepo("https://api.modrinth.com/maven/", "maven.modrinth") + maven { + url = uri("https://www.cursemaven.com") + content { + includeGroup("curse.maven") + } + } mavenLocal() } @@ -343,9 +362,20 @@ tasks { dependsOn("reobfModJar", fullJar) } - val modDownload = register("downloadMods") { - doLast { - downloadMods() + val modDownload = register("resolveTestMods") { + doFirst { + val configFile = rootProject.file("testmods.yaml") + val data: List> = configFile.reader().use(Yaml()::load) + val deps = data.map { project.dependencies.create(it["maven"] as String) } + + val config = configurations.detachedConfiguration(*deps.toTypedArray()) + val files = config.resolve() + + val dir = project.file("run/test/mods").apply { + if (exists()) deleteRecursively() + mkdirs() + } + files.forEach { it.copyTo(dir.resolve(it.name)) } } } @@ -369,26 +399,6 @@ tasks { } } -fun downloadMods() { - val dir = project.file("run/test/mods") - if (dir.exists()) { - dir.deleteRecursively() - } - dir.mkdirs() - - file("testmods.txt").forEachLine { - if (it.isBlank() || it.startsWith("#")) return@forEachLine - - val split = it.split(" ") - if (split.isEmpty()) return@forEachLine - - download.run { - dest(dir) - src(split[0]) - } - } -} - publishMods { file.set(fullJar.archiveFile) changelog.set(providers.environmentVariable("CHANGELOG").orElse("# $version")) @@ -452,3 +462,19 @@ publishing { } } } + +// Adapted from https://gist.github.com/pupnewfster/6c21401789ca6d74f9892be8c1c505c9 +fun RepositoryHandler.exclusiveRepo(location: String, vararg groups: String) { + exclusiveRepo(location) { + for (group in groups) { + includeGroup(group) + } + } +} + +fun RepositoryHandler.exclusiveRepo(location: String, config: Action) { + exclusiveContent { + forRepositories(maven(location), fg.repository) + filter(config) + } +} \ No newline at end of file diff --git a/testmods.txt b/testmods.txt deleted file mode 100644 index f67cbbf1..00000000 --- a/testmods.txt +++ /dev/null @@ -1,4 +0,0 @@ -https://cdn.modrinth.com/data/ZHKrK8Rp/versions/Q8JSGhdj/fastback-0.15.6%2B1.20.1-fabric.jar https://modrinth.com/mod/fastback - -# Requiring connector extras: -https://edge.forgecdn.net/files/4715/716/BeaconOverhaul-1.8.4+1.20.jar https://www.curseforge.com/minecraft/mc-mods/beaconoverhaul diff --git a/testmods.yaml b/testmods.yaml new file mode 100644 index 00000000..97a0fed5 --- /dev/null +++ b/testmods.yaml @@ -0,0 +1,8 @@ +- id: fastback + homepage: https://modrinth.com/mod/fastback + maven: maven.modrinth:fastback:0.15.6+1.20.1-fabric + +# Requiring connector extras: +- id: beaconoverhaul + homepage: https://www.curseforge.com/minecraft/mc-mods/beaconoverhaul + maven: curse.maven:beaconoverhaul-430382:4715716