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

Hello,

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":

https://github.com/tony84727/xp-tweak/blob/7f24df8f46f78840d145605db1d2cfdd988ef66b/build.gradle#L114-L117

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.

Guest
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.



×
×
  • Create New...

Important Information

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