Skip to content

Commit 90d5a07

Browse files
committed
Changed as per comment to get list of available maven versions using sdk list and installed the latest stable version.
1 parent dc1c3fc commit 90d5a07

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

src/java/install.sh

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -342,22 +342,17 @@ fi
342342

343343
# Install Maven
344344
if [[ "${INSTALL_MAVEN}" = "true" ]] && ! mvn --version > /dev/null 2>&1; then
345-
if [ "${MAVEN_VERSION}" = "3.9.9" ] || [ "${MAVEN_VERSION}" = "latest" ]; then
346-
echo "Manually installing Maven 3.9.9..."
347-
curl -fsSL https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip -o /tmp/apache-maven-3.9.9-bin.zip
348-
unzip -q /tmp/apache-maven-3.9.9-bin.zip -d /opt
349-
ln -sfn /opt/apache-maven-3.9.9 /opt/maven
350-
chown -R ${USERNAME}: /opt/apache-maven-3.9.9 /opt/maven
351-
# Set up environment variables
352-
echo "export MAVEN_HOME=/opt/maven" >> /etc/profile.d/maven.sh
353-
echo "export PATH=\$MAVEN_HOME/bin:\$PATH" >> /etc/profile.d/maven.sh
354-
chmod +x /etc/profile.d/maven.sh
355-
# Source for current shell
356-
export MAVEN_HOME=/opt/maven
357-
export PATH=$MAVEN_HOME/bin:$PATH
358-
else
359-
sdk_install maven ${MAVEN_VERSION}
345+
MAVEN_VERSION_TO_INSTALL="${MAVEN_VERSION}"
346+
if [ "${MAVEN_VERSION}" = "latest" ]; then
347+
# Get the latest stable Maven version from sdk list
348+
MAVEN_VERSION_TO_INSTALL=$(
349+
su ${USERNAME} -c ". ${SDKMAN_DIR}/bin/sdkman-init.sh && \
350+
sdk list maven | grep -E '^[[:space:]]*[0-9]+(\.[0-9]+)*[[:space:]]' | grep -v -- '-' | head -n 1 | awk '{print \$1}'"
351+
)
352+
echo "Resolved latest stable Maven version: ${MAVEN_VERSION_TO_INSTALL}"
360353
fi
354+
355+
sdk_install maven "${MAVEN_VERSION_TO_INSTALL}"
361356
fi
362357

363358
# Install Groovy

0 commit comments

Comments
 (0)