dotfiles/sdkman-darwin-setup
Ahmad Ansori Palembani 2ee7dcd7a0
feat: Script for SDKMAN! java setup on macOS
macOS find JAVA_HOME differently than other OS for some reason, and it
doesn't seems to be documented either, but basically macOS will detect
latest JVM(Platform) in "/Library/Java/JavaVirtualMachines" (or
"~/Library/Java/JavaVirtualMachines"). To do detect the version they
look up Info.plist in "<java-distro>/Contents", if it's the newest it
then print the "Home" dir path of that distro.
(e.g. "/Users/<user>/Library/Java/JavaVirtualMachines/zulu-13.0.0/Contents/Home")

Not sure why SDKMAN! didn't handle this themselves, but whatever. This
solve my issue when trying to run KMM iOS App

REF: https://stackoverflow.com/questions/76523553/how-to-make-usr-libexec-java-home-find-jdk-installed-using-sdkman-on-macos
2024-07-08 12:55:03 +07:00

26 lines
1.1 KiB
Bash
Executable file

#!/bin/sh
mkdir -p "$HOME/Library/Java/JavaVirtualMachines/sdkman-current/Contents"
ln -si $HOME/.sdkman/candidates/java/current "$HOME/Library/Java/JavaVirtualMachines/sdkman-current/Contents/Home"
echo "<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>sdkman.current</string>
<key>CFBundleName</key>
<string>SDKMAN Current JDK</string>
<key>JavaVM</key>
<dict>
<key>JVMPlatformVersion</key>
<string>9999</string>
<key>JVMVendor</key>
<string>Homebrew</string>
<key>JVMVersion</key>
<string>9999</string>
</dict>
</dict>
</plist>" > "$HOME/Library/Java/JavaVirtualMachines/sdkman-current/Contents/__tmp"
mv -i "$HOME/Library/Java/JavaVirtualMachines/sdkman-current/Contents/__tmp" "$HOME/Library/Java/JavaVirtualMachines/sdkman-current/Contents/Info.plist"
rm "$HOME/Library/Java/JavaVirtualMachines/sdkman-current/Contents/__tmp" 2>/dev/null