From 5385a075ebec9e2fe560cb4a482ed0f8514518a0 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Thu, 27 Aug 2020 10:25:56 +0300 Subject: [PATCH] Set javac version 1.8 on Ubuntu 16.04 (#1483) * set up javac version * fix update-java-alternatives * add version check * change java check * fix checks and position of update-java-alternatives * resolve comments Co-authored-by: Dmitry Shibanov --- images/linux/scripts/installers/java-tools.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/images/linux/scripts/installers/java-tools.sh b/images/linux/scripts/installers/java-tools.sh index b64c576c..7ec94b73 100644 --- a/images/linux/scripts/installers/java-tools.sh +++ b/images/linux/scripts/installers/java-tools.sh @@ -10,6 +10,15 @@ source $HELPER_SCRIPTS/os.sh set -e +function javaTool { + if [[ "$2" =~ ([1]{0,1}.)?$DEFAULT_JDK_VERSION.* ]]; then + echo "$1 $2 is equal to default one $DEFAULT_JDK_VERSION" + else + echo "$1 $2 is not equal to default one $DEFAULT_JDK_VERSION" + exit 1 + fi +} + # Install GPG Key for Adopt Open JDK. See https://adoptopenjdk.net/installation.html wget -qO - "https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public" | apt-key add - add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/ @@ -38,6 +47,11 @@ apt-get -y install adoptopenjdk-8-hotspot=\* apt-get -y install adoptopenjdk-11-hotspot=\* # Set Default Java version. +if isUbuntu16; then + # issue: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=825987 + # stackoverflow: https://askubuntu.com/questions/1187136/update-java-alternatives-only-java-but-not-javac-is-changed + sed -i 's/(hl|jre|jdk|plugin|DUMMY) /(hl|jre|jdk|jdkhl|plugin|DUMMY) /g' /usr/sbin/update-java-alternatives +fi update-java-alternatives -s /usr/lib/jvm/adoptopenjdk-${DEFAULT_JDK_VERSION}-hotspot-amd64 echo "JAVA_HOME_8_X64=/usr/lib/jvm/adoptopenjdk-8-hotspot-amd64" | tee -a /etc/environment @@ -85,6 +99,11 @@ for cmd in gradle java javac mvn ant; do fi done +javaVersion=$(java -version |& head -n 1 | cut -d\" -f 2) +javaTool "Java" $javaVersion +javacVersion=$(javac -version |& cut -d" " -f2) +javaTool "Javac" $javacVersion + # Document what was added to the image echo "Lastly, documenting what we added to the metadata file" if isUbuntu16 || isUbuntu18 ; then