Skip to content

Instantly share code, notes, and snippets.

@JDLogic
Last active November 25, 2022 14:17
Show Gist options
  • Save JDLogic/bf16deed3bcf99bd9e1a22eb21148389 to your computer and use it in GitHub Desktop.
Save JDLogic/bf16deed3bcf99bd9e1a22eb21148389 to your computer and use it in GitHub Desktop.
How to use ForgeGradle's updateMappings task

What is it

This task will migrate (remap) the project's source files to a new mapping version.

Warning:

Running this task with edit your project's source files. It does NOT make a backup. It is highly recommened that you commit any pending changes before doing this. (If you are not using version control, you should be.)

Before running the command

Source must be compilable

This process uses Srg2Source to remap the project's source files. Therefore, your project must be compilable for this process to work.

Adding other source sets

By default, the updateMappings task will only update the source directories in the projects main source set. If you use additioanl source sets in your project, then you must add them to the remapping tasks. Below is an example adding an api source set. Note: The property check is important as these tasks do not exists unless it is specified.

if (project.hasProperty('UPDATE_MAPPINGS')) {
   extractRangeMap {
     sources sourceSets.api.java.srcDirs
   }
   applyRangeMap {
     sources sourceSets.api.java.srcDirs
   }
   sourceSets.api.java.srcDirs.each { extractMappedNew.addTarget it }
 }

The command

This command should be run before you update the mapping version in you build file.

./gradlew -PUPDATE_MAPPINGS="new mapping version" -PUPDATE_MAPPINGS_CHANNEL="snapshot" updateMappings

Note that the UPDATE_MAPPINGS_CHANNEL property is not required and will default to snapshot.

Known issues

  • Extra imports: Srg2Source is not the greatest with inner classes and will sometimes add extra imports for them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment