@@ -20,7 +20,7 @@ plugins {
20
20
id(' eclipse' )
21
21
id(' idea' )
22
22
id(' maven-publish' )
23
- id(' net.neoforged.gradle.userdev ' ) version(' 7 .0.154 ' )// https://projects.neoforged.net/neoforged/neogradle
23
+ id(' net.neoforged.moddev ' ) version(' 2 .0.75 ' )// https://projects.neoforged.net/neoforged/moddevgradle
24
24
}
25
25
26
26
tasks. named(' wrapper' , Wrapper ) {
@@ -71,7 +71,6 @@ sourceSets {
71
71
compileClasspath + = api. output
72
72
}
73
73
gameTest {
74
- runs. modIdentifier = ' mekanismtests'
75
74
compileClasspath + = api. output
76
75
}
77
76
}
@@ -96,7 +95,6 @@ setupExtraSourceSets(sourceSets.gameTest, false)
96
95
// based on the primary added source set
97
96
for (String name : secondaryModules) {
98
97
def sourceSet = sourceSets. create(name)
99
- sourceSet. runs. modIdentifier = name
100
98
sourceSet. resources {
101
99
// Add the generated module resources
102
100
srcDirs + = [" src/datagen/generated/mekanism${ name} " ]
@@ -155,11 +153,12 @@ SourceSet setupExtraSourceSet(SourceSet baseSourceSet, String extra) {
155
153
extraSourceSet. resources. srcDirs = [" src/${ extra} /${ name} /resources" ]
156
154
extraSourceSet. compileClasspath + = project. sourceSets. api. output
157
155
extraSourceSet. compileClasspath + = project. sourceSets. main. output
156
+ extraSourceSet. runtimeClasspath + = project. sourceSets. main. runtimeClasspath
158
157
if (baseSourceSet != project. sourceSets. main) {
159
158
// 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
160
159
extraSourceSet. compileClasspath + = getExtraSourceSet(project. sourceSets. main, extra). get(). output
161
160
extraSourceSet. compileClasspath + = baseSourceSet. output
162
- extraSourceSet. runs . modIdentifier = name
161
+ extraSourceSet. runtimeClasspath + = baseSourceSet . runtimeClasspath
163
162
}
164
163
return extraSourceSet
165
164
}
@@ -170,10 +169,6 @@ static void extendConfigurations(Configuration base, Configuration... configurat
170
169
}
171
170
}
172
171
173
- Provider<SourceSet > getExtraSourceSet (String base , String name ) {
174
- return project. sourceSets. named(base). flatMap(sourceSet -> getExtraSourceSet(sourceSet, name))
175
- }
176
-
177
172
Provider<SourceSet > getExtraSourceSet (SourceSet base , String name ) {
178
173
return project. sourceSets. named(base. getTaskName(name, null ))
179
174
}
@@ -197,8 +192,8 @@ def setupTasks(SourceSet sourceSet) {
197
192
tasks. named(sourceSet. processResourcesTaskName, ProcessResources ) {
198
193
setGroup(' process resources' )
199
194
duplicatesStrategy = DuplicatesStrategy . FAIL
200
- var versionProperties = [' version ' : mod_version, ' mc_version' : minecraft_version_range, ' forge_version' : forge_version_range, ' loader_version ' : loader_version_range ,
201
- ' jei_version' : jei_version_range]
195
+ var versionProperties = [' file ' : [ ' jarVersion ' : mod_version] , ' mc_version' : minecraft_version_range, ' forge_version' : forge_version_range,
196
+ ' loader_version ' : loader_version_range, ' jei_version' : jei_version_range]
202
197
// Mark the properties as inputs so that when they change things update
203
198
inputs. properties(versionProperties)
204
199
filesMatching(' META-INF/neoforge.mods.toml' ) { expand(versionProperties) }
@@ -235,76 +230,132 @@ java {
235
230
withSourcesJar()
236
231
}
237
232
238
- minecraft. accessTransformers. files(
239
- file(' src/main/resources/META-INF/accesstransformer.cfg' ),
240
- file(' src/additions/resources/META-INF/accesstransformer.cfg' ),
241
- // Dev time only ATs so the file name doesn't have to match accesstransformer.cfg
242
- file(' src/datagen/main/resources/META-INF/datagen_ats.cfg' ),
243
- file(' src/gameTest/resources/META-INF/gametest_ats.cfg' )
244
- )
245
-
246
- runs {
247
- configureEach {
248
- if (hasProperty(' forge_force_ansi' )) {
249
- // Force ansi if declared as a gradle variable, as the auto detection doesn't detect IntelliJ properly
250
- // or eclipse's plugin that adds support for ansi escape in console
251
- systemProperties. put(' terminal.ansi' , (String ) property(' forge_force_ansi' ))
252
- }
233
+ final runsFolder = layout. projectDirectory. dir(' runs' )
234
+ final clientRunsFolder = runsFolder. dir(' client' )
253
235
254
- modSources. add((SourceSet []) [sourceSets. main, sourceSets. api])
236
+ neoForge {
237
+ // This enables modding tasks and configurations
238
+ enable {
239
+ version = forge_version
240
+ enabledSourceSets = sourceSets // All source sets use Minecraft code
241
+ }
255
242
256
- for (String name : secondaryModules) {
257
- modSources. add((SourceSet ) sourceSets. named(name). get())
243
+ mods {
244
+ mekanism {
245
+ sourceSet((SourceSet ) sourceSets. api)
246
+ sourceSet((SourceSet ) sourceSets. main)
258
247
}
259
-
260
- // if the selected toolchain is a JBR, enable DCEVM
261
- if (javaToolchains . launcherFor(java . toolchain) . map { it . metadata . vendor } . getOrElse( ' ' ) . contains( ' JetBrains ' )) {
262
- jvmArguments . add( ' -XX:+AllowEnhancedClassRedefinition ' )
248
+ // contains main mod + its datagen code
249
+ mekanismData {
250
+ modSourceSets = mods . mekanism . modSourceSets
251
+ sourceSet(( SourceSet ) sourceSets . datagenMain )
263
252
}
264
- }
265
- // Note: To enable logging into the client account, set the neogradle.subsystems.devLogin.conventionForRun property to true in your gradle user home
266
- // https://github.com/neoforged/NeoGradle?tab=readme-ov-file#per-run-configuration
267
- client {
268
- }
269
- clientAlt {
270
- configure(' client' )
271
- // Force disable devLogin for clientAlt regardless of if it is enabled via gradle properties for the main gradle run
272
- devLogin. enabled(false )
273
- if (! (findProperty(' neogradle.subsystems.devLogin.conventionForRun' ) ?: false )) {
274
- // If the property is missing or set to false (so the normal runClient task would use Dev as the name),
275
- // change the name of the alt client type so that it doesn't conflict with the main dev one
276
- programArguments. addAll((String []) [' --username' , ' AltDev' ])
253
+ mekanismtests {
254
+ sourceSet((SourceSet ) sourceSets. gameTest)
277
255
}
278
256
}
279
- server {
280
- }
281
- gameTestServer {
282
- modSources. add((SourceSet ) sourceSets. gameTest)
283
- }
284
- gameTestClient {
285
- configure(' client' )
286
- modSources. add((SourceSet ) sourceSets. gameTest)
287
- }
288
- junit {
289
- unitTestSources. add((SourceSet ) sourceSets. test)
290
- }
291
- data {
292
- programArguments. addAll((String []) [' --all' , ' --output' , file(' src/datagen/generated/' ). absolutePath,
293
- ' --mod' , ' mekanism' , ' --existing' , file(' src/main/resources/' ). absolutePath])
257
+ for (String name : secondaryModules) {
258
+ final sourceSet = sourceSets. named(name)
259
+ mods. maybeCreate(name). modSourceSets. add(sourceSet)
260
+ // Create a secondary mod group for the modules main code + its datagen code
261
+ final datagenMod = mods. maybeCreate(name + ' Data' )
262
+ datagenMod. modSourceSets. add(sourceSet)
263
+ datagenMod. modSourceSets. add(sourceSet. flatMap(s -> getExtraSourceSet(s, ' datagen' )))
264
+ }
265
+
266
+ accessTransformers = [
267
+ ' src/main/resources/META-INF/accesstransformer.cfg' ,
268
+ ' src/additions/resources/META-INF/accesstransformer.cfg' ,
269
+ // Dev time only ATs so the file name doesn't have to match accesstransformer.cfg
270
+ ' src/datagen/main/resources/META-INF/datagen_ats.cfg' ,
271
+ ' src/gameTest/resources/META-INF/gametest_ats.cfg' ,
272
+ ]
294
273
295
- modSources. add((SourceSet ) sourceSets. datagenMain)
274
+ runs {
275
+ configureEach {
276
+ if (hasProperty(' forge_force_ansi' )) {
277
+ // Force ansi if declared as a gradle variable, as the auto detection doesn't detect IntelliJ properly
278
+ // or eclipse's plugin that adds support for ansi escape in console
279
+ systemProperties. put(' terminal.ansi' , (String ) property(' forge_force_ansi' ))
280
+ }
296
281
297
- for (String name : secondaryModules) {
298
- modSources. add(getExtraSourceSet(name, ' datagen' ). get())
299
- programArguments. addAll((String []) [' --mod' , " mekanism${ name} " , ' --existing' , file(" src/${ name} /resources/" ). absolutePath])
300
- }
282
+ loadedMods = [mods. mekanism]
283
+ for (String name : secondaryModules) {
284
+ loadedMods. add(mods. named(name))
285
+ }
286
+ // if the selected toolchain is a JBR, enable DCEVM
287
+ if (javaToolchains. launcherFor(java. toolchain). map { it. metadata. vendor }. getOrElse(' ' ). contains(' JetBrains' )) {
288
+ jvmArguments. addAll(' -XX:+IgnoreUnrecognizedVMOptions' , ' -XX:+AllowEnhancedClassRedefinition' )
289
+ }
301
290
302
- dependencies {
303
- runtime(configurations. datagenNonMod)
291
+ // Uncomment this to get verbose debug logging
292
+ // logLevel = org.slf4j.event.Level.DEBUG
293
+ }
294
+ // Note: To enable logging into the client account, set the mc_devlogin property to true in your gradle user home
295
+ // You can also run gradlew runClient -Pmc_devlogin=true
296
+ client {
297
+ client()
298
+ gameDirectory. value(clientRunsFolder)
299
+ if (findProperty(' mc_devlogin' ) ?: false ) {
300
+ devLogin = true
301
+ }
302
+ }
303
+ clientAlt {
304
+ client()
305
+ gameDirectory. value(runsFolder. dir(' clientAlt' ))
306
+ // Force dev login to be disabled for this run to allow using a secondary username
307
+ devLogin = false
308
+ programArguments. addAll(' --username' , ' AltDev' )
309
+ }
310
+ server {
311
+ server()
312
+ gameDirectory. value(runsFolder. dir(' server' ))
313
+ }
314
+ gameTestServer {
315
+ type = ' gameTestServer'
316
+ gameDirectory. value(runsFolder. dir(' gameTestServer' ))
317
+ sourceSet = sourceSets. gameTest
318
+ loadedMods. add(mods. mekanismtests)
319
+ }
320
+ gameTestClient {
321
+ client()
322
+ gameDirectory. value(clientRunsFolder)
323
+ if (findProperty(' mc_devlogin' ) ?: false ) {
324
+ devLogin = true
325
+ }
326
+ sourceSet = sourceSets. gameTest
327
+ loadedMods. add(mods. mekanismtests)
328
+ programArguments. addAll(' --quickPlaySingleplayer' , ' GameTestWorld' )
304
329
}
330
+ data {
331
+ data()
332
+ gameDirectory. value(runsFolder. dir(' data' ))
333
+ programArguments. addAll(' --all' , ' --output' , file(' src/datagen/generated/' ). absolutePath,
334
+ ' --mod' , ' mekanism' , ' --existing' , file(' src/main/resources/' ). absolutePath)
335
+
336
+ sourceSet = sourceSets. datagenMain
337
+ loadedMods = [mods. mekanismData]
338
+
339
+ for (String name : secondaryModules) {
340
+ // println("Adding $name")
341
+ loadedMods. add(mods. named(name + ' Data' ))
342
+ programArguments. addAll(' --mod' , ' mekanism' + name, ' --existing' , file(" src/${ name} /resources/" ). absolutePath)
343
+ }
344
+ }
345
+ }
346
+
347
+ unitTest {
348
+ enable()
349
+ testedMod = mods. mekanism
350
+ loadedMods = runs. client. loadedMods
305
351
}
306
352
}
307
353
354
+ // Ensure any jar without the necessary FML manifest attributes gets picked up via legacy classpath.
355
+ // This configuration only exists after setting the neoForge version above.
356
+ // TODO: Remove all this datagenNonMod stuff once we add FMLModType to yaml-ops
357
+ configurations. dataAdditionalRuntimeClasspath. extendsFrom configurations. datagenNonMod
358
+
308
359
static void exclusiveRepo (RepositoryHandler handler , String url , String ... groups ) {
309
360
exclusiveRepo(handler, url, filter -> {
310
361
for (def group : groups) {
@@ -341,14 +392,11 @@ repositories { RepositoryHandler handler ->
341
392
exclusiveRepo(handler, ' https://maven.parchmentmc.org/' , ' org.parchmentmc.data' )
342
393
}
343
394
344
- tasks. named(' test' ) {
345
- // 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
346
- enabled = false
395
+ tasks. named(' test' , Test ) {
396
+ useJUnitPlatform()
347
397
}
348
398
349
399
dependencies {
350
- implementation(" net.neoforged:neoforge:${ forge_version} " )
351
-
352
400
compileOnly(project(' :annotation-processor' ))
353
401
localRuntime(project(' :annotation-processor' ))
354
402
annotationProcessor(project(' :annotation-processor' ))
@@ -360,7 +408,7 @@ dependencies {
360
408
testRuntimeOnly(" org.junit.jupiter:junit-jupiter-engine:${ junit_version} " )
361
409
// We use https://github.com/jqwik-team/jqwik to allow for implementing property based testing
362
410
testImplementation(" net.jqwik:jqwik:${ jqwik_version} " )
363
-
411
+
364
412
compileOnly(" mezz.jei:jei-${ minecraft_version} -neoforge-api:${ jei_version} " )
365
413
if (recipe_viewer == ' jei' || recipe_viewer == ' hybrid' ) {
366
414
localRuntime(" mezz.jei:jei-${ minecraft_version} -neoforge:${ jei_version} " )
0 commit comments