-
Notifications
You must be signed in to change notification settings - Fork 9
/
kotlinw
executable file
·51 lines (43 loc) · 1.77 KB
/
kotlinw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
set -e
ROOT_DIR="$(dirname $0)"
JDK_VERSION="$(grep -s 'java-gradle' $ROOT_DIR/gradle/libs.versions.toml | cut -d'"' -f2)"
if [ -z "$JDK_VERSION" ]; then
JDK_VERSION="21"
fi
KOTLIN_VERSION="1.9.0"
if [ -f "$ROOT_DIR/gradle/libs.versions.toml" ]; then
KOTLIN_VERSION="$(grep -m 1 '^kotlin \?=' $ROOT_DIR/gradle/libs.versions.toml | cut -d'"' -f2)"
fi
INSTALLATION_DIR="${HOME}/.kotlinw/${KOTLIN_VERSION}"
BINARY_DIR="${INSTALLATION_DIR}/kotlinc/bin"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if [ -d "/usr/lib/jvm/zulu-$JDK_VERSION-amd64" ]; then
JAVA_HOME="/usr/lib/jvm/zulu-$JDK_VERSION-amd64/"
elif [ -d "/usr/lib/jvm/zulu$JDK_VERSION-ca-amd64" ]; then
JAVA_HOME="/usr/lib/jvm/zulu$JDK_VERSION-ca-amd64/"
else
java --version
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
JAVA_HOME="/Library/Java/JavaVirtualMachines/zulu-$JDK_VERSION.jdk/Contents/Home"
if [ ! -d "/Library/Java/JavaVirtualMachines/zulu-${JDK_VERSION}.jdk/Contents/Home" ]; then
echo "Installing JDK ${JDK_VERSION} (you may be prompted for your password)..."
brew tap mdogan/zulu
brew install --cask "zulu-jdk${JDK_VERSION}"
fi
else
echo "Only macOS and Linux are supported."
exit 1
fi
if [ ! -f "${BINARY_DIR}/kotlin" ]; then
echo "Downloading Kotlin ${KOTLIN_VERSION}"
mkdir -p ${INSTALLATION_DIR}
temp_file=$(mktemp /tmp/kotlin.zip.XXXXXX)
curl -sLo "${temp_file}" "https://github.com/JetBrains/kotlin/releases/download/v${KOTLIN_VERSION}/kotlin-compiler-${KOTLIN_VERSION}.zip"
unzip -q "${temp_file}" -d "${INSTALLATION_DIR}"
rm -f "${temp_file}"
fi
# this works around an issue where the Kotlin compiler used by ktlint accesses code that JDK 12+ don't allow access to
export JAVA_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED"
"${BINARY_DIR}/kotlin" "$@"