nea89o / Forge1.8.9Template

The Unlicense
141 stars 42 forks source link

How to shade a dependency? #34

Closed DavidTheExplorer closed 4 months ago

DavidTheExplorer commented 4 months ago

I'm a Maven user who started modding a few days ago - Please forgive my basic gradle knowledge. I'm trying to create an Hypixel mod, so I added the hypixel api: image image

The mod works within the IDE, but not when I create a jar. I know from Maven that I need to shade and relocate the API, and I tried to do this: image But when I do build the jar file still doesn't contain the API... What am I doing wrong?

nea89o commented 4 months ago

Instead of using implementation you need to use shadowImpl. This is done because in mods you want to be much more deliberate in what you include in your mod.

DavidTheExplorer commented 4 months ago

Instead of using implementation you need to use shadowImpl. This is done because in mods you want to be much more deliberate in what you include in your mod.

It worked! :) But I have a question: Why did it relocate a transitive dependency outside of the deps package? image

nea89o commented 4 months ago

relocate works on package names. you will probably not want to shade gson at all, so you would want to exclude that dependency:

shadowImpl("my:dependency:1.0.0") {
    exclude (group ="com.google.code.gson")
}
DavidTheExplorer commented 4 months ago

relocate works on package names. you will probably not want to shade gson at all, so you would want to exclude that dependency:

shadowImpl("my:dependency:1.0.0") {
  exclude (group ="com.google.code.gson")
}

Why would I not want to shade GSON if my dependency depends on it? After you answer, you can close this because my problem is solved :)

nea89o commented 4 months ago

Normally you would want to shade the dependency as well (and also specify that package to relocate). However gson is already present in minecraft, so you can just use that versionn.