nea89o / Forge1.8.9Template

The Unlicense
120 stars 36 forks source link

How to shade a dependency? #34

Closed DavidTheExplorer closed 1 week ago

DavidTheExplorer commented 1 week 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 1 week 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 1 week 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 1 week 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 1 week 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 1 week 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.