Skip to content

Commit 195e9d2

Browse files
committed
Update to ForgeGradle 7
1 parent 27ab359 commit 195e9d2

File tree

7 files changed

+105
-153
lines changed

7 files changed

+105
-153
lines changed

build.gradle

Lines changed: 83 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
plugins {
2-
id 'eclipse'
2+
id 'java'
33
id 'idea'
4+
id 'eclipse'
45
id 'maven-publish'
5-
id 'net.minecraftforge.gradle' version '[6.0.46,6.2)'
6+
id 'net.minecraftforge.accesstransformers' version '5.0.1'
7+
id 'net.minecraftforge.gradle' version '7.0.0-beta.46'
8+
id 'net.minecraftforge.jarjar' version '0.2.3'
69
id 'org.ajoberstar.grgit' version '5.2.0'
7-
id 'org.spongepowered.mixin' version '0.7.+'
810
}
911

1012
final commitId
@@ -19,113 +21,68 @@ mod_version = "${minecraft_version}-${mod_version}-${commitId}"
1921

2022
version = mod_version
2123
group = mod_group_id
22-
23-
base {
24-
archivesName = mod_id
25-
}
24+
base.archivesName = mod_id
2625

2726
// Mojang ships Java 21 to end users in 1.20.5+, so your mod should target Java 21.
2827
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
2928

