Files
2026-07-31 10:46:40 +00:00

138 lines
4.3 KiB
Groovy

plugins {
id 'java-library'
id 'net.neoforged.moddev' version '2.0.143'
}
group = mod_group_id
version = mod_version
base { archivesName = mod_id }
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
repositories {
mavenCentral()
}
neoForge {
version = project.neo_version
// Expose the mojmapped, decompiled Minecraft sources so they can be grepped.
// `./gradlew createMinecraftArtifacts` produces them under build/ + the MDG cache.
accessTransformers.from('src/main/resources/META-INF/accesstransformer.cfg')
runs {
configureEach {
systemProperty 'forge.logging.markers', 'REGISTRIES'
logLevel = org.slf4j.event.Level.DEBUG
}
client {
client()
}
server {
server()
programArgument '--nogui'
}
}
mods {
"$mod_id" {
sourceSet sourceSets.main
}
}
}
// The end-to-end suite asserts on reports produced by a real dedicated server, so it is kept out of
// `check`: it downloads and installs NeoForge and takes minutes. Run it with `./gradlew e2eTest`.
sourceSets {
e2e {
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
}
}
configurations {
e2eImplementation.extendsFrom testImplementation
e2eRuntimeOnly.extendsFrom testRuntimeOnly
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.34'
annotationProcessor 'org.projectlombok:lombok:1.18.34'
testCompileOnly 'org.projectlombok:lombok:1.18.34'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.34'
testImplementation platform('org.junit:junit-bom:5.11.3')
testImplementation 'org.junit.jupiter:junit-jupiter'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testImplementation 'org.assertj:assertj-core:3.26.3'
// The analysis, report and origin packages are deliberately free of Minecraft types so they can be
// unit-tested without a game runtime. These two are the only libraries they touch, at the versions
// Minecraft 1.21.1 itself ships.
testImplementation 'it.unimi.dsi:fastutil:8.5.12'
testImplementation 'com.google.code.gson:gson:2.10.1'
}
// Interpolate mod metadata into neoforge.mods.toml
var generateModMetadata = tasks.register('generateModMetadata', ProcessResources) {
var replaceProperties = [
minecraft_version : minecraft_version,
neo_version : neo_version,
mod_id : mod_id,
mod_name : mod_name,
mod_license : mod_license,
mod_version : mod_version,
mod_authors : mod_authors,
mod_description : mod_description,
]
inputs.properties replaceProperties
expand replaceProperties
from 'src/main/templates'
into "$buildDir/generated/sources/modMetadata"
}
sourceSets.main.resources.srcDir generateModMetadata
neoForge.ideSyncTask generateModMetadata
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.release = 21
options.compilerArgs << '-Xlint:all,-processing,-serial'
}
tasks.named('test', Test) {
useJUnitPlatform()
testLogging {
events 'passed', 'skipped', 'failed'
exceptionFormat 'full'
showStandardStreams = false
}
}
var e2eRoot = layout.buildDirectory.dir('e2e')
var e2eServers = tasks.register('e2eServers', Exec) {
group = 'verification'
description = 'Installs a NeoForge dedicated server, runs the mod on it twice and keeps its reports.'
dependsOn tasks.named('jar')
workingDir projectDir
commandLine 'bash', 'e2e/run-servers.sh'
environment 'E2E_OUT', e2eRoot.get().asFile.absolutePath
outputs.upToDateWhen { false }
}
tasks.register('e2eTest', Test) {
group = 'verification'
description = 'Asserts on the reports the dedicated servers produced. Not part of `check`: it is slow.'
dependsOn e2eServers
testClassesDirs = sourceSets.e2e.output.classesDirs
classpath = sourceSets.e2e.runtimeClasspath
systemProperty 'e2e.root', e2eRoot.get().asFile.absolutePath
useJUnitPlatform()
testLogging {
events 'passed', 'skipped', 'failed'
exceptionFormat 'full'
}
outputs.upToDateWhen { false }
}