Last active
November 22, 2019 14:38
-
-
Save gnarroway/888ad96a2b7135b2ef2648b3880f36ec to your computer and use it in GitHub Desktop.
Create an uberjar from a clojure classpath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assembles dependencies from a classpath generated by clojure -Spath | |
# | |
# Usage: ./assemble.sh $(clojure -R:dev -Spath) | |
classpath=$1 | |
# 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 | |
else | |
echo "Ignoring $path" | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 https://clojure.org/guides/deps_and_cli#aot_compilation for details | |
jar --create --file target/app.jar --main-class app.core -C target/classes/ . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, could you give a sample
deps.edn
file for this?