shadowfacts / Forgelin

Fork of Emberwalker's Forgelin with some sprinkles on top.
Other
95 stars 30 forks source link

Shading/Bundling Forgelin #3

Closed Eladkay closed 7 years ago

Eladkay commented 7 years ago

When building a mod with Forgelin shaded I get this error:

 Execution failed for task ':reobfJar'.
 java.util.zip.ZipException: duplicate entry: META-INF/kotlin-stdlib.kotlin_module

Talking to @JamiesWhiteShirt it seems expected but I still would like to see if there's anything that could be done to make Forgelin shadeable. In this specific case I really cannot use a lib mod.

shadowfacts commented 7 years ago
  1. The whole point of Forgelin is so that multiple mods don't have to shade the Kotlin libraries themselves :V
  2. Are you shading the Kotlin libs and Forgelin? Forgelin itself bundles the Kotlin libs so if you're shading Forgelin, you don't need to shade Kotlin.
Eladkay commented 7 years ago

Not shading the kotlin libs themselves. Only shading Forgelin and another, completely unrelated library.

shadowfacts commented 7 years ago

Can you post a Gist of your build.gradle file (and gradle.properties/build.properties if you have it)?

Eladkay commented 7 years ago

https://github.com/unaussprechlich/HudPixelExtended/blob/1.9.4_dev_experimental/build.gradle

shadowfacts commented 7 years ago

Instead of using the old method of shading, try using the Shadow Gradle plugin.

Eladkay commented 7 years ago

I didn't even know ForgeGradle can take plugins. I'll look into that. How is it related to the problem though? The problem seems to be some sort of double-shading problem.

shadowfacts commented 7 years ago

With the Shadow plugin you can whitelist certain dependencies to shade and exclude transitive dependencies which I don't believe can be done with the old method.

Eladkay commented 7 years ago

What would I whitelist/blacklist? Forgelin's Kotlin dependency?

shadowfacts commented 7 years ago

Forgelin has Kotlin shaded and it transitively depends on Kotlin so there are technically two copies of Kotlin in your project. Since you're shading the Forgelin jar which has Kotlin builtin and transitively depends on Kotlin, you're getting two copies of Kotlin shaded.

You would have something like this in your build.gradle:

dependencies {
    compile "net.shadowfacts:Forgelin:1.1.0"
}

shadowJar {
    dependencies {
        include(dependency("net.shadowfacts:Forgelin:1.1.0"))
        include(dependency("joda-time:joda-time:2.9.6"))
    }
}

You would also need to remove the required configuration and the jars block from your build.gradle.

Eladkay commented 7 years ago

Ok, thanks!

JamiesWhiteShirt commented 7 years ago

Even if this resolves this specific problem, there is another issue related to shading. If a mod using Forgelin 1.1.0+ adds something to the manifest, I am fairly sure there will be a conflict with the manifest file. It might actually be a bad idea all together. I don't know what FML will do when there are several jars with manifests pointing to the same FML core mod.

I firmly believe it should not be recommended to shade Forgelin, mostly because of multiple mods shading the same dependency. This further reinforces it.

Eladkay commented 7 years ago

Yes, I agree that shading dependencies is seldom a good idea, but in this specific case it is required and it is not likely to cause any problems.

shadowfacts commented 7 years ago

The recommendation has always been not to shade Forgelin, because it defeats its entire purpose as well as potentially causing conflicts.