Skip to content

Instantly share code, notes, and snippets.

@jacobemcken
Created December 21, 2023 18:49
Show Gist options
  • Save jacobemcken/86bf32af31b386457209e736ffdbfd73 to your computer and use it in GitHub Desktop.
Save jacobemcken/86bf32af31b386457209e736ffdbfd73 to your computer and use it in GitHub Desktop.
Script helping to install newer Java versions on Netlify required by Shadow-cljs
#!/bin/bash
CACHE_DIR=$NETLIFY_BUILD_BASE/cache
rm -rf $HOME/.m2/
cp -a $NETLIFY_BUILD_BASE/cache/.m2/ $HOME/.m2/
JAVA_DOWNLOAD_URL="https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz"
JAVA_RELEASE=jdk-17.0.2 # Must match directory inside archive in JAVA_DOWNLOAD_URL
currentver="$(java -version 2>&1 |head -n1 | cut -d'"' -f2 |cut -d'.' -f1)"
requiredver="11" # Shadow-cljs requires a minimum of Java 11
# Version check shamelessly copied from StackOverflow:
# https://unix.stackexchange.com/a/285928
if [ ! "$(printf '%s\n' "$requiredver" "$currentver" | sort -V | head -n1)" = "$requiredver" ]; then
echo "Java version 11 is required as minimum by Shadow-cljs (found Java version $currentver)"
if [ ! -d "$CACHE_DIR/$JAVA_RELEASE" ]; then
echo "Downloading $JAVA_RELEASE since it isn't available in cache"
wget --quiet -O openjdk.tar.gz $JAVA_DOWNLOAD_URL
tar xf openjdk.tar.gz --directory $CACHE_DIR
fi
echo "Enabling $JAVA_RELEASE from cache, by making it available on PATH"
export PATH=$CACHE_DIR/$JAVA_RELEASE/bin:$PATH
fi
{
"scripts": {
"release": ". ./java.sh && npx shadow-cljs release app",
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment