Skip to content

Instantly share code, notes, and snippets.

@Commoble
Last active January 15, 2024 06:05
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Commoble/ddc75e819a690198c15d26564d139333 to your computer and use it in GitHub Desktop.
Save Commoble/ddc75e819a690198c15d26564d139333 to your computer and use it in GitHub Desktop.
How2ShadowJar in a minecraft forge mod's buildscript
// thanks to gigaherz for pointing me in the right directions on the buildscript
// The shadow gradle plugin assists with repackaging a 3rd-party library jar within your own jar
// In addition to ensuring that your end-users have the library available when they use your own thing,
// it also helps avoid collisions with other things that are also using the same library.
// As always, make sure the license of the library allows redistribution and is compatible with
// your own thing's license before redistributing it in this manner
buildscript {
repositories {
jcenter() // buildscript repo to get shadow from
}
}
plugins {
// this version works on gradle 4.9
// more recent versions of shadow work on more recent versions of gradle
id 'com.github.johnrengelman.shadow' version '4.0.4'
}
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java' // java plugin is needed for the shadow plugin to work
repositories {
// java repo to get the repackaged lib from
maven { url "https://repo.for/your/included/lib" }
}
configurations {
shade
}
dependencies {
compile "lib.group:lib_artifact:lib_version"
shade "lib.group:lib_artifact:lib_version"
}
shadowJar {
classifier = ''
configurations = [project.configurations.shade]
relocate 'lib.group', "${project.group}.shadow.lib.group" // ensure repackaged packages have unique names
}
reobf {
shadowJar { }
}
// this replaces jar.finalizedBy('reobfJar') in the standard forge mod buildscript
tasks.build.dependsOn reobfShadowJar
jar.finalizedBy('reobfShadowJar')
@Danjb1
Copy link

Danjb1 commented May 23, 2022

For anyone else who finds this, there is a newer guide here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment