Shadowing dependencies into mod JAR
When you build a mod, you can shadow dependencies into the JAR file. This is useful when you want to distribute your mod as a single JAR file, without including the inner jars, or if you want exclusive control of the dependencies.
Shadowing dependencies is only supported in the main primary jar, we are working on a more complete publication system that supports an arbitrary combination of jars.
This is an optional features and will need to be enabled
The shadow module is mutually exclusive with the jarjar module. You can only use one of them at a time.
Enabling Shadowing
As this feature is optional, and a different distribution method can be used (like jar-in-jar), you will need to enable it in your settings
file:
- Groovy
- Kotlin
features {
usesShadowing = true
}
features {
usesShadowing.set(true)
}
Including dependencies
To shadow dependencies you have to add them to the contained
configuration of your main
source set in your build.gradle:
- Groovy
- Kotlin
tableau {
sourceSets {
main {
contained "com.google.guava:guava:30.1-jre"
}
}
}
tableau {
sourceSets {
main {
contained("com.google.guava:guava:30.1-jre")
}
}
}
This will shadow the Guava library in your mod JAR file as a JAR-in-JAR dependency.
We highly recommend remapping the packages of the dependencies you shadow to avoid conflicts with other mods.
Remapping packages
To remap the packages of the dependencies you shadow, you can add the source and target packages to the renamedNamespaces
property:
- Groovy
- Kotlin
tableau {
shadowing {
renamedNamespaces = [
"com.google.common": "com.example.guava"
]
}
}
tableau {
shadowing {
renamedNamespaces.set(mapOf(
"com.google.common" to "com.example.guava"
))
}
}
This will remap the com.google.common
package to com.example.guava
in the shadowed dependencies as well as your own mod.
Include transitive dependencies
By default, only the direct dependencies are shadowed in the mod JAR file. If you want to shadow transitive dependencies, you can set the usesNoneTransitiveShadow
parameter to false:
- Groovy
- Kotlin
tableau {
jarJar {
usesNoneTransitiveShadow = false
}
}
tableau {
jarJar {
usesNoneTransitiveShadow.set(false)
}
}
This will shadow all transitive dependencies of the direct dependencies into the mod JAR file.
Implementation extension
By default, all dependencies added to the contained configuration are treated as implementation
dependencies.
If you want to disable this behavior, you can set the extendImplementation
parameter to false:
- Groovy
- Kotlin
tableau {
shadowing {
extendImplementation = false
}
}
tableau {
shadowing {
extendImplementation.set(false)
}
}