-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added support for changing OpenJDK versions
* feat: added command to change OpenJDK version * feat: Improve UX * test: explicitely declared java_ver and javac_ver
- Loading branch information
1 parent
cbdf150
commit 50be37b
Showing
2 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
description: | | ||
Change default java version from OpenJDK v11. | ||
parameters: | ||
java-version: | ||
type: integer | ||
default: 8 | ||
description: | | ||
The version of OpenJDK to change to | ||
steps: | ||
- run: | ||
command: | | ||
CURRENT_JAVA_VER="$( java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1 )" | ||
CURRENT_JAVAC_VER="$( javac -version 2>&1 | head -1 | cut -f 2- -d ' ' | sed '/^1\./s///' | cut -d'.' -f1 )" | ||
echo "Current Java Version: $CURRENT_JAVA_VER" | ||
echo "Current Java Compiler Version : $CURRENT_JAVAC_VER" | ||
if [ "$CURRENT_JAVA_VER" -ne <<parameters.java-version>> ]; then | ||
if [ <<parameters.java-version>> -eq 8 ] || [ <<parameters.java-version>> -eq 11 ]; then | ||
if [ <<parameters.java-version>> -eq 8 ]; then | ||
sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java | ||
else | ||
sudo update-alternatives --set java /usr/lib/jvm/java-11-openjdk-amd64/bin/java | ||
fi | ||
sudo update-alternatives --set javac /usr/lib/jvm/java-<<parameters.java-version>>-openjdk-amd64/bin/javac | ||
else | ||
sudo apt install openjdk-<<parameters.java-version>>-jdk | ||
fi | ||
echo "export JAVA_HOME=/usr/lib/jvm/java-<<parameters.java-version>>-openjdk-amd64" >>~/.bashrc | ||
echo "export PATH=$JAVA_HOME/bin:$PATH" >>~/.bashrc | ||
fi | ||
NEW_JAVA_VER="$( java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1 )" | ||
NEW_JAVAC_VER="$( javac -version 2>&1 | head -1 | cut -f 2- -d ' ' | sed '/^1\./s///' | cut -d'.' -f1 )" | ||
echo "New Java Version : $NEW_JAVA_VER" | ||
echo "New Java Compiler Version : $NEW_JAVAC_VER" | ||
name: change OpenJDK version | ||
|