Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Create an uberjar from a clojure classpath
# Assembles dependencies from a classpath generated by clojure -Spath
# Usage: ./ $(clojure -R:dev -Spath)
# Clean output dir
mkdir -p target/classes
rm -rf target/classes/*
for path in ${classpath//:/ }; do
if [[ -d $path ]]; then
# Copy our source paths
echo "Copying $path"
cp -R $path/* target/classes/
elif [[ -f $path && $path == *.jar ]]; then
# Unpack jars, never overwriting (to retain classpath precedence)
# Also exclude some extensions that will cause issues bundling signed jars
echo "Unpacking $path"
unzip -n -qq $path -x META-INF/*.SF META-INF/*.RSA META-INF/*.DSA -d target/classes > /dev/null 2>&1
echo "Ignoring $path"
# Optional step
# Add your project pom with correct version to the output
# Assumes you have a :project-version in your deps.edn
version=$(cat deps.edn | grep :project-version | cut -d'"' -f2)
clojure -Spom
sed -i '' "s/<version>.*<\/version>/<version>$version<\/version>/" pom.xml
mkdir -p target/classes/META-INF/maven/foo/foo
cp pom.xml target/classes/META-INF/maven/foo/foo/
# Creates an executable jar, which can be run with:
# java -jar target/app.jar
# java -cp target/app.jar clojure.main -m app.core
# --main-class expects that you have a main class which you compiled before assembling.
# clj -e "(compile 'app.core)"
# See for details
jar --create --file target/app.jar --main-class app.core -C target/classes/ .

This comment has been minimized.

Copy link

DogLooksGood commented Nov 22, 2019

Hi, could you give a sample deps.edn file for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.