30-
println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
29+
println "Java: ${providers.systemProperty('java.version').get()}, " +
30+
"JVM: ${providers.systemProperty('java.vm.version').get()} (${providers.systemProperty('java.vendor').get()}), " +
31+
"Arch: ${providers.systemProperty('os.arch').get()}"
32+
3133
minecraft {
32-
// The mappings can be changed at any time and must be in the following format.
33-
// Channel: Version:
34-
// official MCVersion Official field/method names from Mojang mapping files
35-
// parchment YYYY.MM.DD-MCVersion Open community-sourced parameter names and javadocs layered on top of official
36-
//
37-
// Parchment is an unofficial project maintained by ParchmentMC, separate from MinecraftForge
38-
// Additional setup is needed to use their mappings: https://parchmentmc.org/docs/getting-started
39-
//
40-
// Simply re-run your setup task after changing the mappings to update your workspace.
4134
mappings channel: mapping_channel, version: mapping_version
4235

43-
// Forge 1.20.6 and newer use official mappings at runtime, so we shouldn't reobf from official to SRG
44-
reobf = false
45-
46-
// When true, this property will have all Eclipse/IntelliJ IDEA run configurations run the "prepareX" task for the given run configuration before launching the game.
47-
// In most cases, it is not necessary to enable.
48-
// enableEclipsePrepareRuns = true
49-
// enableIdeaPrepareRuns = true
50-
51-
// This property allows configuring Gradle's ProcessResources task(s) to run on IDE output locations before launching the game.
52-
// It is REQUIRED to be set to true for this template to function.
53-
// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
54-
copyIdeResources = true
55-
56-
// When true, this property will add the folder name of all declared run configurations to generated IDE run configurations.
57-
// The folder name can be set on a run configuration using the "folderName" property.
58-
// By default, the folder name of a run configuration is the name of the Gradle project containing it.
59-
// generateRunFolders = true
60-
61-
// This property enables access transformers for use in development, applied to the Minecraft artifact.
62-
// The access transformer file can be anywhere in the project.
63-
// However, it must be at "META-INF/accesstransformer.cfg" in the final mod jar to be loaded by Forge.
64-
// This default location is a best practice to automatically put the file in the right place in the final jar.
65-
// See https://docs.minecraftforge.net/en/latest/advanced/accesstransformers/ for more information.
66-
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
67-
68-
// Default run configurations.
69-
// These can be tweaked, removed, or duplicated as needed.
36+
accessTransformers = true
37+
7038
runs {
71-
// Applies to all the run configs below
7239
configureEach {
73-
workingDirectory project.file('run')
40+
workingDir.convention layout.projectDirectory.dir('run')
7441

75-
// Optional additional logging. The markers can be added/remove as needed, separated by commas.
76-
// "SCAN": For mods scan.
77-
// "REGISTRIES": For firing of registry events.
78-
// "REGISTRYDUMP": For getting the contents of all registries.
79-
// property 'forge.logging.markers', 'REGISTRIES'
42+
//systemProperty 'forge.logging.markers', 'REGISTRIES'
8043

81-
property 'forge.logging.console.level', 'debug'
44+
systemProperty 'forge.logging.console.level', 'debug'
8245

83-
// Recommended for development - enables more descriptive errors at the cost of slower startup and registration.
84-
property 'eventbus.api.strictRuntimeChecks', 'true'
46+
systemProperty 'eventbus.api.strictRuntimeChecks', 'true'
8547

86-
// arg "-mixin.config=${mod_id}.mixins.json"
48+
//args "-mixin.config=${mod_id}.mixins.json"
8749
}
8850

89-
client {
90-
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
91-
property 'forge.enabledGameTestNamespaces', mod_id
51+
register('client') {
52+
systemProperty 'forge.enabledGameTestNamespaces', mod_id
9253
}
9354

94-
server {
95-
property 'forge.enabledGameTestNamespaces', mod_id
55+
register('server') {
56+
systemProperty 'forge.enabledGameTestNamespaces', mod_id
9657
args '--nogui'
9758
}
9859

99-
// This run config launches GameTestServer and runs all registered gametests, then exits.
100-
// By default, the server will crash when no gametests are provided.
101-
// The gametest system is also enabled by default for other run configs under the /test command.
102-
gameTestServer {
103-
property 'forge.enabledGameTestNamespaces', mod_id
60+
register('gameTestServer') {
61+
systemProperty 'forge.enabledGameTestNamespaces', mod_id
10462
}
10563

106-
data {
107-
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
108-
args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
64+
register('data') {
65+
workingDir = layout.projectDirectory.dir('run-data')
66+
67+
args '--mod', mod_id, '--all', '--output', layout.projectDirectory.dir('src/generated/resources'), '--existing', layout.projectDirectory.dir('src/main/resources')
10968
}
11069
}
11170
}
11271

11372
// Include resources generated by data generators.
114-
sourceSets.main.resources { srcDir 'src/generated/resources' }
73+
sourceSets.main.resources { srcDir layout.projectDirectory.dir('src/generated/resources') }
11574

116-
repositories {
117-
// Put repositories for dependencies here
118-
mavenCentral()
119-
120-
maven {
121-
name = 'Forge'
122-
url = 'https://maven.minecraftforge.net'
123-
}
75+
// This methods registers jarJar for the default jar task.
76+
// The closure allows you to configure the task, instead of needing to do this:
77+
// tasks.named('jarJar', net.minecraftforge.jarjar.gradle.JarJar)
78+
jarJar.register() {
79+
archiveClassifier = null
80+
}
12481

125-
maven {
126-
name = 'Minecraft libraries'
127-
url = 'https://libraries.minecraft.net'
128-
}
82+
repositories {
83+
maven minecraft.mavenizer
84+
maven fg.forgeMaven
85+
maven fg.minecraftLibsMaven
12986

13087
exclusiveContent {
13188
forRepository {
@@ -158,19 +115,15 @@ repositories {
158115
}
159116
}
160117

118+
mavenCentral()
119+
mavenLocal()
120+
161121
// If you have mod jar dependencies in ./libs, you can declare them as a repository like so.
162122
// See https://docs.gradle.org/current/userguide/declaring_repositories.html#sub:flat_dir_resolver
163-
// flatDir {
164-
// dir 'libs'
165-
// }
166-
}
167-
168-
configurations {
169-
embed {
170-
transitive = false
171-
}
172-
173-
implementation.extendsFrom embed
123+
// NOTE: Support for local dependencies is still experimental in ForgeGradle 7.
124+
//flatDir {
125+
// dir 'libs'
126+
//}
174127
}
175128

176129
dependencies {
@@ -179,7 +132,7 @@ dependencies {
179132
// The "userdev" classifier will be requested and setup by ForgeGradle.
180133
// If the group id is "net.minecraft" and the artifact id is one of ["client", "server", "joined"],
181134
// then special handling is done to allow a setup of a vanilla dependency without the use of an external repository.
182-
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
135+
implementation minecraft.dependency("net.minecraftforge:forge:$minecraft_version-$forge_version")
183136

184137
// Forge 1.21.6+ uses EventBus 7, which shifts most of its runtime validation to compile-time via an annotation processor
185138
// to improve performance in production environments. This line is required to enable said compile-time validation
@@ -192,7 +145,7 @@ dependencies {
192145
// At runtime, use the full JEI jar for Forge
193146
// runtimeOnly fg.deobf("mezz.jei:jei-1.21.1-forge:${jei_version}")
194147

195-
embed "org.apache.httpcomponents:fluent-hc:${httpclient_version}"
148+
implementation jarJar("org.apache.httpcomponents:fluent-hc:${httpclient_version}")
196149

197150
// TODO: Jade doesn't support Forge any more
198151
// implementation fg.deobf("curse.maven:jade-324717:${jade_file_id}")
@@ -202,13 +155,32 @@ dependencies {
202155
// Example mod dependency using a mod jar from ./libs with a flat dir repository
203156
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
204157
// The group id is ignored when searching -- in this case, it is "blank"
205-
// implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}")
158+
// NOTE: Support for deobfuscated dependencies has not yet been added in ForgeGradle 7.
159+
//implementation "blank:coolmod-${mc_version}:${coolmod_version}"
206160

207161
// For more info:
208162
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
209163
// http://www.gradle.org/docs/current/userguide/dependency_management.html
210164
}
211165

166+
tasks.withType(JavaCompile).configureEach {
167+
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
168+
options.compilerArgs.addAll(['-Xlint:unchecked', '-Xlint:deprecation'])
169+
}
170+
171+
tasks.withType(Javadoc).configureEach {
172+
options.encoding = 'UTF-8'
173+
174+
var standardOptions = (StandardJavadocDocletOptions) options
175+
standardOptions.addStringOption("tag", "apiNote:a:API Note:")
176+
standardOptions.addBooleanOption("Xdoclint:all,-missing", true)
177+
}
178+
179+
tasks.register('javadocJar', Jar) {
180+
from javadoc.destinationDir
181+
182+
archiveClassifier.set('javadoc')
183+
}
212184
// This block of code expands all declared replace properties in the specified resource targets.
213185
// A missing property will result in an error. Properties are expanded using ${} Groovy notation.
214186
// When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments.
@@ -222,10 +194,10 @@ tasks.named('processResources', ProcessResources) {
222194
mod_issue_tracker_url: mod_issue_tracker_url, mod_display_url: mod_display_url,
223195
mod_authors : mod_authors, mod_description: mod_description
224196
]
225-
inputs.properties replaceProperties
197+
inputs.property('replaceProperties', replaceProperties)
226198

227199
filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {
228-
expand replaceProperties + [project: project]
200+
expand replaceProperties
229201
}
230202
}
231203

@@ -242,39 +214,23 @@ tasks.named('jar', Jar) {
242214
])
243215
// attributes['MixinConfigs'] = "${mod_id}.mixins.json"
244216
}
217+
218+
archiveClassifier = 'slim'
245219
}
246220

247221
// Example configuration to allow publishing using the maven-publish plugin
248222
publishing {
249-
publications {
250-
register('mavenJava', MavenPublication) {
251-
artifact jar
252-
}
253-
}
254223
repositories {
255-
maven {
256-
url "file://${project.projectDir}/mcmodsrepo"
257-
}
224+
maven { url = "file://${layout.projectDirectory.asFile}/mcmodsrepo" }
258225
}
259-
}
260226

261-
tasks.withType(JavaCompile).configureEach {
262-
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
263-
options.compilerArgs.addAll(['-Xlint:unchecked', '-Xlint:deprecation'])
264-
}
227+
publications.register('mavenJava', MavenPublication) {
228+
// The java component publishes the jar output as the primary artifact
229+
//from components.java
265230

266-
tasks.withType(Javadoc).configureEach {
267-
options.encoding = 'UTF-8'
268-
269-
var standardOptions = (StandardJavadocDocletOptions) options
270-
standardOptions.addStringOption("tag", "apiNote:a:API Note:")
271-
standardOptions.addBooleanOption("Xdoclint:all,-missing", true)
272-
}
273-
274-
tasks.register('javadocJar', Jar) {
275-
from javadoc.destinationDir
276-
277-
archiveClassifier.set('javadoc')
231+
// The jarJar component publishes the jarJar output as the primary artifact
232+
from components.jarJar
233+
}
278234
}
279235

280236
artifacts {
@@ -285,19 +241,12 @@ artifacts {
285241
idea.module { downloadJavadoc = downloadSources = true }
286242

287243
eclipse {
244+
// Eclipse no longer downloads javadocs and sources by default, this tells Gradle to force Eclipse to do it.
245+
classpath { downloadJavadoc = downloadSources = true }
246+
247+
// NOTE: ForgeGradle 7 does not yet support Eclipse run configurations
288248
// Run everytime eclipse builds the code
289249
//autoBuildTasks genEclipseRuns
290250
// Run when importing the project
291-
synchronizationTasks 'genEclipseRuns'
292-
}
293-
294-
// Merge the resources and classes into the same directory, because Java expects modules to be in a single directory.
295-
// And if we have it in multiple we have to do performance intensive hacks like having the UnionFileSystem
296-
// This will eventually be migrated to ForgeGradle so modders don't need to manually do it. But that is later.
297-
sourceSets.each {
298-
def dir = layout.buildDirectory.dir("sourcesSets/$it.name")
299-
it.output.resourcesDir = dir
300-
it.java.destinationDirectory = dir
251+
//synchronizationTasks 'genEclipseRuns'
301252
}
302-
303-
// TODO: Contained dependencies are disabled in 1.14, re-evaluate when they're re-enabled

gradle.properties

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
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=-Xmx5G
4-
org.gradle.daemon=false
1+
org.gradle.caching=true
2+
org.gradle.parallel=true
3+
org.gradle.configureondemand=true
54

6-
# In the case that Gradle needs to fork to recompile, this will set the memory for that process.
7-
systemProp.net.minecraftforge.gradle.repo.recompile.fork=true
8-
systemProp.net.minecraftforge.gradle.repo.recompile.fork.args=-Xmx5G
9-
10-
# Opts-out of ForgeGradle automatically adding mavenCentral(), Forge's maven and MC libs maven to the repositories block
11-
systemProp.net.minecraftforge.gradle.repo.attach=false
5+
org.gradle.configuration-cache=true
6+
org.gradle.configuration-cache.parallel=true
7+
org.gradle.configuration-cache.problems=warn
128

9+
net.minecraftforge.gradle.merge-source-sets=true
1310

1411
## Environment Properties
1512

gradle/wrapper/gradle-wrapper.jar

130 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)