Skip to content

Instantly share code, notes, and snippets.

@KorewaLidesu
Last active February 27, 2024 02:18
Show Gist options
  • Save KorewaLidesu/eae14e92a4d733924ed2529e3f5e5256 to your computer and use it in GitHub Desktop.
Save KorewaLidesu/eae14e92a4d733924ed2529e3f5e5256 to your computer and use it in GitHub Desktop.
Adding hotswap agent to RFG-based gradle project

This provide simple way to download hotswap agent to your project folder without pain setup it

Can be use for other purposes outside of below example, be creative with it :chenstare:

Warning: You have to install DCEVM to your JDK and make sure your Gradle is using it, else this won't work as HotswapAgent relied on DCEVM to work (check ref here or below install guide)

Notes

DCEVM does not officially support mixin swapping:

  • When run on Java 1.8:181, DCEVM and Mixin reloads do not work.
  • When run on DCEVM Java 11, you can reload, but the hot swap task freezes.
  • When run on JetBrains Runtime's Java 17 fork (with DCEVM), Mixin hotswapping and DCEVM work properly.

Installing DCEVM on Java 8 for nerds

You can use JDK from any distributor (I dont guarantee it will work, have a test yourself) The one I will do in this guide is Zulu, take this as reference and apply base on which distribution you will use.

  • Check the notes first to decide which version you will use, then download DCEVM from here.
  • Run it as a Java application (if your JAVA_HOME and PATH only contains Java8), or specific it and run on the terminal as below: java -jar DCEVM-8u<version>-installer.jar (vary on the downloaded file name).
  • As DCEVM was built on very very old days, it won't detect most of newer Java distributor. So now you will have to specific it yourself (ref).
  • If you are prefer running DCEVM as main JVM, then press Replace by DCEVM. Else if you are also use it for other purposes, press Install DCEVM as altjvm. With this done, the Uninstall button should highlight up and ready to use for hotswapping.
  • If you are install it as altjvm, make sure to add -XXaltjvm=dcevm to the JVM launch argument to make sure that you are using DCEVM as JVM or else this won't work.
  • Make sure that you are point your IDE or whatevery it is to use the JDK you just install DCEVM, else it will throw errors out. :smug:

Also, it is better to install it as altjvm so you can use the JDK for other purposes without have headache if anything goes wrong.

Below example is:

  • Work with minecraft modding gradle project using RetroFuturaGradle
  • Can be copy and paste directly within build.gradle (or extra.gradle if you are using CleanroomMC overhaul template)
  • Already added argument to switch JVM to DCEVM.
def hotswapAgent = file('libs/hotswap_agent.jar')
if (!hotswapAgent.exists()) {
new URL('https://github.com/HotswapProjects/HotswapAgent/releases/download/1.4.2-SNAPSHOT/hotswap-agent-1.4.2-SNAPSHOT.jar')
.withInputStream{ i -> hotswapAgent.withOutputStream{ it << i }}
}
minecraft {
extraRunJvmArguments.add('-XXaltjvm=dcevm')
extraRunJvmArguments.add('-javaagent:' + hotswapAgent.getAbsolutePath().replace('\\', '\\\\'))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment