gradle-fat-jar
An executable jar with every dependency inside it, from a project holding daukle.toml and src/main/java/ and no build.gradle, no settings.gradle and no wrapper. A real packaging plugin from the Gradle Plugin Portal does the packaging, applied from a jar daukle pinned by sha256, and the generated build declares no repositories {} at all.
$ daukle gradle:run-shadow
Hello from a fat jar
That line is printed by org.apache.commons.lang3.StringUtils, which is inside the jar being run, so the output is evidence that the dependency was bundled and not merely downloaded.
| task | what it does |
|---|---|
daukle gradle:shadow-jar | writes build/daukle/gradle/build/libs/example-gradle-fat-jar-1.0.0-all.jar |
daukle gradle:run-shadow | runs that jar |
daukle gradle:jar | the ordinary jar, with no dependency in it |
daukle maven:resolve --resolve | rewrites daukle/maven/classpath.lua from the coordinates |
What to look at
Nothing here knows what a fat jar is. daukle/gradle has no fat-jar feature: shadowJar is a task a third-party plugin contributes, named in tasks, and the plugin is acquired exactly as a compile dependency is. That is the whole design, and it is why a different packaging plugin needs no change to daukle.
main applies Gradle's application plugin, and that is what makes the jar runnable. A packaging plugin reads Main-Class from the application extension, so without it the jar is built correctly and has no entry point, and java -jar on it fails with "no main manifest attribute". Setting the manifest by hand from configure is not possible here, because attributes(...) is a method taking a map and this surface is data.
The relocation is two properties, and the names matter. enableAutoRelocation moves every bundled package under relocationPrefix, so a library this jar carries cannot collide with a different version of the same library in whatever loads it. Shadow 8.x spelled the first one enableRelocation, and shadow 9 answers that with Could not set unknown property. Shadow's other spelling, relocate 'from', 'to', is a method call and is not expressible: this plugin renders blocks and assignments and no Groovy.
daukle/maven/classpath.lua is committed, and that is the shape rather than a shortcut. It holds twenty pinned entries: the one coordinate this project compiles against, and the nineteen modules the shadow plugin itself needs in order to exist. Every url has a sha256 that daukle computed by fetching and hashing the jar, because Maven Central publishes none. daukle.lua includes the file, which is how generated data stays out of the manifest you wrote.
The order matters the first time, and the refusal cannot be followed
A manifest declaring [[toolchains.gradle.plugins]] while pluginClasspath is empty is refused, and every command generates, so even maven:resolve is refused. The message is right and cannot be obeyed in that order. Starting from nothing, it is two steps:
1. declare the [[toolchains.maven.resolve]] block with no [[toolchains.gradle.plugins]] block, and run daukle maven:resolve --resolve, which writes daukle/maven/classpath.lua; 2. add the plugins block.
daukle loads the committed classpath.lua by itself, so there is no daukle.lua.
This example is committed at the end of that sequence, so copying it and changing a coordinate only needs step 1 again.
What this example cannot show
A jar whose Main-Class was asserted by reading the manifest. A zip stores its entry NAMES uncompressed but its entry CONTENTS deflated, so the manifest inside this jar is not greppable. The proof that the entry point is there is that the jar RUNS, which is what the console block above is.
minimize. Shadow can drop classes no code reaches, and nothing here uses it: it is reachability analysis over a closure, which shadow should do and daukle should not.
Two plugins applied at once. Gradle resolves nothing in a generated build, so if two plugin closures disagreed about a version the winner would be whichever jar path was emitted first, and nothing currently decides that. One plugin is applied here and the question is open.
A Maven project. Everything here is Gradle. daukle/maven resolves coordinates; it does not build.
A multi-project build. The generated settings.gradle names one root project and nothing here answers an include ':app'.
The one file that is a harness input rather than part of the example
needs-tools marks this example as one that provisions real tools, which the harness skips unless DAUKLE_EXAMPLE_E2E=1 is set. CI sets it on every runner. The console block above is executed rather than decorative: its $ line is run and the line beneath it must appear in the output.
The first run is slow
A Gradle distribution, a JDK and twenty jars, with no progress reported while they download. All of it is cached per digest afterwards and shared by every project on the machine that pins the same things.
Every file in it
daukle.toml
schema = 1
project = "daukle/example-gradle-fat-jar"
version = "1.0.0"
[modules]
[resolvers.github]
url = "https://raw.githubusercontent.com/daukle/daukle/1f515141e06d16eace718a45944a39933611fa39/plugins/github-releases.lua"
sha256 = "3789865c266eb53fafcf7300d77a24461170c615195d92d0ddf88078c556e23e"
[plugins]
maven = { resolver = "github", coordinate = "daukle/maven@^1.1.0" }
gradle = { resolver = "github", coordinate = "daukle/gradle@^1.3.0" }
# This block is what produced `daukle/maven/classpath.lua`, which is committed
# and which daukle loads by itself. `daukle maven:resolve
# --resolve` fetches both closures, hashes every jar and writes them as pinned
# entries. The result is committed on purpose: a pinned closure belongs in the
# project's history, and a plugin is applied FROM a jar, so there is nothing to
# apply until one is there. Run it again when you change a coordinate.
[toolchains.maven]
for = "gradle"
coordinates = ["org.apache.commons:commons-lang3:3.17.0"]
# The plugin's own closure, from the Plugin Portal rather than Central, and
# into its own key. Nineteen modules, none of which this project compiles
# against: they are what Gradle loads to HAVE the plugin.
[[toolchains.maven.resolve]]
repository = "https://plugins.gradle.org/m2"
for = "gradle"
into = "pluginClasspath"
coordinates = ["com.gradleup.shadow:shadow-gradle-plugin:9.3.2"]
[toolchains.gradle]
version = "9.6.0"
main = "com.example.Main"
tasks = ["shadowJar", "runShadow"]
[[toolchains.gradle.plugins]]
id = "com.gradleup.shadow"
version = "9.3.2"
# `enableAutoRelocation` is shadow 9's spelling; 8.x called it
# `enableRelocation` and 9 answers that with "Could not set unknown property".
# Both are properties, which is why they are expressible here at all: shadow's
# other spelling is `relocate 'a', 'b'`, a method call, and this surface is data.
[toolchains.gradle.configure.shadowJar]
enableAutoRelocation = true
relocationPrefix = "com.example.shaded"
daukle/maven/classpath.lua
-- Generated by maven:resolve. Do not edit: daukle.toml is yours, this is not.
-- Every url and sha256 here was fetched and hashed, because Maven Central
-- publishes no .sha256 for these artifacts.
--
-- Include it from daukle.lua:
-- daukle.include("daukle/maven/classpath.lua")
do
local toolchain = daukle.config.toolchains and daukle.config.toolchains.gradle
if toolchain == nil then
error('daukle.config.toolchains.gradle does not exist: maven resolved for "'
.. 'gradle" but the manifest declares no such toolchain', 0)
end
local classpath = toolchain.classpath or {}
classpath[#classpath + 1] = {
url = "https://repo1.maven.org/maven2/org/apache/commons/commons-lang3/3.17.0/commons-lang3-3.17.0.jar",
sha256 = "6ee731df5c8e5a2976a1ca023b6bb320ea8d3539fbe64c8a1d5cb765127c33b4",
as = "commons-lang3 3.17.0",
}
toolchain.classpath = classpath
local pluginClasspath = toolchain.pluginClasspath or {}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/com/gradleup/shadow/shadow-gradle-plugin/9.3.2/shadow-gradle-plugin-9.3.2.jar",
sha256 = "3eb7d9a75357bd6e2dbe4ea67feb2f61a44e02b633943ba3b3bf8e6eec4fbc1f",
as = "shadow-gradle-plugin 9.3.2",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/org/apache/ant/ant/1.10.15/ant-1.10.15.jar",
sha256 = "763acda4a69588c9ea8817a952851ff0c2fc4bffa1d081c2565dc407f29d5794",
as = "ant 1.10.15",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/commons-codec/commons-codec/1.21.0/commons-codec-1.21.0.jar",
sha256 = "4da851cb6abfb98bfe9eb77c5e5fc47f5414fa28b94e21b7fd9a646705dc167f",
as = "commons-codec 1.21.0",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/commons-io/commons-io/2.21.0/commons-io-2.21.0.jar",
sha256 = "7d643a2afea8b058b762aa6fb90e5b256f6c729739f8b3784c3370ddc609e88d",
as = "commons-io 2.21.0",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/org/apache/logging/log4j/log4j-core/2.25.3/log4j-core-2.25.3.jar",
sha256 = "362b7fcb65b73aa46cc4bc53abf4eb216f444a83b5d1a037cb6fdfff0ae9f0f9",
as = "log4j-core 2.25.3",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/org/vafer/jdependency/2.15/jdependency-2.15.jar",
sha256 = "f28343d5a0d68e9618788e366df5a0443806195539172ed1d3205c62be4e4193",
as = "jdependency 2.15",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/org/jdom/jdom2/2.0.6.1/jdom2-2.0.6.1.jar",
sha256 = "0b20f45e3a0fd8f0d12cdc5316b06776e902b1365db00118876f9175c60f302c",
as = "jdom2 2.0.6.1",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-metadata-jvm/2.3.20-RC/kotlin-metadata-jvm-2.3.20-RC.jar",
sha256 = "1159180ced532723f3d305b34c84d653bb09e253e2976aac17342d33d806bbf6",
as = "kotlin-metadata-jvm 2.3.20-RC",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/org/codehaus/plexus/plexus-utils/4.0.2/plexus-utils-4.0.2.jar",
sha256 = "8957274e75fe2c278b1428dd16a0daeee1dd38152cb6eff816177ac28fccb697",
as = "plexus-utils 4.0.2",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/org/codehaus/plexus/plexus-xml/4.1.1/plexus-xml-4.1.1.jar",
sha256 = "e09b1fcc46da744a0e4dabe703f287ce133b631ea95c6e1a8a82ebad2b1a2815",
as = "plexus-xml 4.1.1",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/org/apache/ant/ant-launcher/1.10.15/ant-launcher-1.10.15.jar",
sha256 = "5c8551990307a032336d98ddaed549a39a689f07d4d4c6b950601bf22b3d6a1b",
as = "ant-launcher 1.10.15",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/org/apache/logging/log4j/log4j-api/2.25.3/log4j-api-2.25.3.jar",
sha256 = "e886682920fa0fb9d6eb6395dcb4de088443f8646c89c5e5846e168e327f406f",
as = "log4j-api 2.25.3",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-stdlib/2.3.20-RC/kotlin-stdlib-2.3.20-RC.jar",
sha256 = "738887d16a305ac73d7f256152f1019984c345f3862601f1ee9328bbeb761fc8",
as = "kotlin-stdlib 2.3.20-RC",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/org/apache/maven/maven-xml/4.0.0-rc-5/maven-xml-4.0.0-rc-5.jar",
sha256 = "a4b7ad3e3410e0feb6438ebb6231c8e02449cd02fcf6451baed820008a103564",
as = "maven-xml 4.0.0-rc-5",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/org/jetbrains/annotations/13.0/annotations-13.0.jar",
sha256 = "ace2a10dc8e2d5fd34925ecac03e4988b2c0f851650c94b8cef49ba1bd111478",
as = "annotations 13.0",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/org/apache/maven/maven-api-xml/4.0.0-rc-5/maven-api-xml-4.0.0-rc-5.jar",
sha256 = "358851a87edd0ddd566a437470ea021ba851a0487ec4d14825ff04db03ff5877",
as = "maven-api-xml 4.0.0-rc-5",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/com/fasterxml/woodstox/woodstox-core/7.1.1/woodstox-core-7.1.1.jar",
sha256 = "02b9d022e9d47704ff8a7a859a0dbfd3b2882a8311eb7ff1e180f760ccda2712",
as = "woodstox-core 7.1.1",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/org/codehaus/woodstox/stax2-api/4.2.2/stax2-api-4.2.2.jar",
sha256 = "a61c48d553efad78bc01fffc4ac528bebbae64cbaec170b2a5e39cf61eb51abe",
as = "stax2-api 4.2.2",
}
pluginClasspath[#pluginClasspath + 1] = {
url = "https://plugins.gradle.org/m2/org/apache/maven/maven-api-annotations/4.0.0-rc-5/maven-api-annotations-4.0.0-rc-5.jar",
sha256 = "1f7325c01a0ac5a5206caff09fa388520c6505dab850178f452d2c6aad3d3c83",
as = "maven-api-annotations 4.0.0-rc-5",
}
toolchain.pluginClasspath = pluginClasspath
end
src/main/java/com/example/Main.java
package com.example;
import org.apache.commons.lang3.StringUtils;
public final class Main {
public static void main(String[] args) {
System.out.println(StringUtils.capitalize("hello from a fat jar"));
}
}