Last active
January 15, 2024 06:05
-
-
Save Commoble/ddc75e819a690198c15d26564d139333 to your computer and use it in GitHub Desktop.
How2ShadowJar in a minecraft forge mod's buildscript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For anyone else who finds this, there is a newer guide here.