Skip to content

Commit 42cfe75

Browse files
authored
[1.20.1] Update to use new ModDevGradle LegacyForge plugin (#3)
1 parent a815189 commit 42cfe75

File tree

19 files changed

+259
-755
lines changed

19 files changed

+259
-755
lines changed

.run/RenderDoc.run.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

build.gradle.kts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
group = "dev.compactmachines"
2-
version = "20.1.0"
1+
plugins {
2+
id("org.jetbrains.gradle.plugin.idea-ext")
3+
}
4+
5+
idea.module.excludeDirs.addAll(files(
6+
".github",
7+
".gradle",
8+
".idea",
9+
"gradle",
10+
"libs"
11+
))

build.gradle.kts.old

Lines changed: 0 additions & 49 deletions
This file was deleted.

buildSrc/build.gradle.kts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
plugins {
2+
`kotlin-dsl`
3+
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.8"
4+
}
5+
6+
val IS_CI = System.getenv("CI_BUILD").toBoolean()
7+
8+
idea.module {
9+
if(!IS_CI) {
10+
isDownloadSources = true
11+
isDownloadJavadoc = true
12+
}
13+
14+
excludeDirs.addAll(files(
15+
".gradle",
16+
"build"
17+
))
18+
}
19+
20+
repositories {
21+
gradlePluginPortal()
22+
mavenCentral()
23+
24+
maven("https://maven.neoforged.net/releases") {
25+
content {
26+
includeGroup("net.neoforged")
27+
}
28+
}
29+
30+
maven("https://prmaven.neoforged.net/ModDevGradle/pr118") {
31+
content {
32+
includeModule("net.neoforged.moddev.legacyforge", "net.neoforged.moddev.legacyforge.gradle.plugin")
33+
includeModule("net.neoforged.moddev.repositories", "net.neoforged.moddev.repositories.gradle.plugin")
34+
includeModule("net.neoforged", "moddev-gradle")
35+
includeModule("net.neoforged.moddev", "net.neoforged.moddev.gradle.plugin")
36+
}
37+
}
38+
}
39+
40+
dependencies {
41+
// working against MDG PR build (118)
42+
// https://github.com/neoforged/ModDevGradle/pull/118
43+
implementation("net.neoforged.moddev:net.neoforged.moddev.gradle.plugin:2.0.60-beta-pr-118-legacy")
44+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package dev.compactmachines;
2+
3+
import org.gradle.jvm.toolchain.JavaLanguageVersion;
4+
import org.gradle.jvm.toolchain.JvmVendorSpec;
5+
6+
public interface GanderConstants {
7+
boolean IS_CI = Boolean.getBoolean("CI");
8+
9+
// java version/vendor to develop against
10+
JavaLanguageVersion JAVA_VERSION = JavaLanguageVersion.of(17);
11+
JvmVendorSpec JAVA_VENDOR = IS_CI ? JvmVendorSpec.ADOPTIUM : JvmVendorSpec.JETBRAINS;
12+
13+
String MINECRAFT_VERSION = "1.20.1";
14+
String MINECRAFT_VERSION_SHORT = MINECRAFT_VERSION.substring("1.".length());
15+
16+
String FORGE_VERSION = MINECRAFT_VERSION + "-47.3.12";
17+
18+
String PARCHMENT_VERSION = MINECRAFT_VERSION;
19+
String PARCHMENT_MAPPINGS = "2023.09.03";
20+
21+
String GROUP = "dev.compactmachines";
22+
String VERSION = MINECRAFT_VERSION_SHORT + ".0";
23+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import dev.compactmachines.GanderConstants
2+
import org.slf4j.event.Level
3+
4+
plugins {
5+
id("java-library")
6+
id("idea")
7+
id("org.jetbrains.gradle.plugin.idea-ext")
8+
id("net.neoforged.moddev.legacyforge")
9+
}
10+
11+
// main convention script which sets up a basic MDG workspace
12+
// pulling in version data from GanderConstants since version catalogs
13+
// from the main outer project are not accessible here
14+
15+
group = GanderConstants.GROUP
16+
version = GanderConstants.VERSION
17+
18+
base {
19+
archivesName = project.name
20+
libsDirectory.convention(rootProject.layout.projectDirectory.dir("libs/${project.name}"))
21+
}
22+
23+
idea.module {
24+
if(!GanderConstants.IS_CI) {
25+
isDownloadSources = true
26+
isDownloadJavadoc = true
27+
}
28+
29+
excludeDirs.addAll(files(
30+
".gradle",
31+
"build",
32+
"run"
33+
))
34+
}
35+
36+
java {
37+
toolchain {
38+
languageVersion.convention(GanderConstants.JAVA_VERSION)
39+
vendor.convention(GanderConstants.JAVA_VENDOR)
40+
}
41+
}
42+
43+
neoForge {
44+
version.convention(GanderConstants.FORGE_VERSION)
45+
// not currently usable since the AT included in legacy forge
46+
// does not itself validate, many unused/nonexistent AT entries exist in it
47+
// validateAccessTransformers.convention(true)
48+
49+
parchment {
50+
minecraftVersion.convention(GanderConstants.PARCHMENT_VERSION)
51+
mappingsVersion.convention(GanderConstants.PARCHMENT_MAPPINGS)
52+
}
53+
54+
// apply this modules AT file if it exists
55+
// also mark for publishing with maven publication
56+
val atFile = file("src/main/resources/META-INF/accesstransformer.cfg")
57+
58+
if(atFile.exists()) {
59+
accessTransformers {
60+
from(atFile)
61+
publish(atFile)
62+
}
63+
}
64+
65+
runs.configureEach {
66+
// set up basic common run config properties
67+
// due to using convention this can be override in each run config
68+
logLevel.convention(Level.DEBUG)
69+
sourceSet.convention(sourceSets[SourceSet.MAIN_SOURCE_SET_NAME])
70+
loadedMods.convention(mods) // all registered mods
71+
gameDirectory.convention(type.map { layout.projectDirectory.dir("run/$it") })
72+
73+
// using '.map' adds args as a 'provider'
74+
// making them lazily evaluated later
75+
// when 'type' actually exists
76+
//
77+
// adds jbr jvm args only for client/server run types
78+
jvmArguments.addAll(type.map {
79+
if(GanderConstants.IS_CI || (it != "client" && it != "server"))
80+
return@map emptyList<String>()
81+
82+
return@map listOf(
83+
"-XX:+AllowEnhancedClassRedefinition",
84+
"-XX:+IgnoreUnrecognizedVMOptions",
85+
"-XX:+AllowRedefinitionToAddDeleteMethods"
86+
)
87+
})
88+
}
89+
}
90+
91+
tasks.jar {
92+
manifest.from(file("src/main/resources/META-INF/MANIFEST.MF"))
93+
}
94+
95+
dependencies {
96+
// not included with MDG currently
97+
// does not affect runtime or production
98+
// safe to have at compile time with no issues
99+
compileOnly("org.jetbrains:annotations:26.0.1")
100+
101+
annotationProcessor("org.spongepowered:mixin:0.8.5:processor")
102+
}
103+
104+
tasks.withType<JavaCompile> {
105+
options.encoding = "UTF-8"
106+
options.release.convention(GanderConstants.JAVA_VERSION.asInt())
107+
108+
if(!GanderConstants.IS_CI) {
109+
options.compilerArgs.addAll(arrayOf("-Xmaxerrs", "9000"))
110+
}
111+
}
112+
113+
javaToolchains.compilerFor {
114+
languageVersion.convention(GanderConstants.JAVA_VERSION)
115+
vendor.convention(GanderConstants.JAVA_VENDOR)
116+
}

gradle.properties

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
2-
# This is required to provide enough memory for the Minecraft decompilation process.
3-
org.gradle.jvmargs = -Xmx3G
4-
org.gradle.daemon = false
1+
org.gradle.jvmargs=-Xmx4G
2+
org.gradle.daemon=true
3+
org.gradle.parallel=true
4+
org.gradle.caching=true
5+
org.gradle.configuration-cache=true

levels/build.gradle.kts

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,12 @@
11
plugins {
2-
idea
3-
alias(forge.plugins.forgegradle)
4-
alias(forge.plugins.mixingradle)
2+
id("gander-convention")
53
}
64

7-
group = rootProject.group
8-
version = rootProject.version
9-
base.archivesName = "levels"
5+
// simply exists to apply the module convention script
6+
// sets up MDG workspace and includes manifest data from resources dir
7+
// additional setup specific to this module may be applied here
108

11-
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
12-
13-
minecraft {
14-
mappings("official", forge.versions.minecraft.get())
15-
copyIdeResources = true
16-
}
17-
18-
mixin {
19-
add(sourceSets[SourceSet.MAIN_SOURCE_SET_NAME], "gander_levels.refmap.json")
20-
config("gander_levels.mixins.json")
21-
}
22-
23-
dependencies {
24-
minecraft("net.minecraftforge:forge:${forge.versions.minecraft.get()}-${forge.versions.forge.get()}")
25-
annotationProcessor("org.spongepowered:mixin:${forge.versions.mixin.get()}:processor")
26-
}
27-
28-
tasks.withType<JavaCompile> {
29-
options.encoding = "UTF-8"
30-
options.compilerArgs.addAll(arrayOf("-Xmaxerrs", "1000"))
31-
}
32-
33-
tasks.jar {
34-
manifest.attributes(
35-
"FMLModType" to "GAMELIBRARY",
36-
"Automatic-Module-Name" to "ganderlevels",
37-
"MixinConfigs" to "gander_levels.mixins.json"
38-
)
39-
}
9+
//mixin {
10+
// add(sourceSets[SourceSet.MAIN_SOURCE_SET_NAME], "gander_levels.mixins.json")
11+
// config("gander_levels.mixins.json")
12+
//}

0 commit comments

Comments
 (0)