339 lines
12 KiB
Groovy
339 lines
12 KiB
Groovy
import groovy.json.JsonSlurper
|
|
import groovy.transform.EqualsAndHashCode
|
|
import groovy.transform.TupleConstructor
|
|
|
|
plugins {
|
|
id 'java-gradle-plugin'
|
|
id 'maven-publish'
|
|
id 'com.gradle.plugin-publish' version '1.2.1'
|
|
id 'com.gradleup.shadow' version '9.0.0-beta15'
|
|
}
|
|
|
|
// TauMC fork of neoforged/ModDevGradle. Upstream derives its version from git tags via the
|
|
// gradleutils plugin and publishes to the NeoForged maven; this fork sets the version by hand
|
|
// (see gradle.properties) and publishes to maven.taumc.org. The plugin ids are deliberately
|
|
// left alone so that consumers only have to add our repository and pin the version.
|
|
group = 'org.taumc'
|
|
base {
|
|
archivesName = "moddev-gradle"
|
|
}
|
|
version = mdg_version
|
|
logger.lifecycle("ModDevGradle version ${project.version}")
|
|
|
|
if (System.getenv('GPP_KEY')) {
|
|
project.ext {
|
|
set('gradle.publish.key', System.getenv('GPP_KEY'))
|
|
set('gradle.publish.secret', System.getenv('GPP_SECRET'))
|
|
}
|
|
}
|
|
|
|
repositories {
|
|
exclusiveContent {
|
|
forRepository {
|
|
maven {
|
|
name = "Fabric"
|
|
url = "https://maven.fabricmc.net/"
|
|
}
|
|
}
|
|
filter {
|
|
includeModule("net.fabricmc", "fabric-loom-native")
|
|
}
|
|
}
|
|
maven {
|
|
name = "NeoForged"
|
|
url = "https://maven.neoforged.net/releases"
|
|
content {
|
|
includeGroup "net.neoforged"
|
|
}
|
|
}
|
|
mavenCentral()
|
|
gradlePluginPortal()
|
|
}
|
|
|
|
sourceSets {
|
|
java8
|
|
main {
|
|
java {
|
|
srcDirs += project.file('src/generated/java')
|
|
}
|
|
compileClasspath += java8.output
|
|
runtimeClasspath += java8.output
|
|
}
|
|
legacy
|
|
test {
|
|
compileClasspath += legacy.output
|
|
runtimeClasspath += legacy.output
|
|
}
|
|
}
|
|
|
|
configurations {
|
|
// Configuration for all dependencies that we want shaded.
|
|
shaded
|
|
// Place shaded dependencies into `compileOnly` so that they do not leak into our publications' dependencies.
|
|
compileOnly.extendsFrom shaded
|
|
legacyCompileOnly.extendsFrom shaded
|
|
testCompileOnly.extendsFrom shaded
|
|
testRuntimeOnly.extendsFrom shaded
|
|
shadowRuntimeElements {
|
|
// `shadowRuntimeElements` is what gets published.
|
|
// We want it to contain the non-shaded runtime dependencies.
|
|
it.extendsFrom implementation, runtimeOnly
|
|
}
|
|
// Change the Category attribute so that includeBuilds don't select the default `runtimeElements` configuration.
|
|
// The Plugin Publish plugin already disables Maven publication of this configuration automatically.
|
|
runtimeElements {
|
|
attributes {
|
|
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, "not-wanted-publication"))
|
|
}
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
compileOnly gradleApi()
|
|
compileOnly "com.intellij:annotations:9.0.4"
|
|
testCompileOnly "com.intellij:annotations:9.0.4"
|
|
shaded "com.google.code.gson:gson:2.11.0"
|
|
implementation "gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext:1.2"
|
|
shaded "net.neoforged:EclipseLaunchConfigs:0.1.11"
|
|
shaded "net.neoforged:VscLaunchConfigs:1.0.8"
|
|
shaded("net.neoforged:JarJarMetadata:0.4.2") {
|
|
exclude group: 'org.slf4j'
|
|
}
|
|
shaded 'net.neoforged.installertools:problems-api:3.0.4'
|
|
|
|
java8CompileOnly gradleApi()
|
|
|
|
testImplementation(enforcedPlatform("org.junit:junit-bom:5.10.3"))
|
|
testImplementation 'org.junit.jupiter:junit-jupiter-api'
|
|
testImplementation 'org.junit.jupiter:junit-jupiter-params'
|
|
testImplementation 'org.assertj:assertj-core:3.26.0'
|
|
testImplementation gradleTestKit()
|
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
|
|
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
|
|
|
legacyImplementation(sourceSets.main.output)
|
|
legacyImplementation(sourceSets.java8.output)
|
|
legacyImplementation gradleApi()
|
|
}
|
|
|
|
java {
|
|
toolchain {
|
|
languageVersion = JavaLanguageVersion.of(17)
|
|
}
|
|
withSourcesJar()
|
|
}
|
|
|
|
jar {
|
|
archiveClassifier = 'slim'
|
|
from sourceSets.java8.output
|
|
from sourceSets.legacy.output
|
|
}
|
|
|
|
shadowJar {
|
|
archiveClassifier = "" // Required for the Plugin Publish Plugin to publish this jar
|
|
|
|
from sourceSets.java8.output
|
|
from sourceSets.legacy.output
|
|
|
|
configurations = [project.configurations.shaded]
|
|
enableRelocation = true
|
|
relocationPrefix = "net.neoforged.moddev.shadow"
|
|
}
|
|
|
|
assemble.dependsOn shadowJar
|
|
|
|
tasks.named("compileJava8Java").configure {
|
|
javaCompiler = javaToolchains.compilerFor {
|
|
languageVersion = JavaLanguageVersion.of(8)
|
|
}
|
|
}
|
|
|
|
javadoc {
|
|
options.addBooleanOption("Xdoclint:all,-missing", true)
|
|
}
|
|
|
|
// This is a shameless ripoff from Fabric Loom:
|
|
// https://github.com/FabricMC/fabric-loom/blob/dev/1.6/build.gradle
|
|
// Need to tweak this file to pretend we are compatible with j8 so the bootstrap will run.
|
|
tasks.withType(GenerateModuleMetadata).configureEach {
|
|
doLast {
|
|
def file = outputFile.get().asFile
|
|
|
|
def metadata = new groovy.json.JsonSlurper().parseText(file.text)
|
|
|
|
metadata.variants.each {
|
|
it.attributes["org.gradle.jvm.version"] = 8
|
|
}
|
|
|
|
file.text = groovy.json.JsonOutput.toJson(metadata)
|
|
}
|
|
}
|
|
|
|
gradlePlugin {
|
|
website = 'https://github.com/TauMC/ModDevGradle'
|
|
vcsUrl = 'https://github.com/TauMC/ModDevGradle.git'
|
|
|
|
plugins {
|
|
moddev {
|
|
id = 'org.taumc.moddev'
|
|
implementationClass = 'net.neoforged.moddevgradle.boot.ModDevPlugin'
|
|
displayName = "NeoForge Mod Development Plugin"
|
|
description = "This plugin helps you create Minecraft mods using the NeoForge platform"
|
|
tags = ["minecraft", "neoforge", "java", "mod"]
|
|
}
|
|
legacyforge {
|
|
id = 'org.taumc.moddev.legacyforge'
|
|
implementationClass = 'net.neoforged.moddevgradle.boot.LegacyForgeModDevPlugin'
|
|
displayName = "Mod Development Plugin for Legacy Forge"
|
|
description = "This plugin helps you create Minecraft mods using the Forge platform, up to 1.20.1"
|
|
tags = ["minecraft", "neoforge", "forge", "java", "mod"]
|
|
}
|
|
repositories {
|
|
id = 'org.taumc.moddev.repositories'
|
|
implementationClass = 'net.neoforged.moddevgradle.boot.RepositoriesPlugin'
|
|
displayName = "NeoForge Mod Development Repositories Plugin"
|
|
description = "This plugin adds the repositories needed for developing Minecraft mods. It is applied automatically by the moddev plugin, but can be applied manually in settings.gradle to make use of Gradle dependency management."
|
|
tags = ["minecraft", "neoforge", "java", "mod"]
|
|
}
|
|
legacyrepositories {
|
|
id = 'org.taumc.moddev.legacyforge.repositories'
|
|
implementationClass = 'net.neoforged.moddevgradle.boot.LegacyRepositoriesPlugin'
|
|
displayName = "Mod Development Repositories Plugin for Legacy Forge"
|
|
description = "This plugin adds the repositories needed for developing Minecraft mods using the Forge platform, up to 1.20.1. It is applied automatically by the legacyforge plugin, but can be applied manually in settings.gradle to make use of Gradle dependency management."
|
|
tags = ["minecraft", "neoforge", "forge", "java", "mod"]
|
|
}
|
|
}
|
|
}
|
|
|
|
test {
|
|
useJUnitPlatform()
|
|
}
|
|
|
|
publishing {
|
|
repositories {
|
|
maven {
|
|
name = 'taumcRepository'
|
|
url = uri('https://maven.taumc.org/releases')
|
|
credentials {
|
|
username = System.getenv('MAVEN_USERNAME')
|
|
password = System.getenv('MAVEN_SECRET')
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// By default, the testkit will use sourceSets.main.runtimeClasspath (= the configuration + the source set's outputs).
|
|
// That contains the non-shaded plugin classes, and does not contain our shaded dependencies!
|
|
// Instead, let's use the shadow jar and configurations.runtimeClasspath.
|
|
tasks.withType(PluginUnderTestMetadata).configureEach {
|
|
it.pluginClasspath.setFrom tasks.shadowJar, configurations.runtimeClasspath
|
|
it.inputs.file(shadowJar.archiveFile)
|
|
}
|
|
|
|
abstract class GenerateVersionOrder extends DefaultTask {
|
|
@OutputFile
|
|
abstract RegularFileProperty getOutput()
|
|
|
|
@TaskAction
|
|
void run() {
|
|
final json = new JsonSlurper()
|
|
final manifest = json.parse('https://piston-meta.mojang.com/mc/game/version_manifest_v2.json'.toURL())
|
|
List<String> versions = manifest.versions.collect { it.id }
|
|
|
|
Comparator<String> BY_LENGTH_REVERSED = Comparator.comparingInt { it.length() }.reversed()
|
|
var indicesByLength = versions.stream().sorted(BY_LENGTH_REVERSED).map(versions::indexOf).map(String::valueOf).toList()
|
|
|
|
// The special renovate-mc-version line contains the latest minecraft version with -snapshot turning into -alpha and -pre into -beta to satisfy snapshot<pre<rc (even though s>p>r). Renovate is configured to do the same replacement.
|
|
final clazz = """
|
|
package net.neoforged.moddevgradle.internal.generated;
|
|
|
|
import java.util.List;
|
|
|
|
public final class MinecraftVersionList {
|
|
private MinecraftVersionList() {
|
|
}
|
|
|
|
// renovate-mc-version: ${versions[0].replace('-snapshot-', '-alpha-').replace('-pre-', '-beta-')}
|
|
/**
|
|
* Released Minecraft Versions as of ${java.time.Instant.now()} from latest to oldest.
|
|
*/
|
|
public static final List<String> VERSIONS = List.of("${versions.join("\", \"")}");
|
|
|
|
// Indices into VERSIONS sorted by descending length of the version id
|
|
private static final int[] BY_LENGTH = {${indicesByLength.join(", ")}};
|
|
|
|
/**
|
|
* Finds the index of the longest matching prefix or -1 if none match.
|
|
* Prefix matches must terminate with one of the given separator characters to be found valid.
|
|
*/
|
|
public static int indexOfByPrefix(String version, String separators) {
|
|
for (var versionIdx : BY_LENGTH) {
|
|
var versionText = VERSIONS.get(versionIdx);
|
|
if (version.startsWith(versionText) && (versionText.length() == version.length() || separators.indexOf(version.charAt(versionText.length())) != -1)) {
|
|
return versionIdx;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
}
|
|
"""
|
|
output.get().asFile.write(clazz)
|
|
}
|
|
}
|
|
|
|
tasks.register('generateVersionOrder', GenerateVersionOrder) {
|
|
output = project.file('src/generated/java/net/neoforged/moddevgradle/internal/generated/MinecraftVersionList.java')
|
|
group = 'build'
|
|
description = "Generates a listing of known Minecraft versions for the purposes of Version comparison"
|
|
}
|
|
|
|
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"
|
|
}
|