Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

How to apply relocate for intellij runs or runServer?

Recommended Posts


I have a mod that use a external library Discord4j. I read posts about using external libraries with mods and successfully used the Gradle shadow plugin to shade the library into my mod.

Discord4j seems to use a newer version of Netty. So I shaded newer version of netty and relocate the package to avoid conflict with Minecraft/Forge. The built mod (shadow jar) can run on the server.

However, I still cannot run the server through my IDE directly, neither through generated Intellij run configurations or the runServer task (./gradlew runServer)

Running the server through IDE will throw this exception:

[15:43:59] [Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception
java.lang.NoSuchMethodError: 'boolean io.netty.handler.ssl.SslProvider.isAlpnSupported(io.netty.handler.ssl.SslProvider)'
        at reactor.netty.http.client.HttpClientSecure.<clinit>(HttpClientSecure.java:79) ~[reactor-netty-0.9.15.RELEASE.jar:0.9.15.RELEASE] {}
        at reactor.netty.http.client.HttpClient.secure(HttpClient.java:1073) ~[reactor-netty-0.9.15.RELEASE.jar:0.9.15.RELEASE] {}
        at discord4j.common.ReactorResources.lambda$static$0(ReactorResources.java:41) ~[discord4j-common-3.1.3.jar:3.1.3] {}
        at discord4j.common.ReactorResources.<init>(ReactorResources.java:54) ~[discord4j-common-3.1.3.jar:3.1.3] {}
        at discord4j.rest.RestClientBuilder.initReactorResources(RestClientBuilder.java:262) ~[discord4j-rest-3.1.3.jar:3.1.3] {}
        at discord4j.rest.RestClientBuilder.build(RestClientBuilder.java:243) ~[discord4j-rest-3.1.3.jar:3.1.3] {}
        at discord4j.core.DiscordClientBuilder.build(DiscordClientBuilder.java:85) ~[discord4j-core-3.1.3.jar:3.1.3] {}
        at discord4j.core.DiscordClientBuilder.build(DiscordClientBuilder.java:73) ~[discord4j-core-3.1.3.jar:3.1.3] {}
        at discord4j.core.DiscordClient.create(DiscordClient.java:59) ~[discord4j-core-3.1.3.jar:3.1.3] {re:classloading}
        at com.github.tony84727.xptweak.XpTweakConfig.getDiscordClient(XpTweakConfig.java:19) ~[main/:?] {re:classloading}
        at com.github.tony84727.xptweak.ModEventListener.onModConfig(ModEventListener.java:42) ~[main/:?] {re:classloading}

Which means Discord4j is using the older version shipped with Minecraft and isAlpnSupported method isn't available.

Is there any way to do shading and relocation in the IDE runs?

Here's the gradle file of the mod: https://github.com/tony84727/xp-tweak/blob/7f24df8f46f78840d145605db1d2cfdd988ef66b/build.gradle

Any help or pointer is appreciated. Thanks!

Link to post
Share on other sites

There's no evidence that you use a newer version of netty within the buildscript. You indeed shadow the version during building, but you do not compile it for use within the game. You still need to require a dependency on it such that it is used within runtime.

  • Thanks 1
Link to post
Share on other sites

Hello @ChampionAsh5357, thank you for your reply!

On 4/12/2021 at 12:27 AM, ChampionAsh5357 said:

There's no evidence that you use a newer version of netty within the buildscript.

I do not use the newer version of netty directly. It's a transitive dependency of Discord4j:

+--- com.discord4j:discord4j-core:3.1.3
|    +--- io.projectreactor:reactor-bom:Dysprosium-SR15
|    |    ...
|    +--- com.discord4j:discord-json:1.5.6
|    |    ...
|    +--- com.discord4j:discord4j-rest:3.1.3
|    |    ...
|    |    \--- com.discord4j:discord4j-common:3.1.3
|    |         +--- io.projectreactor:reactor-bom:Dysprosium-SR15 (*)
|    |         +--- com.discord4j:discord-json:1.5.6 (*)
|    |         +--- io.projectreactor.netty:reactor-netty:0.9.15.RELEASE
|    |         |    +--- io.netty:netty-codec-http:4.1.54.Final

(BTW, Minecraft is using io.netty:netty-all:4.1.25.Final)


On 4/12/2021 at 12:27 AM, ChampionAsh5357 said:

You indeed shadow the version during building, but you do not compile it for use within the game

I thought those line will extend "compile" by "shadow" configuration, making "compile" inherit dependencies from "shaodw":


But anyway, I tried. I added netty dependency to the buildscript and found out that ./gradlew runServer is working!🎉 (the PR)

However, for intellij runs, still no luck. (I've run ./gradlew genIntellijRuns again after updating the buildscript). Starting server by IDE runs will still throw java.lang.NoSuchMethodError, indicating those runs are still using old version of netty.


I still wish I can launch server by IDE runs so I can use IDE's debug utilities.

Link to post
Share on other sites
On 4/13/2021 at 1:08 PM, MinecraftXwinP said:

However, for intellij runs, still no luck. (I've run ./gradlew genIntellijRuns again after updating the buildscript). Starting server by IDE runs will still throw java.lang.NoSuchMethodError, indicating those runs are still using old version of netty.

My bad, after modifying a build script, IDE need to sync with gradle again to rebuild the model or module(?). After syncing, the IDE runs works.

Although, I'm still not sure what happened. I guess it's because when explicitly adding the netty dependency into the dependencies block, gradle will prefer newer version over the original version used by Minecraft?


The final working buildscript for me is: https://github.com/tony84727/xp-tweak/blob/14c629e3e582beed0d620313a291cd2b54273220/build.gradle

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • That is just the modpack, no logs.
    • I created a modpack for me and my friends but we constantly crash after ~5 minutes of playing , Can some one help me please ? Here are the logs and the modpack : https://www.mediafire.com/file/kqnui7c0wzu8t7k/VladPack4-1.16.5.zip/file
    • I wrote a class that stores the BlockPos and BlockState of a specific block that needs to be changed into another block after a certain amount of time. So far I just coded stone bricks being changed into cracked stone bricks. In every worldtickevent I call a method called onTick in which there is a slight chance (1 in 1000) that this change will occur. The class that does this is called DecayHandler.java   DecayHandler.Java :   public class DecayHandler { public BlockState blockState; public BlockPos blockPos; public World world; private Random random; public int decayChance = 1000; private boolean decayed = false; public DecayHandler(BlockState blockState, BlockPos blockPos, World world){ this.blockState = blockState; this.blockPos = blockPos; this.world = world; random = new Random(); } public DecayHandler OnTick(){ //TODO: Refactor in other methods and implement BlockSwapper if(random.nextInt(decayChance) == 0 && !decayed){ System.out.println(this.blockPos + " Decayed"); if(world.setBlockAndUpdate(blockPos, Blocks.CRACKED_STONE_BRICKS.getBlock().defaultBlockState())){ this.blockState = Blocks.CRACKED_STONE_BRICKS.getBlock().defaultBlockState(); decayed = true; return this; } } //WorldDecayData.get(); return null; } }   This code works fine when I load in to a world and place stone bricks down. The stone bricks stay there for a couple of seconds and then they change into cracked stone bricks. The problem occurs when I save and quit to title and rejoin the same world when I placed stone brick that hadn't decayed yet. The game seems to remember what DecayHandlers were running which I guess is logical because I never closed it. So when the world is reloaded again my code stops without error and no longer functions. I can see in the terminal that the last message that was displayed was that a block decayed so I put a breakpoint on it to see what went wrong. By the way, the game keeps running just fine but my code just stops. The part where it seems to go wrong is in this line:  if(world.setBlockAndUpdate(blockPos, Blocks.CRACKED_STONE_BRICKS.getBlock().defaultBlockState())) When I try to step in to every single detail the callstack becomes insanely large and I'm unable to understand what's going on. The only thing I know is that right at the end they put my thread in to parking or something? I really don't understand what was going on. Can someone explain why this is happening? I don't have a clue of what's going on.
    • Thank you @ChampionAsh5357 for your replies and useful feedback! I'll follow your advice and see where it takes me.
    • This statement is a bit incorrect. The methods still exist, they just use a different mapping set (MCP) than what forge ships with the mdk by default (mojmap). You can use forge-bot on the Forge Discord or Linkie on the Linkie Discord to translate from them. I would probably use a chunk capability instead and tick logic on loaded chunks since you'd have to check every block if it's loaded other than checking the loaded chunks. You could also use a world capability to store the chunks that have an active capability for more efficient usage.
  • Topics

  • Who's Online (See full list)

  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.