Skip to content

Commit

Permalink
MDG
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Jun 21, 2024
1 parent 95623a6 commit d118ee8
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 78 deletions.
153 changes: 87 additions & 66 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {
id('eclipse')
id('idea')
id('maven-publish')
id('net.neoforged.gradle.userdev') version('7.0.145')//https://projects.neoforged.net/neoforged/neogradle
id('net.neoforged.moddev')
}

tasks.named('wrapper', Wrapper).configure {
Expand Down Expand Up @@ -70,7 +70,6 @@ sourceSets {
compileClasspath += api.output
}
gameTest {
runs.modIdentifier = 'mekanismtests'
compileClasspath += api.output
}
}
Expand All @@ -82,6 +81,7 @@ configurations {
extendConfigurations(compileOnly, apiCompileOnly, testCompileOnly)
extendConfigurations(runtimeOnly, apiRuntimeOnly)
extendConfigurations(localRuntime, apiLocalRuntime)
gameTestRuntimeClasspath.extendsFrom runtimeClasspath
datagenNonMod
}

Expand All @@ -95,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 @@ -154,11 +153,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 @@ -234,76 +235,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])
neoForge {
version = forge_version

for (String name : secondaryModules) {
modSources.add((SourceSet) sourceSets.named(name).get())
mods {
mekanism {
modSourceSets = [sourceSets.api, sourceSets.main, sourceSets.datagenMain]
}

//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')
mekanismtests {
modSourceSets = [sourceSets.gameTest]
}
}
//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'])
}
}
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'))
}

mods.add(neoForge.mods.named("mekanism"))
for (String name : secondaryModules) {
mods.add(neoForge.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')) {
// TODO MDG jvmArguments.add('-XX:+AllowEnhancedClassRedefinition')
}
}
//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 {
client()
}
clientAlt {
client()
//Force disable devLogin for clientAlt regardless of if it is enabled via gradle properties for the main gradle run
// TODO MDG 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'])
}
}
server {
server()
}
gameTestServer {
type = "gameTestServer"
sourceSet = sourceSets.gameTest
mods = neoForge.mods
}
gameTestClient {
client()
sourceSet = sourceSets.gameTest
mods = neoForge.mods
}
data {
data()
programArguments.addAll((String[]) ['--all', '--output', file('src/datagen/generated/').absolutePath,
'--mod', 'mekanism', '--existing', file('src/main/resources/').absolutePath])

sourceSet = sourceSets.datagenMain
mods.add(neoForge.mods.named("mekanism"))

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

unitTest {
enable()
testedMod = mods.named("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,13 +365,10 @@ repositories { RepositoryHandler handler ->
}

tasks.named('test').configure {
//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)
useJUnitPlatform()
}

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

compileOnly(project(':annotation-processor'))
localRuntime(project(':annotation-processor'))
annotationProcessor(project(':annotation-processor'))
Expand Down
8 changes: 3 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# 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
org.gradle.configuration-cache=true

java_version=21
minecraft_version=1.21
Expand All @@ -24,9 +23,8 @@ junit_version=5.10.2
jqwik_version=1.8.5

#NeoGradle Settings
neogradle.subsystems.parchment.minecraftVersion=1.20.6
neogradle.subsystems.parchment.mappingsVersion=2024.06.02
neogradle.subsystems.conventions.sourcesets.enabled=false
neoForge.parchment.minecraftVersion=1.20.6
neoForge.parchment.mappingsVersion=2024.06.02

#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('0.1.100')
}
}

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

include('annotation-processor')
include('annotation-processor')

0 comments on commit d118ee8

Please sign in to comment.