When using custom docker build :
Dockerfile :
FROM fedora:34
ENV TERM=xterm
ENV JAVA_HOME=/usr/java/jdk-11.0.11/
ENV JDK_HOME=/usr/java/jdk-11.0.11/
ENV JAVAC=/usr/java/jdk-11.0.11/bin/javac
ENV PATH=$JAVA_HOME:$JAVA_HOME/bin:$PATH
RUN dnf update -y
RUN dnf upgrade -y
# Install Oracle jdk 11
COPY Fedora/jdk-11.0.11_linux-x64_bin.rpm /root/jdk.rpm
RUN rpm --force --nosignature -ivh jdk.rpm
RUN rm *
RUN dnf install -y maven
ENTRYPOINT /bin/bash
‘mvn -B -DskipTests clean package’ works as expected on local docker
meanwhile on circle ci using this configuration :
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1
jobs:
build-and-test:
docker:
- image: .../circle_ci_builder
steps:
# Checkout git project
- checkout
# Build maven
- run:
name: build
command: mvn -B -DskipTests clean package
...
build fails with this error :
#!/bin/bash -eo pipefail mvn -B -DskipTests clean package
/usr/bin/mvn: Failed to set JAVACMD
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
Exited with code exit status 1
CircleCI received exit code 1
So i managed to see what’s happening and i changed my mvn script and rebuilt my docker this way :
mvn script from line 105 i added echo $JAVACMD and echo $JAVA_HOME:
if [ -z "$JAVA_HOME" ] ; then
JAVACMD=`which java`
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
echo "The JAVA_HOME environment variable is not defined correctly" >&2
echo "This environment variable is needed to run this program" >&2
echo "NB: JAVA_HOME should point to a JDK not a JRE" >&2
echo $JAVA_HOME
echo $JAVACMD
$JAVACMD -version
exit 1
fi
and now i got this error :
#!/bin/bash -eo pipefail mvn -B -DskipTests clean package
/usr/bin/mvn: Failed to set JAVACMD
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
/usr/java/jdk-11.0.11
/usr/java/jdk-11.0.11/bin/java
java version "11.0.11" 2021-04-20 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.11+9-LTS-194) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.11+9-LTS-194, mixed mode) Exited with code exit status 1
CircleCI received exit code 1
So apparantly my JAVA_HOME is fine also my JAVACMD is executable since $JAVACMD -version returns version of oracle JDK the problem is that at maven script if [ ! -x "$JAVACMD" ]
statment returns true as if $JAVACMD wasen’t executable file
if i remove this check from mvn script my circle ci job builds well my project but i don’t think is good idea to modify mvn script by hand.
If someone have a fix for this bug would be cool to share it :).
PS. I tried to build with cmig/openjdk:11.0 and mvn clean install works fine so i checked the mvn script inside of this docker image and is completly the same one as the fedora original script. i see no diff between two of them but the mine still doesn’t works correctly so i fear that if [ -x ] statements on any other script wont work :’( nither.