Maven "No compiler is provided" (JAVA_HOME is a JRE) - Fix in CI
The maven-compiler-plugin could not find a Java compiler because JAVA_HOME points at a JRE, not a JDK. A JRE ships the runtime but no javac, so compilation cannot start.
What this error means
Compilation fails immediately with No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?. Tests never run because nothing compiled.
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile)
on project app: No compiler is provided in this environment. Perhaps you are
running on a JRE rather than a JDK?Common causes
JAVA_HOME points at a JRE
A JRE directory has no bin/javac and no lib/tools.jar/compiler module. Maven looks under JAVA_HOME for the compiler and finds none.
A JRE-only image or package was installed
Base images or packages named *-jre install the runtime only. The runner can run Java but cannot compile it.
How to fix it
Install a JDK and point JAVA_HOME at it
Provision a full JDK so javac is present, then confirm JAVA_HOME.
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- run: |
echo "JAVA_HOME=${JAVA_HOME}"
"${JAVA_HOME}/bin/javac" -versionFix JAVA_HOME in a container build
On a bare image, install the JDK package (not the JRE) and export JAVA_HOME to it.
apt-get update && apt-get install -y openjdk-21-jdk
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
export PATH="${JAVA_HOME}/bin:${PATH}"How to prevent it
- Always install a full JDK (not a JRE) on build runners and assert javac with
"${JAVA_HOME}/bin/javac" -versionearly in the job.