55 * Please check https://github.com/GregTechCEu/Buildscripts/blob/master/build.gradle for updates.
66 */
77
8+ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
9+ import com.gtnewhorizons.retrofuturagradle.mcp.ReobfuscatedJar
810import com.modrinth.minotaur.dependencies.ModDependency
911import com.modrinth.minotaur.dependencies.VersionDependency
1012import org.gradle.api.tasks.testing.logging.TestExceptionFormat
@@ -25,6 +27,7 @@ plugins {
2527 id ' com.modrinth.minotaur' version ' 2.7.+' apply false
2628 id ' com.diffplug.spotless' version ' 6.13.0' apply false
2729 id ' com.palantir.git-version' version ' 3.0.0' apply false
30+ id ' com.github.johnrengelman.shadow' version ' 8.1.1' apply false
2831}
2932
3033if (verifySettingsGradle()) {
@@ -61,6 +64,9 @@ propertyDefaultIfUnset("includeWellKnownRepositories", true)
6164propertyDefaultIfUnset(" includeCommonDevEnvMods" , true )
6265propertyDefaultIfUnset(" noPublishedSources" , false )
6366propertyDefaultIfUnset(" forceEnableMixins" , false )
67+ propertyDefaultIfUnset(" usesShadowedDependencies" , false )
68+ propertyDefaultIfUnset(" minimizeShadowedDependencies" , true )
69+ propertyDefaultIfUnset(" relocateShadowedDependencies" , true )
6470propertyDefaultIfUnset(" modrinthProjectId" , " " )
6571propertyDefaultIfUnset(" modrinthRelations" , " " )
6672propertyDefaultIfUnset(" curseForgeProjectId" , " " )
@@ -189,6 +195,11 @@ if (project.file('.git/HEAD').isFile() || project.file('.git').isFile()) {
189195 apply plugin : ' com.palantir.git-version'
190196}
191197
198+ // Shadowing
199+ if (usesShadowedDependencies. toBoolean()) {
200+ apply plugin : ' com.github.johnrengelman.shadow'
201+ }
202+
192203
193204// Configure Java
194205
@@ -356,6 +367,13 @@ repositories {
356367configurations {
357368 embed
358369 implementation. extendsFrom(embed)
370+
371+ if (usesShadowedDependencies. toBoolean()) {
372+ for (config in [compileClasspath, runtimeClasspath, testCompileClasspath, testRuntimeClasspath]) {
373+ config. extendsFrom(shadowImplementation)
374+ config. extendsFrom(shadowCompile)
375+ }
376+ }
359377}
360378
361379dependencies {
@@ -534,21 +552,7 @@ if (usesMixins.toBoolean()) {
534552
535553jar {
536554 manifest {
537- def attribute_map = [:]
538- if (coreModClass) {
539- attribute_map[' FMLCorePlugin' ] = " ${ modGroup} .${ coreModClass} "
540- }
541- if (! containsMixinsAndOrCoreModOnly. toBoolean() && (usesMixins. toBoolean() || coreModClass)) {
542- attribute_map[' FMLCorePluginContainsFMLMod' ] = true
543- }
544- if (accessTransformersFile) {
545- attribute_map[' FMLAT' ] = accessTransformersFile. toString()
546- }
547-
548- if (usesMixins. toBoolean()) {
549- attribute_map[' ForceLoadAsMod' ] = ! containsMixinsAndOrCoreModOnly. toBoolean()
550- }
551- attributes(attribute_map)
555+ attributes(getManifestAttributes())
552556 }
553557
554558 // Add all embedded dependencies into the jar
@@ -571,6 +575,66 @@ tasks.register('apiJar', Jar) {
571575 }
572576}
573577
578+ // Configure shadow jar task
579+ if (usesShadowedDependencies. toBoolean()) {
580+ tasks. named(' shadowJar' , ShadowJar ). configure {
581+ manifest {
582+ attributes(getManifestAttributes())
583+ }
584+ // Only shadow classes that are actually used, if enabled
585+ if (minimizeShadowedDependencies. toBoolean()) {
586+ minimize()
587+ }
588+ configurations = [
589+ project. configurations. shadowImplementation,
590+ project. configurations. shadowCompile
591+ ]
592+ archiveClassifier. set(' dev' )
593+ if (relocateShadowedDependencies. toBoolean()) {
594+ relocationPrefix = modGroup + ' .shadow'
595+ enableRelocation = true
596+ }
597+ }
598+ configurations. runtimeElements. outgoing. artifacts. clear()
599+ configurations. apiElements. outgoing. artifacts. clear()
600+ configurations. runtimeElements. outgoing. artifact(tasks. named(' shadowJar' , ShadowJar ))
601+ configurations. apiElements. outgoing. artifact(tasks. named(' shadowJar' , ShadowJar ))
602+ tasks. named(' jar' , Jar ) {
603+ enabled = false
604+ finalizedBy(tasks. shadowJar)
605+ }
606+ tasks. named(' reobfJar' , ReobfuscatedJar ) {
607+ inputJar. set(tasks. named(' shadowJar' , ShadowJar ). flatMap({it. archiveFile}))
608+ }
609+ AdhocComponentWithVariants javaComponent = (AdhocComponentWithVariants ) project. components. findByName(' java' )
610+ javaComponent. withVariantsFromConfiguration(configurations. shadowRuntimeElements) {
611+ skip()
612+ }
613+ for (runTask in [' runClient' , ' runServer' ]) {
614+ tasks. named(runTask). configure {
615+ dependsOn(' shadowJar' )
616+ }
617+ }
618+ }
619+
620+ def getManifestAttributes () {
621+ def attributes = [:]
622+ if (coreModClass) {
623+ attributes[' FMLCorePlugin' ] = " ${ modGroup} .${ coreModClass} "
624+ }
625+ if (! containsMixinsAndOrCoreModOnly. toBoolean() && (usesMixins. toBoolean() || coreModClass)) {
626+ attributes[' FMLCorePluginContainsFMLMod' ] = true
627+ }
628+ if (accessTransformersFile) {
629+ attributes[' FMLAT' ] = accessTransformersFile. toString()
630+ }
631+
632+ if (usesMixins. toBoolean()) {
633+ attributes[' ForceLoadAsMod' ] = ! containsMixinsAndOrCoreModOnly. toBoolean()
634+ }
635+ return attributes
636+ }
637+
574638
575639// IDE Configuration
576640
@@ -705,7 +769,7 @@ if (modrinthApiKey.isPresent() || deploymentDebug.toBoolean()) {
705769 gameVersions = [minecraftVersion]
706770 loaders = [" forge" ]
707771 debugMode = deploymentDebug. toBoolean()
708- uploadFile = file( " build/libs/ ${ archivesBaseName } - ${ version } .jar " )
772+ uploadFile = reobfJar
709773 additionalFiles = getSecondaryArtifacts()
710774 }
711775 if (modrinthRelations. size() != 0 ) {
@@ -906,7 +970,7 @@ def propertyDefaultIfUnsetWithEnvVar(String propertyName, defaultValue, String e
906970}
907971
908972def getSecondaryArtifacts () {
909- def secondaryArtifacts = [jar]
973+ def secondaryArtifacts = [usesShadowedDependencies . toBoolean() ? tasks . shadowJar : tasks . jar]
910974 if (! noPublishedSources. toBoolean()) secondaryArtifacts + = [sourcesJar]
911975 if (apiPackage) secondaryArtifacts + = [apiJar]
912976 return secondaryArtifacts
0 commit comments