-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathkotlinw
More file actions
executable file
·29 lines (23 loc) · 1.21 KB
/
kotlinw
File metadata and controls
executable file
·29 lines (23 loc) · 1.21 KB
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
#!/bin/sh
set -e
ROOT_DIR="$(dirname "$0")"
KOTLIN_VERSION="$(grep -m 1 '^kotlin \?=' "$ROOT_DIR/gradle/libs.versions.toml" | cut -d'"' -f2)"
INSTALLATION_DIR="${HOME}/.kotlinw/${KOTLIN_VERSION}"
BINARY_DIR="${INSTALLATION_DIR}/kotlinc/bin"
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"
SCRIPT_FILE="$1"
# will remove the first element of the $@ arguments array since we read it already above
shift
# uses kotlinc instead of kotlin because the latter doesn't allow specifying a jvm target and defaults to Java 8
# the -- between SCRIPT_FILE and the other arguments is there so that the arguments are treated as arguments to the
# script and not to kotlinc
"${BINARY_DIR}/kotlinc" "-script" "$SCRIPT_FILE" "--" "${@}"