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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract org.gradle.api.file.RegularFileProperty
     
    abstract org.gradle.api.file.ConfigurableFileCollection
    Everything to bundle: the project's classes/resource directories followed by the runtime-dependency jars.
    abstract org.gradle.api.provider.Property<Integer>
    DEFLATE level, -1 = zlib default (6).
    abstract org.gradle.api.provider.Property<String>
    Main-Class manifest attribute; if unset, the jar is not executable.
    abstract org.gradle.api.provider.MapProperty<String,String>
    Extra manifest main-attributes to add.
    abstract org.gradle.api.provider.Property<Boolean>
    When true, drops any bundled dependency class Minimizer's reachability analysis can't prove is used by the project's own code.
    abstract org.gradle.api.provider.SetProperty<String>
    Classes minimize() never drops regardless of reachability; see MinimizeSpec.keep(java.lang.String...).
    abstract org.gradle.api.file.DirectoryProperty
    Persistent cross-build cache directory for packed sources (see PackCache); set by ShadedJarPlugin to a fixed location under Gradle's user home.
    abstract org.gradle.api.file.ConfigurableFileCollection
    The project's own compiled output (classes/resource directories) — a subset of getClasspath(), tracked separately so Minimizer knows which reachability roots to always keep, as opposed to the dependency jars that are actually eligible for dropping.
    abstract org.gradle.api.provider.MapProperty<String,String>
    Exclude patterns per relocation, same shape as getRelocationIncludes().
    abstract org.gradle.api.provider.MapProperty<String,String>
    Include patterns per relocation, keyed by the same prefix as getRelocations().
    abstract org.gradle.api.provider.MapProperty<String,String>
    Package relocations: source dotted prefix -> shaded dotted prefix.
    abstract org.gradle.api.provider.Property<Boolean>
    STORE everything instead of DEFLATE (fastest, ~larger).
    abstract org.gradle.workers.WorkerExecutor
     
    void
    run()
     

    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, usesService

    Methods 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, setImpliesSubProjects

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods 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. @Classpath makes up-to-date checks ignore jar timestamps/order-insensitive metadata, giving proper incrementality.
    • getArchiveFile

      @OutputFile public abstract org.gradle.api.file.RegularFileProperty getArchiveFile()
    • getMainClass

      @Input @Optional public abstract org.gradle.api.provider.Property<String> getMainClass()
      Main-Class manifest 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

      @Input @Optional public abstract org.gradle.api.provider.Property<Integer> getLevel()
      DEFLATE level, -1 = zlib default (6).
    • getStore

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> 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 as getRelocations().
    • getRelocationExcludes

      @Input @Optional public abstract org.gradle.api.provider.MapProperty<String,String> getRelocationExcludes()
      Exclude patterns per relocation, same shape as getRelocationIncludes().
    • getMinimize

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getMinimize()
      When true, drops any bundled dependency class Minimizer's reachability analysis can't prove is used by the project's own code.
    • getMinimizeKeep

      @Input @Optional public abstract org.gradle.api.provider.SetProperty<String> getMinimizeKeep()
      Classes minimize() never drops regardless of reachability; see MinimizeSpec.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 of getClasspath(), tracked separately so Minimizer knows 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 iterates getClasspath() 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 (see PackCache); set by ShadedJarPlugin to 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

      public void run() throws Exception
      Throws:
      Exception