Package com.ljarocki.shadedjar
Class FatJarTask
java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
com.ljarocki.shadedjar.FatJarTask
- All Implemented Interfaces:
Comparable<org.gradle.api.Task>,org.gradle.api.internal.DynamicObjectAware,org.gradle.api.internal.TaskInternal,org.gradle.api.Named,org.gradle.api.plugins.ExtensionAware,org.gradle.api.Task,org.gradle.util.Configurable<org.gradle.api.Task>
@CacheableTask
public abstract class FatJarTask
extends org.gradle.api.DefaultTask
Builds a fat (uber) JAR by merging the project's own output and every runtime
dependency into one archive. Each source is (re)compressed in parallel on
Gradle's worker pool (bounded by
--max-workers); a single assembler
thread then streams the parts into a valid, reproducible JAR with first-wins
duplicate handling.
With no relocations this is a plain fat JAR; with
relocations it is a shaded JAR (packages rewritten by ASM in the workers).
Duplicate strategy is first-wins in classpath order (so project classes beat
deps), except META-INF/services/* files and the well-known Spring
properties files (spring.factories/.handlers/.schemas,
see SpringProperties), which are merged across all sources instead.
Signature files and dependency manifests are stripped; a fresh manifest with
an optional Main-Class is generated — and Multi-Release: true
if any source contributes a META-INF/versions/N/... entry, since the
JVM otherwise ignores that directory entirely (see buildManifest(boolean)).
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.gradle.api.Named
org.gradle.api.Named.Namer -
Field Summary
Fields inherited from interface org.gradle.api.Task
TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract org.gradle.api.file.RegularFilePropertyabstract org.gradle.api.file.ConfigurableFileCollectionEverything to bundle: the project's classes/resource directories followed by the runtime-dependency jars.abstract org.gradle.api.provider.Property<Integer> getLevel()DEFLATE level, -1 = zlib default (6).abstract org.gradle.api.provider.Property<String> Main-Classmanifest attribute; if unset, the jar is not executable.Extra manifest main-attributes to add.abstract org.gradle.api.provider.Property<Boolean> Whentrue, drops any bundled dependency classMinimizer's reachability analysis can't prove is used by the project's own code.abstract org.gradle.api.provider.SetProperty<String> Classesminimize()never drops regardless of reachability; seeMinimizeSpec.keep(java.lang.String...).abstract org.gradle.api.file.DirectoryPropertyPersistent cross-build cache directory for packed sources (seePackCache); set byShadedJarPluginto a fixed location under Gradle's user home.abstract org.gradle.api.file.ConfigurableFileCollectionThe project's own compiled output (classes/resource directories) — a subset ofgetClasspath(), tracked separately soMinimizerknows which reachability roots to always keep, as opposed to the dependency jars that are actually eligible for dropping.Exclude patterns per relocation, same shape asgetRelocationIncludes().Include patterns per relocation, keyed by the same prefix asgetRelocations().Package relocations: source dotted prefix -> shaded dotted prefix.abstract org.gradle.api.provider.Property<Boolean> getStore()STORE everything instead of DEFLATE (fastest, ~larger).abstract org.gradle.workers.WorkerExecutorvoidrun()Methods inherited from class org.gradle.api.DefaultTask
compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesServiceMethods inherited from class org.gradle.api.internal.AbstractTask
acceptServiceReferences, appendParallelSafeAction, doNotTrackState, doNotTrackStateIf, getAsDynamicObject, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonsNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, restoreOnlyIf, restoreTaskActions, setImpliesSubProjectsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gradle.api.Task
doNotTrackState, notCompatibleWithConfigurationCache
-
Constructor Details
-
FatJarTask
public FatJarTask()
-
-
Method Details
-
getClasspath
@Classpath public abstract org.gradle.api.file.ConfigurableFileCollection getClasspath()Everything to bundle: the project's classes/resource directories followed by the runtime-dependency jars. Order matters — earlier entries win duplicates.@Classpathmakes up-to-date checks ignore jar timestamps/order-insensitive metadata, giving proper incrementality. -
getArchiveFile
@OutputFile public abstract org.gradle.api.file.RegularFileProperty getArchiveFile() -
getMainClass
Main-Classmanifest attribute; if unset, the jar is not executable. -
getManifestAttributes
@Input @Optional public abstract org.gradle.api.provider.MapProperty<String,String> getManifestAttributes()Extra manifest main-attributes to add. -
getLevel
DEFLATE level, -1 = zlib default (6). -
getStore
STORE everything instead of DEFLATE (fastest, ~larger). -
getRelocations
@Input @Optional public abstract org.gradle.api.provider.MapProperty<String,String> getRelocations()Package relocations: source dotted prefix -> shaded dotted prefix. Empty (the default) means a plain fat JAR; any entry turns on shading. -
getRelocationIncludes
@Input @Optional public abstract org.gradle.api.provider.MapProperty<String,String> getRelocationIncludes()Include patterns per relocation, keyed by the same prefix asgetRelocations(). -
getRelocationExcludes
@Input @Optional public abstract org.gradle.api.provider.MapProperty<String,String> getRelocationExcludes()Exclude patterns per relocation, same shape asgetRelocationIncludes(). -
getMinimize
Whentrue, drops any bundled dependency classMinimizer's reachability analysis can't prove is used by the project's own code. -
getMinimizeKeep
Classesminimize()never drops regardless of reachability; seeMinimizeSpec.keep(java.lang.String...). -
getProjectOutput
@Classpath public abstract org.gradle.api.file.ConfigurableFileCollection getProjectOutput()The project's own compiled output (classes/resource directories) — a subset ofgetClasspath(), tracked separately soMinimizerknows which reachability roots to always keep, as opposed to the dependency jars that are actually eligible for dropping. Not used for packing itself (that still iteratesgetClasspath()in full); only for the minimize pre-pass. -
getPackCacheDir
@Internal public abstract org.gradle.api.file.DirectoryProperty getPackCacheDir()Persistent cross-build cache directory for packed sources (seePackCache); set byShadedJarPluginto a fixed location under Gradle's user home.@Internal, not@InputDirectory/@OutputDirectory— it's a look-aside optimization, not part of this task's own declared inputs/outputs, and its (machine-wide, ever-growing) contents must never be hashed as part of this task's up-to-date/build-cache key. -
getWorkerExecutor
@Inject public abstract org.gradle.workers.WorkerExecutor getWorkerExecutor() -
run
- Throws:
Exception
-