Skip to content

Commit

Permalink
MDG 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Jan 19, 2025
1 parent 560b0f5 commit a36cbb7
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 88 deletions.
164 changes: 95 additions & 69 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')
}

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 @@ -83,6 +82,7 @@ configurations {
extendConfigurations(compileOnly, apiCompileOnly, testCompileOnly)
extendConfigurations(runtimeOnly, apiRuntimeOnly)
extendConfigurations(localRuntime, apiLocalRuntime)
gameTestRuntimeClasspath.extendsFrom runtimeClasspath
datagenNonMod
}

Expand All @@ -96,7 +96,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 +154,13 @@ 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
neoForge.mods.maybeCreate(name).modSourceSets.add(extraSourceSet)
}
return extraSourceSet
}
Expand Down Expand Up @@ -197,7 +198,7 @@ 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,
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)
Expand Down Expand Up @@ -235,76 +236,99 @@ 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'))
}

modSources.add((SourceSet[]) [sourceSets.main, sourceSets.api])

for (String name : secondaryModules) {
modSources.add((SourceSet) sourceSets.named(name).get())
}
neoForge {
// This enables modding tasks and configurations
enable {
version = forge_version
enabledSourceSets = sourceSets // All source sets use Minecraft code
}

//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')
mods {
mekanism {
modSourceSets = [sourceSets.api, sourceSets.main, 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 {
modSourceSets = [sourceSets.gameTest]
}
}
server {
}
gameTestServer {
modSources.add((SourceSet) sourceSets.gameTest)
}
gameTestClient {
configure('client')
modSources.add((SourceSet) sourceSets.gameTest)
}
junit {
unitTestSources.add((SourceSet) sourceSets.test)
for (String name : secondaryModules) {
mods.maybeCreate(name).modSourceSets.add(sourceSets.named(name))
}
data {
programArguments.addAll((String[]) ['--all', '--output', file('src/datagen/generated/').absolutePath,
'--mod', 'mekanism', '--existing', file('src/main/resources/').absolutePath])

modSources.add((SourceSet) sourceSets.datagenMain)
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',
]

for (String name : secondaryModules) {
modSources.add(getExtraSourceSet(name, 'datagen').get())
programArguments.addAll((String[]) ['--mod', "mekanism${name}", '--existing', file("src/${name}/resources/").absolutePath])
}
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'))
}

loadedMods = [mods.mekanism]
for (String name : secondaryModules) {
loadedMods.add(mods.named(name))
}

dependencies {
runtime(configurations.datagenNonMod)
//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')
}
}
//Note: To enable logging into the client account, set the enable_devlogin property to true in your gradle user home
client {
client()
devLogin = Boolean.valueOf(project.enable_devlogin)
}
clientAlt {
client()
// Force dev login to be disabled for this run to allow using a secondary username
devLogin = false
programArguments.addAll('--username', 'AltDev')
}
server {
server()
}
gameTestServer {
type = "gameTestServer"
sourceSet = sourceSets.gameTest
loadedMods = neoForge.mods
}
gameTestClient {
client()
sourceSet = sourceSets.gameTest
loadedMods = neoForge.mods
}
data {
data()
programArguments.addAll('--all', '--output', file('src/datagen/generated/').absolutePath,
'--mod', 'mekanism', '--existing', file('src/main/resources/').absolutePath)

sourceSet = sourceSets.datagenMain
loadedMods.add(mods.mekanism)

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

unitTest {
enable()
testedMod = mods.mekanism
}
}

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 +365,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').configure {
useJUnitPlatform()
}

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

compileOnly(project(':annotation-processor'))
localRuntime(project(':annotation-processor'))
annotationProcessor(project(':annotation-processor'))
Expand All @@ -360,7 +381,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 Expand Up @@ -422,6 +443,11 @@ dependencies {
//datagenMainRuntimeOnly("curse.maven:projecte-226410:${projecte_id}")

datagenNonMod("com.thiakil:yaml-ops:${yamlops_version}")

// Enable dev login in clientAlt run
if (enable_devlogin) {
runtimeOnly "net.covers1624:DevLogin:0.1.0.4"
}
}

def getManifestAttributes(String title) {
Expand Down
11 changes: 6 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 @@ -19,14 +18,16 @@ minecraft_version_range=[1.21.1]
# options are: alpha, beta, release
release_type=alpha

# Enable or disable the use of dev logon for the client run
enable_devlogin=false

#JUnit/Testing dependencies
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
neoForge.parchment.mappingsVersion=2024.06.23

#misc settings
# recipe viewer, currently accepts: jei, emi, hybrid
Expand Down
12 changes: 5 additions & 7 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@

pluginManagement {
repositories {
gradlePluginPortal()
maven {
name = "NeoForge"
url = "https://maven.neoforged.net/releases/"
}
plugins {
//https://projects.neoforged.net/neoforged/moddevgradle
id('net.neoforged.moddev') version('2.0.75')
}
}

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"
2 changes: 1 addition & 1 deletion src/main/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="mekanism"
version="${version}"
version="${file.jarVersion}"
displayName="Mekanism"
displayURL="https://aidancbrady.com/mekanism/"
authors="Aidancbrady, Thommy101, Thiakil, pupnewfster, dizzyd"
Expand Down
4 changes: 2 additions & 2 deletions src/tools/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="mekanismtools"
version="${version}"
version="${file.jarVersion}"
displayName="Mekanism: Tools"
displayURL="https://aidancbrady.com/mekanism/"
authors="Aidancbrady, Thommy101, Thiakil, pupnewfster, dizzyd"
Expand All @@ -16,6 +16,6 @@ license="MIT"
[[dependencies.mekanismtools]]
modId="mekanism"
type="required"
versionRange="[${version}]"
versionRange="[${file.jarVersion}]"
ordering="AFTER"
side="BOTH"

0 comments on commit a36cbb7

Please sign in to comment.