Skip to content

Commit

Permalink
Switch from NeoGradle to MDG (#8125)
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte authored Jan 30, 2025
1 parent 8745710 commit 9495847
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 120 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,3 @@ jobs:
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{ matrix.language }}"
upload: false # disable the upload here - we will upload in a different action
output: sarif-results

- name: filter-sarif
uses: advanced-security/filter-sarif@v1
with:
# filter out NG generated MC sources
patterns: |
-build/tmp/.cache/**
-build/neoForm/**
input: sarif-results/${{ matrix.language }}.sarif
output: sarif-results/${{ matrix.language }}.sarif

- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: sarif-results/${{ matrix.language }}.sarif
2 changes: 1 addition & 1 deletion .github/workflows/gametests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
run: ./gradlew runGameTestServer

- name: Run Unit Tests with Gradle
run: ./gradlew testJunit
run: ./gradlew test
7 changes: 0 additions & 7 deletions .github/workflows/gradle-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ jobs:
with:
file: gradle.properties
all: true
- name: Cache NG outputs
uses: actions/cache@v4
with:
key: ${{ steps.gradle_props.outputs.minecraft_version }}-${{ steps.gradle_props.outputs.forge_version }}
path: |
build/neoForge
build/neoForm
- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@v3
- name: Setup Java
Expand Down
194 changes: 121 additions & 73 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ plugins {
id('eclipse')
id('idea')
id('maven-publish')
id('net.neoforged.gradle.userdev') version('7.0.154')//https://projects.neoforged.net/neoforged/neogradle
id('net.neoforged.moddev') version('2.0.75')//https://projects.neoforged.net/neoforged/moddevgradle
}

tasks.named('wrapper', Wrapper) {
Expand Down Expand Up @@ -71,7 +71,6 @@ sourceSets {
compileClasspath += api.output
}
gameTest {
runs.modIdentifier = 'mekanismtests'
compileClasspath += api.output
}
}
Expand All @@ -96,7 +95,6 @@ setupExtraSourceSets(sourceSets.gameTest, false)
// based on the primary added source set
for (String name : secondaryModules) {
def sourceSet = sourceSets.create(name)
sourceSet.runs.modIdentifier = name
sourceSet.resources {
//Add the generated module resources
srcDirs += ["src/datagen/generated/mekanism${name}"]
Expand Down Expand Up @@ -155,11 +153,12 @@ SourceSet setupExtraSourceSet(SourceSet baseSourceSet, String extra) {
extraSourceSet.resources.srcDirs = ["src/${extra}/${name}/resources"]
extraSourceSet.compileClasspath += project.sourceSets.api.output
extraSourceSet.compileClasspath += project.sourceSets.main.output
extraSourceSet.runtimeClasspath += project.sourceSets.main.runtimeClasspath
if (baseSourceSet != project.sourceSets.main) {
//If the base sourceSet is main it already is the extra source set and has a reference to the base one from before this if statement
extraSourceSet.compileClasspath += getExtraSourceSet(project.sourceSets.main, extra).get().output
extraSourceSet.compileClasspath += baseSourceSet.output
extraSourceSet.runs.modIdentifier = name
extraSourceSet.runtimeClasspath += baseSourceSet.runtimeClasspath
}
return extraSourceSet
}
Expand All @@ -170,10 +169,6 @@ static void extendConfigurations(Configuration base, Configuration... configurat
}
}

Provider<SourceSet> getExtraSourceSet(String base, String name) {
return project.sourceSets.named(base).flatMap(sourceSet -> getExtraSourceSet(sourceSet, name))
}

Provider<SourceSet> getExtraSourceSet(SourceSet base, String name) {
return project.sourceSets.named(base.getTaskName(name, null))
}
Expand All @@ -197,8 +192,8 @@ def setupTasks(SourceSet sourceSet) {
tasks.named(sourceSet.processResourcesTaskName, ProcessResources) {
setGroup('process resources')
duplicatesStrategy = DuplicatesStrategy.FAIL
var versionProperties = ['version': mod_version, 'mc_version': minecraft_version_range, 'forge_version': forge_version_range, 'loader_version': loader_version_range,
'jei_version': jei_version_range]
var versionProperties = ['file' : ['jarVersion': mod_version], 'mc_version': minecraft_version_range, 'forge_version': forge_version_range,
'loader_version': loader_version_range, 'jei_version': jei_version_range]
//Mark the properties as inputs so that when they change things update
inputs.properties(versionProperties)
filesMatching('META-INF/neoforge.mods.toml') { expand(versionProperties) }
Expand Down Expand Up @@ -235,76 +230,132 @@ java {
withSourcesJar()
}

minecraft.accessTransformers.files(
file('src/main/resources/META-INF/accesstransformer.cfg'),
file('src/additions/resources/META-INF/accesstransformer.cfg'),
//Dev time only ATs so the file name doesn't have to match accesstransformer.cfg
file('src/datagen/main/resources/META-INF/datagen_ats.cfg'),
file('src/gameTest/resources/META-INF/gametest_ats.cfg')
)

runs {
configureEach {
if (hasProperty('forge_force_ansi')) {
//Force ansi if declared as a gradle variable, as the auto detection doesn't detect IntelliJ properly
// or eclipse's plugin that adds support for ansi escape in console
systemProperties.put('terminal.ansi', (String) property('forge_force_ansi'))
}
final runsFolder = layout.projectDirectory.dir('runs')
final clientRunsFolder = runsFolder.dir('client')

modSources.add((SourceSet[]) [sourceSets.main, sourceSets.api])
neoForge {
// This enables modding tasks and configurations
enable {
version = forge_version
enabledSourceSets = sourceSets // All source sets use Minecraft code
}

for (String name : secondaryModules) {
modSources.add((SourceSet) sourceSets.named(name).get())
mods {
mekanism {
sourceSet((SourceSet) sourceSets.api)
sourceSet((SourceSet) sourceSets.main)
}

//if the selected toolchain is a JBR, enable DCEVM
if (javaToolchains.launcherFor(java.toolchain).map { it.metadata.vendor }.getOrElse('').contains('JetBrains')) {
jvmArguments.add('-XX:+AllowEnhancedClassRedefinition')
// contains main mod + its datagen code
mekanismData {
modSourceSets = mods.mekanism.modSourceSets
sourceSet((SourceSet) sourceSets.datagenMain)
}
}
//Note: To enable logging into the client account, set the neogradle.subsystems.devLogin.conventionForRun property to true in your gradle user home
// https://github.com/neoforged/NeoGradle?tab=readme-ov-file#per-run-configuration
client {
}
clientAlt {
configure('client')
//Force disable devLogin for clientAlt regardless of if it is enabled via gradle properties for the main gradle run
devLogin.enabled(false)
if (!(findProperty('neogradle.subsystems.devLogin.conventionForRun') ?: false)) {
//If the property is missing or set to false (so the normal runClient task would use Dev as the name),
// change the name of the alt client type so that it doesn't conflict with the main dev one
programArguments.addAll((String[]) ['--username', 'AltDev'])
mekanismtests {
sourceSet((SourceSet) sourceSets.gameTest)
}
}
server {
}
gameTestServer {
modSources.add((SourceSet) sourceSets.gameTest)
}
gameTestClient {
configure('client')
modSources.add((SourceSet) sourceSets.gameTest)
}
junit {
unitTestSources.add((SourceSet) sourceSets.test)
}
data {
programArguments.addAll((String[]) ['--all', '--output', file('src/datagen/generated/').absolutePath,
'--mod', 'mekanism', '--existing', file('src/main/resources/').absolutePath])
for (String name : secondaryModules) {
final sourceSet = sourceSets.named(name)
mods.maybeCreate(name).modSourceSets.add(sourceSet)
// Create a secondary mod group for the modules main code + its datagen code
final datagenMod = mods.maybeCreate(name + 'Data')
datagenMod.modSourceSets.add(sourceSet)
datagenMod.modSourceSets.add(sourceSet.flatMap(s -> getExtraSourceSet(s, 'datagen')))
}

accessTransformers = [
'src/main/resources/META-INF/accesstransformer.cfg',
'src/additions/resources/META-INF/accesstransformer.cfg',
//Dev time only ATs so the file name doesn't have to match accesstransformer.cfg
'src/datagen/main/resources/META-INF/datagen_ats.cfg',
'src/gameTest/resources/META-INF/gametest_ats.cfg',
]

modSources.add((SourceSet) sourceSets.datagenMain)
runs {
configureEach {
if (hasProperty('forge_force_ansi')) {
//Force ansi if declared as a gradle variable, as the auto detection doesn't detect IntelliJ properly
// or eclipse's plugin that adds support for ansi escape in console
systemProperties.put('terminal.ansi', (String) property('forge_force_ansi'))
}

for (String name : secondaryModules) {
modSources.add(getExtraSourceSet(name, 'datagen').get())
programArguments.addAll((String[]) ['--mod', "mekanism${name}", '--existing', file("src/${name}/resources/").absolutePath])
}
loadedMods = [mods.mekanism]
for (String name : secondaryModules) {
loadedMods.add(mods.named(name))
}
//if the selected toolchain is a JBR, enable DCEVM
if (javaToolchains.launcherFor(java.toolchain).map { it.metadata.vendor }.getOrElse('').contains('JetBrains')) {
jvmArguments.addAll('-XX:+IgnoreUnrecognizedVMOptions', '-XX:+AllowEnhancedClassRedefinition')
}

dependencies {
runtime(configurations.datagenNonMod)
// Uncomment this to get verbose debug logging
// logLevel = org.slf4j.event.Level.DEBUG
}
//Note: To enable logging into the client account, set the mc_devlogin property to true in your gradle user home
// You can also run gradlew runClient -Pmc_devlogin=true
client {
client()
gameDirectory.value(clientRunsFolder)
if (findProperty('mc_devlogin') ?: false) {
devLogin = true
}
}
clientAlt {
client()
gameDirectory.value(runsFolder.dir('clientAlt'))
// Force dev login to be disabled for this run to allow using a secondary username
devLogin = false
programArguments.addAll('--username', 'AltDev')
}
server {
server()
gameDirectory.value(runsFolder.dir('server'))
}
gameTestServer {
type = 'gameTestServer'
gameDirectory.value(runsFolder.dir('gameTestServer'))
sourceSet = sourceSets.gameTest
loadedMods.add(mods.mekanismtests)
}
gameTestClient {
client()
gameDirectory.value(clientRunsFolder)
if (findProperty('mc_devlogin') ?: false) {
devLogin = true
}
sourceSet = sourceSets.gameTest
loadedMods.add(mods.mekanismtests)
programArguments.addAll('--quickPlaySingleplayer', 'GameTestWorld')
}
data {
data()
gameDirectory.value(runsFolder.dir('data'))
programArguments.addAll('--all', '--output', file('src/datagen/generated/').absolutePath,
'--mod', 'mekanism', '--existing', file('src/main/resources/').absolutePath)

sourceSet = sourceSets.datagenMain
loadedMods = [mods.mekanismData]

for (String name : secondaryModules) {
//println("Adding $name")
loadedMods.add(mods.named(name + 'Data'))
programArguments.addAll('--mod', 'mekanism' + name, '--existing', file("src/${name}/resources/").absolutePath)
}
}
}

unitTest {
enable()
testedMod = mods.mekanism
loadedMods = runs.client.loadedMods
}
}

// Ensure any jar without the necessary FML manifest attributes gets picked up via legacy classpath.
// This configuration only exists after setting the neoForge version above.
//TODO: Remove all this datagenNonMod stuff once we add FMLModType to yaml-ops
configurations.dataAdditionalRuntimeClasspath.extendsFrom configurations.datagenNonMod

static void exclusiveRepo(RepositoryHandler handler, String url, String... groups) {
exclusiveRepo(handler, url, filter -> {
for (def group : groups) {
Expand Down Expand Up @@ -341,14 +392,11 @@ repositories { RepositoryHandler handler ->
exclusiveRepo(handler, 'https://maven.parchmentmc.org/', 'org.parchmentmc.data')
}

tasks.named('test') {
//Disable builtin test task as we use and build uses testJunit so there is no point in having it also attempt to run an empty test task
enabled = false
tasks.named('test', Test) {
useJUnitPlatform()
}

dependencies {
implementation("net.neoforged:neoforge:${forge_version}")

compileOnly(project(':annotation-processor'))
localRuntime(project(':annotation-processor'))
annotationProcessor(project(':annotation-processor'))
Expand All @@ -360,7 +408,7 @@ dependencies {
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junit_version}")
//We use https://github.com/jqwik-team/jqwik to allow for implementing property based testing
testImplementation("net.jqwik:jqwik:${jqwik_version}")

compileOnly("mezz.jei:jei-${minecraft_version}-neoforge-api:${jei_version}")
if (recipe_viewer == 'jei' || recipe_viewer == 'hybrid') {
localRuntime("mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}")
Expand Down
8 changes: 3 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx4G
org.gradle.configuration-cache=true

java_version=21
Expand All @@ -23,10 +22,9 @@ release_type=alpha
junit_version=5.11.0
jqwik_version=1.9.0

#NeoGradle Settings
neogradle.subsystems.parchment.minecraftVersion=1.21.1
neogradle.subsystems.parchment.mappingsVersion=2024.11.17
neogradle.subsystems.conventions.sourcesets.enabled=false
#Parchment Settings
neoForge.parchment.minecraftVersion=1.21.1
neoForge.parchment.mappingsVersion=2024.11.17

#misc settings
# recipe viewer, currently accepts: jei, emi, hybrid
Expand Down
11 changes: 1 addition & 10 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven {
name = "NeoForge"
url = "https://maven.neoforged.net/releases/"
}
}
}

plugins {
id('org.gradle.toolchains.foojay-resolver-convention') version('0.9.0')
}

include('annotation-processor')
include('annotation-processor')
4 changes: 2 additions & 2 deletions src/additions/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license="MIT"

[[mods]]
modId="mekanismadditions"
version="${version}"
version="${file.jarVersion}"
displayName="Mekanism: Additions"
displayURL="https://aidancbrady.com/mekanism/"
authors="Aidancbrady, Thommy101, Thiakil, pupnewfster, dizzyd"
Expand All @@ -16,6 +16,6 @@ license="MIT"
[[dependencies.mekanismadditions]]
modId="mekanism"
type="required"
versionRange="[${version}]"
versionRange="[${file.jarVersion}]"
ordering="AFTER"
side="BOTH"
4 changes: 2 additions & 2 deletions src/generators/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license="MIT"

[[mods]]
modId="mekanismgenerators"
version="${version}"
version="${file.jarVersion}"
displayName="Mekanism: Generators"
displayURL="https://aidancbrady.com/mekanism/"
authors="Aidancbrady, Thommy101, Thiakil, pupnewfster, dizzyd"
Expand All @@ -16,6 +16,6 @@ license="MIT"
[[dependencies.mekanismgenerators]]
modId="mekanism"
type="required"
versionRange="[${version}]"
versionRange="[${file.jarVersion}]"
ordering="AFTER"
side="BOTH"
Loading

0 comments on commit 9495847

Please sign in to comment.