[build.myproject]
command = '''
# Create the destination directories
mkdir -p "$out"/{lib,bin}
# Build a fat jar with gradle using the shadowJar plugin
gradle shadowJar
# Copy the newly built jars to $out
cp build/libs/*.jar $out/lib
# Build a script that gets the absolute path to the JAR at run time
# and then calls 'java -jar $JAR_PATH'
echo '#!/usr/bin/env bash' > $out/bin/myproject
echo 'SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"' >> $out/bin/myproject
echo 'JAR_PATH="$SCRIPT_DIR/../lib/myproject-app-all.jar"' >> $out/bin/myproject
echo 'exec java -jar "$JAR_PATH" "$@"' >> $out/bin/myproject
# Ensure that the script has the correct permissions
chmod 755 $out/bin/myproject
'''