<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Noah</title>
    <description>The latest articles on DEV Community by Noah (@noah_1).</description>
    <link>https://dev.to/noah_1</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4269806%2F06b9dd41-e699-476c-a714-91ee3263fb03.png</url>
      <title>DEV Community: Noah</title>
      <link>https://dev.to/noah_1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/noah_1"/>
    <language>en</language>
    <item>
      <title>java -version Shows the Wrong Version on Mac</title>
      <dc:creator>Noah</dc:creator>
      <pubDate>Sun, 29 Nov 2026 08:27:59 +0000</pubDate>
      <link>https://dev.to/noah_1/java-version-shows-the-wrong-version-on-mac-24ii</link>
      <guid>https://dev.to/noah_1/java-version-shows-the-wrong-version-on-mac-24ii</guid>
      <description>&lt;p&gt;You installed a newer JDK, opened a fresh Terminal window, ran &lt;code&gt;java -version&lt;/code&gt;, and still saw JDK 8, JDK 11, or a vendor you did not expect. The install probably worked. The more common problem is that the &lt;code&gt;java&lt;/code&gt; command is resolving a different JDK from the one you think you selected.&lt;/p&gt;

&lt;p&gt;This walkthrough is ordered like a diagnosis rather than an installation guide. You will inventory what macOS can see, follow the shell startup files that set your environment, trace &lt;code&gt;PATH&lt;/code&gt; and command caching, check version-manager shims, and finally compare the terminal’s JVM with the one your IDE and Gradle use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What java -version Actually Reports&lt;/li&gt;
&lt;li&gt;Step 1: Inventory the JDKs macOS Can See&lt;/li&gt;
&lt;li&gt;Step 2: Check Which Shell Startup File Runs&lt;/li&gt;
&lt;li&gt;Step 3: Trace PATH Precedence and Cached Commands&lt;/li&gt;
&lt;li&gt;Step 4: Check Version Manager Shims&lt;/li&gt;
&lt;li&gt;Step 5: Check the IDE and Gradle JVM&lt;/li&gt;
&lt;li&gt;Verification Checklist&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What java -version Actually Reports
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;java -version&lt;/code&gt; reports the JVM that the shell resolves when it looks up &lt;code&gt;java&lt;/code&gt;. It is not an inventory of every JDK on the machine, and it is not necessarily the newest JDK you installed.&lt;/p&gt;

&lt;p&gt;On macOS, &lt;code&gt;/usr/bin/java&lt;/code&gt; is a system launcher that looks for an installed JDK. &lt;a href="https://docs.oracle.com/en/java/javase/27/install/installation-jdk-macos.html" rel="noopener noreferrer"&gt;Oracle’s macOS JDK installation notes&lt;/a&gt; explain that &lt;code&gt;java -version&lt;/code&gt; shows the default JDK and that &lt;code&gt;/usr/bin/java&lt;/code&gt; will find the newest JDK installed. That default can still be overridden by an older &lt;code&gt;java&lt;/code&gt; earlier in your &lt;code&gt;PATH&lt;/code&gt;, and a stale &lt;code&gt;JAVA_HOME&lt;/code&gt; can affect launchers and build tools that consult it.&lt;/p&gt;

&lt;p&gt;This distinction explains a common surprise: &lt;code&gt;echo $JAVA_HOME&lt;/code&gt; may point at JDK 17 while &lt;code&gt;java -version&lt;/code&gt; prints JDK 11, or &lt;code&gt;JAVA_HOME&lt;/code&gt; may be empty while &lt;code&gt;java&lt;/code&gt; works perfectly. &lt;code&gt;JAVA_HOME&lt;/code&gt; is a convention used by build tools and scripts. The &lt;code&gt;java&lt;/code&gt; command itself is found through &lt;code&gt;PATH&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Also compare &lt;code&gt;java -version&lt;/code&gt; with &lt;code&gt;javac -version&lt;/code&gt;. If they disagree, one of them is coming from a different directory. The same applies to the vendor name and build string: “OpenJDK” and “Oracle” can both be Java 17, but they are not the same installation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Inventory the JDKs macOS Can See
&lt;/h2&gt;

&lt;p&gt;Before changing shell files, establish a baseline. Ask the macOS Java helper what it can find:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;/usr/libexec/java_home -V
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The capital &lt;code&gt;-V&lt;/code&gt; lists the JVMs recognized by the helper. Read the version, architecture, vendor, and full path for each entry. On Apple Silicon, pay attention to &lt;code&gt;arm64&lt;/code&gt; versus &lt;code&gt;x86_64&lt;/code&gt;; a correct version number with the wrong architecture can still cause confusing behavior.&lt;/p&gt;

&lt;p&gt;If the list is empty, macOS cannot see the JDK yet, so fix that before editing shell files. If the command fails or its output looks wrong, try the same check with &lt;code&gt;JAVA_HOME&lt;/code&gt; removed for that one command, since a stale value can affect the helper: &lt;code&gt;env -u JAVA_HOME /usr/libexec/java_home -V&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To test a specific version without changing your environment, use the helper’s &lt;code&gt;-v&lt;/code&gt; and &lt;code&gt;--exec&lt;/code&gt; options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;/usr/libexec/java_home -v 11 --exec java -version
/usr/libexec/java_home -v 11 --exec javac -version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Oracle documentation also shows this &lt;code&gt;java_home -v &amp;lt;version&amp;gt; --exec&lt;/code&gt; pattern for running a different JDK than the default. If the expected JDK appears in the inventory, the installation itself is probably fine and the problem is selection. If it does not appear, fix visibility first.&lt;/p&gt;

&lt;p&gt;If JDK 11 is the version you expect, the &lt;a href="https://javathinking.com/blog/jdk-11-install-mac/" rel="noopener noreferrer"&gt;JDK 11 macOS installation guide&lt;/a&gt; shows the expected install location, &lt;code&gt;JAVA_HOME&lt;/code&gt; value, and verification output. That gives you a known-good baseline to compare against before you start editing startup files.&lt;/p&gt;

&lt;p&gt;A Homebrew installation is a frequent reason a JDK is missing from this list. Homebrew keeps its OpenJDK formulae keg-only, so they do not replace the system Java tools automatically. &lt;a href="https://docs.brew.sh/Language-Runtimes-and-Packages" rel="noopener noreferrer"&gt;Homebrew’s notes on making a JDK visible to macOS&lt;/a&gt; explain that the caveats may give you a command to link the JDK bundle into &lt;code&gt;/Library/Java/JavaVirtualMachines&lt;/code&gt;, which is where macOS tools look. A typical link command looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo ln -sfn &lt;span class="s2"&gt;"$(brew --prefix openjdk@11)/libexec/openjdk.jdk"&lt;/span&gt; \
  /Library/Java/JavaVirtualMachines/openjdk-11.jdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the path printed by &lt;code&gt;brew info&lt;/code&gt; for your formula and Mac. After linking, run &lt;code&gt;/usr/libexec/java_home -V&lt;/code&gt; again. Do not assume that &lt;code&gt;brew install openjdk@11&lt;/code&gt; alone made the JDK visible to &lt;code&gt;java_home&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Check Which Shell Startup File Runs
&lt;/h2&gt;

&lt;p&gt;macOS has used zsh as the default login and interactive shell since macOS 10.15, and &lt;a href="https://support.apple.com/en-us/102360" rel="noopener noreferrer"&gt;Apple’s guide to zsh as the default shell&lt;/a&gt; maps &lt;code&gt;.zprofile&lt;/code&gt; to login sessions and &lt;code&gt;.zshrc&lt;/code&gt; to each new Terminal session. That matters because an export placed in the wrong file can appear to work only after you manually run &lt;code&gt;source&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://zsh.sourceforge.io/Doc/Release/Files.html" rel="noopener noreferrer"&gt;The zsh startup file documentation&lt;/a&gt; gives the exact order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;/etc/zshenv&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;~/.zshenv&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/etc/zprofile&lt;/code&gt;, then &lt;code&gt;~/.zprofile&lt;/code&gt;, for login shells&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/etc/zshrc&lt;/code&gt;, then &lt;code&gt;~/.zshrc&lt;/code&gt;, for interactive shells&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/etc/zlogin&lt;/code&gt;, then &lt;code&gt;~/.zlogin&lt;/code&gt;, for login shells&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;On a default macOS installation, a new Terminal window starts a login, interactive zsh, so both &lt;code&gt;.zprofile&lt;/code&gt; and &lt;code&gt;.zshrc&lt;/code&gt; are normally read. A non-interactive shell, such as a script started by a build tool, does not read &lt;code&gt;.zshrc&lt;/code&gt;. That is one reason a setting can work in Terminal but not in an IDE or automated build.&lt;/p&gt;

&lt;p&gt;Typical symptoms and their file-level causes:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Symptom&lt;/th&gt;
&lt;th&gt;Likely cause&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;echo $JAVA_HOME&lt;/code&gt; is blank in a new Terminal, but works after &lt;code&gt;source ~/.zshrc&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;The export is only in a file the new shell did not read, or you set it manually in the old shell&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;You edited &lt;code&gt;.bash_profile&lt;/code&gt; but the shell is zsh&lt;/td&gt;
&lt;td&gt;zsh does not read &lt;code&gt;.bash_profile&lt;/code&gt;; use &lt;code&gt;.zprofile&lt;/code&gt; or &lt;code&gt;.zshrc&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;It works over SSH but not in the IDE&lt;/td&gt;
&lt;td&gt;The IDE may not be using the same login shell environment&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;It works in one Terminal tab but not another after a &lt;code&gt;cd&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;A directory-specific file or version-manager hook is changing the value&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If you use bash instead of zsh, the same ideas apply with different filenames: login shells read &lt;code&gt;~/.bash_profile&lt;/code&gt;, while interactive non-login shells read &lt;code&gt;~/.bashrc&lt;/code&gt;. A bash export in &lt;code&gt;.bash_profile&lt;/code&gt; will not help a zsh session, and a zsh export in &lt;code&gt;.zshrc&lt;/code&gt; will not help a non-interactive bash script.&lt;/p&gt;

&lt;p&gt;To make a version selection persistent, copy the JDK home path from your inventory into the startup file that matches the shell sessions you care about. For example, in &lt;code&gt;~/.zprofile&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;JAVA_HOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/Library/Java/JavaVirtualMachines/temurin-11.jdk/Contents/Home"&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$JAVA_HOME/bin:$PATH"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the exact path from your inventory; do not guess a version-numbered directory. If you need the value in non-login interactive shells too, put the block in &lt;code&gt;~/.zshrc&lt;/code&gt; instead. Do not add it to both files unless you guard against duplicate &lt;code&gt;PATH&lt;/code&gt; entries. Check the final value rather than assuming the file you edited wins, because a later startup file can reorder &lt;code&gt;PATH&lt;/code&gt; again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Trace PATH Precedence and Cached Commands
&lt;/h2&gt;

&lt;p&gt;The first matching &lt;code&gt;java&lt;/code&gt; on &lt;code&gt;PATH&lt;/code&gt; wins. Print the candidates instead of guessing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$PATH"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; tr &lt;span class="s1"&gt;':'&lt;/span&gt; &lt;span class="s1"&gt;'\n'&lt;/span&gt;
&lt;span class="nb"&gt;type&lt;/span&gt; -a java
&lt;span class="nb"&gt;type&lt;/span&gt; -a javac
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;type -a&lt;/code&gt; shows every match in order, including aliases, functions, and hashed commands. If an old JDK’s &lt;code&gt;bin&lt;/code&gt; directory appears before the JDK you want, that old &lt;code&gt;java&lt;/code&gt; will win even if &lt;code&gt;JAVA_HOME&lt;/code&gt; points somewhere newer.&lt;/p&gt;

&lt;p&gt;A stale &lt;code&gt;JAVA_HOME&lt;/code&gt; is a common source of this problem. If a startup file contains:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$JAVA_HOME/bin:$PATH"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and &lt;code&gt;JAVA_HOME&lt;/code&gt; still points at JDK 8, that line puts JDK 8 in front of everything else. Change &lt;code&gt;JAVA_HOME&lt;/code&gt; first, then rebuild the path, or set the explicit JDK path.&lt;/p&gt;

&lt;p&gt;The shell also caches command locations. If you change &lt;code&gt;PATH&lt;/code&gt; in the current shell and &lt;code&gt;java&lt;/code&gt; still resolves to the old binary, clear the cache. In zsh, whose &lt;a href="https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Commands.html" rel="noopener noreferrer"&gt;builtin command reference&lt;/a&gt; documents &lt;code&gt;rehash&lt;/code&gt; as the same as &lt;code&gt;hash -r&lt;/code&gt;, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rehash
&lt;span class="nb"&gt;type&lt;/span&gt; -a java
java -version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In bash, use &lt;code&gt;hash -r&lt;/code&gt;. Then check &lt;code&gt;type -a java&lt;/code&gt; again. A new Terminal window also clears this cache because it starts a new shell.&lt;/p&gt;

&lt;p&gt;One more place to look is &lt;code&gt;/usr/bin/java&lt;/code&gt; itself. If your &lt;code&gt;PATH&lt;/code&gt; contains &lt;code&gt;/usr/bin&lt;/code&gt; before any JDK &lt;code&gt;bin&lt;/code&gt; directory, the system launcher decides which JDK to use. That may be the newest JDK in &lt;code&gt;/Library/Java/JavaVirtualMachines&lt;/code&gt;, but it will not see a Homebrew keg that was never linked there, and it will not see an SDKMAN or jenv installation unless that tool has put its own shims earlier in &lt;code&gt;PATH&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Check Version Manager Shims
&lt;/h2&gt;

&lt;p&gt;If you use jenv, the shim directory is probably doing the selection. A shim is a small wrapper that chooses the real JDK and then hands off to it. &lt;a href="https://github.com/jenv/jenv" rel="noopener noreferrer"&gt;jenv’s README&lt;/a&gt; explains that it sets &lt;code&gt;JAVA_HOME&lt;/code&gt; globally, locally, or per shell, and that it needs to be initialized in your shell with &lt;code&gt;eval "$(jenv init -)"&lt;/code&gt;. The export plugin is what makes jenv set &lt;code&gt;JAVA_HOME&lt;/code&gt; to its shim path; enable it with &lt;code&gt;jenv enable-plugin export&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Run the diagnostic first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;jenv doctor
jenv versions
cat .java-version 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$JENV_VERSION"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;jenv doctor&lt;/code&gt; reports whether jenv is loaded and whether the &lt;code&gt;java&lt;/code&gt; in your path is actually a jenv shim. If it says the Java binary is not in the jenv shims, your &lt;code&gt;PATH&lt;/code&gt; order is wrong or jenv is not initialized in this shell.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;jenv versions&lt;/code&gt; shows the active version with an asterisk and often tells you where it was set. The precedence is global, then local, then shell, with shell highest. Set the level you need with &lt;code&gt;jenv global &amp;lt;version&amp;gt;&lt;/code&gt;, &lt;code&gt;jenv local &amp;lt;version&amp;gt;&lt;/code&gt;, or &lt;code&gt;jenv shell &amp;lt;version&amp;gt;&lt;/code&gt;; &lt;code&gt;jenv local&lt;/code&gt; writes the &lt;code&gt;.java-version&lt;/code&gt; file. A &lt;code&gt;.java-version&lt;/code&gt; file in the project directory can silently pin an old JDK every time you enter that directory. &lt;code&gt;jenv shell&lt;/code&gt; affects only the current shell and is easy to forget, so check &lt;code&gt;JENV_VERSION&lt;/code&gt; before you edit global settings.&lt;/p&gt;

&lt;p&gt;If the JDK was installed but never added to jenv, jenv cannot select it. Add the real JDK home, not the &lt;code&gt;bin&lt;/code&gt; directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;jenv add /Library/Java/JavaVirtualMachines/temurin-11.jdk/Contents/Home
jenv versions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some other version managers use the same shim principle: their initialization code puts shims ahead of the system paths, and a per-directory version file can override the global default. The useful question is not only “which JDK is installed?” but “which manager is currently in front of &lt;code&gt;PATH&lt;/code&gt;, and what version has it selected?”&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Check the IDE and Gradle JVM
&lt;/h2&gt;

&lt;p&gt;If Terminal reports the right version but your IDE or Gradle build reports an old one, the shell is no longer the only suspect. &lt;a href="https://docs.gradle.org/current/userguide/toolchains.html" rel="noopener noreferrer"&gt;Gradle’s Java toolchains documentation&lt;/a&gt; explains that the IDE has its own Gradle JVM setting, and that this is separate from the project toolchain, which is the set of Java tools for the version the build compiles against. In IntelliJ IDEA, check Settings &amp;gt; Build, Execution, Deployment &amp;gt; Gradle &amp;gt; Gradle JVM. In Eclipse, check Preferences &amp;gt; Gradle &amp;gt; Gradle JDK.&lt;/p&gt;

&lt;p&gt;Gradle can use two JVMs: the client JVM that starts the build and the daemon JVM, a long-lived background process that executes it. &lt;a href="https://docs.gradle.org/current/userguide/gradle_daemon.html" rel="noopener noreferrer"&gt;The Gradle daemon documentation&lt;/a&gt; notes that the daemon can be reused only when its Java home, version, and JVM arguments match. If Gradle still reports an old JVM, stop the daemon and inspect again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./gradlew --stop
./gradlew --version
./gradlew -q javaToolchains
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;--version&lt;/code&gt; shows the JVM running Gradle. The &lt;code&gt;javaToolchains&lt;/code&gt; task lists the JDKs Gradle detects, including where each one was found. If the build uses a toolchain, Gradle may compile with JDK 11 while &lt;code&gt;java -version&lt;/code&gt; shows JDK 21; that is not a bug. The toolchain is a build-level choice, while &lt;code&gt;java -version&lt;/code&gt; reports the shell’s JVM.&lt;/p&gt;

&lt;p&gt;Also check for a pinned JDK in &lt;code&gt;gradle.properties&lt;/code&gt;. The Gradle daemon documentation identifies &lt;code&gt;org.gradle.java.home&lt;/code&gt; as one of the settings that determines the daemon JVM. A project-level or user-level &lt;code&gt;gradle.properties&lt;/code&gt; can keep an old path alive long after the shell has moved on. Search both the project root and &lt;code&gt;~/.gradle/gradle.properties&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If only one project needs the older JDK, prefer a project-level toolchain or a local version-manager setting over a global &lt;code&gt;PATH&lt;/code&gt; edit. That keeps the rest of your tools on the default JDK while the project gets the version it needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verification Checklist
&lt;/h2&gt;

&lt;p&gt;Run these in order and compare the answers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;java -version&lt;/code&gt; and &lt;code&gt;javac -version&lt;/code&gt; — do they report the same version, vendor, and build?&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;echo $JAVA_HOME&lt;/code&gt; and &lt;code&gt;type -a java&lt;/code&gt; — does &lt;code&gt;JAVA_HOME&lt;/code&gt; point to the same JDK as the first &lt;code&gt;java&lt;/code&gt; on &lt;code&gt;PATH&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/usr/libexec/java_home -V&lt;/code&gt; — is the expected JDK listed with the right architecture?&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;echo "$PATH" | tr ':' '\n'&lt;/code&gt; — is any older JDK &lt;code&gt;bin&lt;/code&gt; directory ahead of the expected one?&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rehash&lt;/code&gt; in zsh or &lt;code&gt;hash -r&lt;/code&gt; in bash — does &lt;code&gt;java -version&lt;/code&gt; change after clearing the cache?&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;jenv doctor&lt;/code&gt;, &lt;code&gt;jenv versions&lt;/code&gt;, and &lt;code&gt;cat .java-version&lt;/code&gt; — is a shim or project file pinning an older version?&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;./gradlew --stop&lt;/code&gt;, &lt;code&gt;./gradlew --version&lt;/code&gt;, and &lt;code&gt;./gradlew -q javaToolchains&lt;/code&gt; — is Gradle using the JVM you expect?&lt;/li&gt;
&lt;li&gt;IDE Gradle JVM setting — does it match the JDK you want the IDE to use?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the terminal is correct but the IDE is wrong, fix the IDE setting. If the IDE is correct but the terminal is wrong, fix the shell startup file or &lt;code&gt;PATH&lt;/code&gt; order. If both are wrong, go back to the inventory and confirm the JDK is actually visible to macOS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;A wrong &lt;code&gt;java -version&lt;/code&gt; on macOS usually means the shell is resolving a different JDK, not that the new JDK failed to install. Start with &lt;code&gt;/usr/libexec/java_home -V&lt;/code&gt; to see what macOS can find, then check the startup file that actually runs, the order of entries in &lt;code&gt;PATH&lt;/code&gt;, and the shell’s command cache. If a version manager is in use, check its shims and per-directory version file. For IDE and Gradle mismatches, check the Gradle JVM setting and stop any stale daemon. Work through those layers in order, and you can fix the version without breaking the rest of your environment.&lt;/p&gt;

</description>
      <category>debugging</category>
      <category>java</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Docker Image with JDK 8 for Legacy CI Builds</title>
      <dc:creator>Noah</dc:creator>
      <pubDate>Sat, 28 Nov 2026 07:37:27 +0000</pubDate>
      <link>https://dev.to/noah_1/docker-image-with-jdk-8-for-legacy-ci-builds-4942</link>
      <guid>https://dev.to/noah_1/docker-image-with-jdk-8-for-legacy-ci-builds-4942</guid>
      <description>&lt;p&gt;Legacy Java 8 services still need to compile and test, but the base images many pipelines inherited are no longer maintained. A Docker image with JDK 8 for a legacy CI build should be small, pinned, and predictable: an explicit &lt;code&gt;JAVA_HOME&lt;/code&gt;, a known JDK patch level, a non-root user, and a toolchain you can verify before the build runs.&lt;/p&gt;

&lt;p&gt;This tutorial builds that image from Eclipse Temurin, pins it by digest, adds Maven with a checked download, and verifies &lt;code&gt;java&lt;/code&gt;, &lt;code&gt;javac&lt;/code&gt;, and the real build command inside the container. It also covers the Jenkins agent detail that trips up many migrations: the agent JVM and the job JDK are not the same thing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Why old JDK 8 images break builds&lt;/li&gt;
&lt;li&gt;Choose a maintained JDK 8 base and architecture&lt;/li&gt;
&lt;li&gt;Write the pinned multi-stage Dockerfile&lt;/li&gt;
&lt;li&gt;Verify the toolchain inside the image&lt;/li&gt;
&lt;li&gt;Pin, update, and audit the image&lt;/li&gt;
&lt;li&gt;Reproduce the JDK 8 toolchain locally&lt;/li&gt;
&lt;li&gt;Jenkins agents: keep the agent JVM separate&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why old JDK 8 images break builds
&lt;/h2&gt;

&lt;p&gt;Start with the image reference, not the build script. If a Dockerfile still says &lt;code&gt;FROM java:8&lt;/code&gt; or &lt;code&gt;FROM openjdk:8&lt;/code&gt;, it is building on an unmaintained image line. The &lt;a href="https://hub.docker.com/_/openjdk" rel="noopener noreferrer"&gt;Docker Hub page for the &lt;code&gt;openjdk&lt;/code&gt; official image&lt;/a&gt; marks the image as officially deprecated and explains that only Early Access tags continue to receive updates after July 2022. That is not a safe source of JDK 8 security fixes.&lt;/p&gt;

&lt;p&gt;The second problem is mutability. Even a maintained tag such as &lt;code&gt;8-jdk-jammy&lt;/code&gt; is a moving pointer: the publisher can rebuild the same tag with a different base OS, CA bundle, locale data, or JDK patch release. &lt;a href="https://docs.docker.com/build/building/best-practices/" rel="noopener noreferrer"&gt;Docker's build best practices&lt;/a&gt; explain that tags are mutable and that a digest pins the exact image content, even if the publisher later moves the tag.&lt;/p&gt;

&lt;p&gt;That difference matters for legacy pipelines. A rebuild six months after the original image was tested can quietly change the compiler patch level or the glibc and certificate stack. The build may fail for reasons unrelated to the application change, and the failure is hard to reproduce because the image reference looks unchanged.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Image reference&lt;/th&gt;
&lt;th&gt;Status&lt;/th&gt;
&lt;th&gt;What it means for CI&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;java:8&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Retired&lt;/td&gt;
&lt;td&gt;No JDK 8 security updates; replace it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;openjdk:8&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Deprecated&lt;/td&gt;
&lt;td&gt;Only Early Access tags updated after July 2022&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;eclipse-temurin:8-jdk-jammy&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Maintained&lt;/td&gt;
&lt;td&gt;Official image, but the tag still moves&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;eclipse-temurin:8-jdk-jammy@sha256:...&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Pinned&lt;/td&gt;
&lt;td&gt;Reproducible until you deliberately update it&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A maintained and pinned base is the foundation. The rest of this article chooses that base and then hardens the build image around it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choose a maintained JDK 8 base and architecture
&lt;/h2&gt;

&lt;p&gt;Eclipse Temurin is the OpenJDK build published by the Eclipse Adoptium project and distributed as a Docker Official Image. The &lt;a href="https://hub.docker.com/_/eclipse-temurin" rel="noopener noreferrer"&gt;Temurin Docker Hub page&lt;/a&gt; documents the supported tags, variants, and platforms.&lt;/p&gt;

&lt;p&gt;Adoptium's own &lt;a href="https://adoptium.net/support" rel="noopener noreferrer"&gt;Temurin support roadmap&lt;/a&gt; lists Java 8 as available at least through December 2032, with maintenance and security updates following upstream OpenJDK's quarterly cadence. That is a much better support story than an abandoned community image, but it still requires you to pick up releases deliberately.&lt;/p&gt;

&lt;h3&gt;
  
  
  Read the tag before you copy it
&lt;/h3&gt;

&lt;p&gt;A tag such as &lt;code&gt;8-jdk-jammy&lt;/code&gt; carries three pieces of information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;8&lt;/code&gt;&lt;/strong&gt;: the Java major version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;jdk&lt;/code&gt;&lt;/strong&gt;: the full development kit, including &lt;code&gt;javac&lt;/code&gt;. A JRE image can run Java but cannot compile it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;jammy&lt;/code&gt;&lt;/strong&gt;: Ubuntu 22.04. The OS name matters because it determines the C library, package versions, and available locales.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Floating aliases such as &lt;code&gt;8-jdk&lt;/code&gt; and &lt;code&gt;8-jdk-jammy&lt;/code&gt; are convenient, but they are exactly the moving tags described earlier. A version-specific tag such as &lt;code&gt;8u&amp;lt;update&amp;gt;-b&amp;lt;build&amp;gt;-jdk-jammy&lt;/code&gt; is easier for reviewers to reason about, but the digest is what makes the image reproducible. Even a floating tag plus a digest is pinned; the tag is just a human-readable label.&lt;/p&gt;

&lt;p&gt;For most legacy Maven, Ant, and Gradle builds, the Ubuntu Jammy variant is the safer default. The Temurin page notes that the Alpine variant uses musl libc, which can break tools and native libraries that assume glibc. Alpine's smaller size is attractive, but a surprising native-library failure in a legacy build costs more than the saved megabytes.&lt;/p&gt;

&lt;p&gt;Before adopting any base, check its default user. Some JDK 8 images run as root by default, so plan to add a non-root &lt;code&gt;USER&lt;/code&gt; even if you choose a different publisher.&lt;/p&gt;

&lt;h3&gt;
  
  
  Choose the architecture deliberately
&lt;/h3&gt;

&lt;p&gt;The Temurin image page lists support for &lt;code&gt;amd64&lt;/code&gt;, &lt;code&gt;arm32v7&lt;/code&gt;, &lt;code&gt;arm64v8&lt;/code&gt;, &lt;code&gt;ppc64le&lt;/code&gt;, &lt;code&gt;riscv64&lt;/code&gt;, &lt;code&gt;s390x&lt;/code&gt;, and &lt;code&gt;windows-amd64&lt;/code&gt;. On a normal x86-64 CI runner, use &lt;code&gt;linux/amd64&lt;/code&gt;. On Apple silicon or arm64 runners, use &lt;code&gt;linux/arm64&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you build for more than one architecture, pin the top-level index digest so Docker can select the matching platform manifest. If you need one specific architecture, pin that platform's manifest digest instead. The command later in this article shows how to inspect both.&lt;/p&gt;

&lt;p&gt;Temurin's &lt;a href="https://raw.githubusercontent.com/adoptium/containers/main/8/jdk/ubuntu/jammy/Dockerfile" rel="noopener noreferrer"&gt;JDK 8 Ubuntu Dockerfile&lt;/a&gt; sets &lt;code&gt;JAVA_HOME=/opt/java/openjdk&lt;/code&gt;, puts &lt;code&gt;$JAVA_HOME/bin&lt;/code&gt; first on &lt;code&gt;PATH&lt;/code&gt;, and runs &lt;code&gt;java -version&lt;/code&gt; and &lt;code&gt;javac -version&lt;/code&gt; as part of the image build. We will keep the same &lt;code&gt;JAVA_HOME&lt;/code&gt; path and add our own explicit checks so the image fails at build time if the toolchain is broken.&lt;/p&gt;

&lt;h2&gt;
  
  
  Write the pinned multi-stage Dockerfile
&lt;/h2&gt;

&lt;p&gt;The Dockerfile below has two stages. The first downloads and verifies Maven. The second copies only the verified Maven directory into the final image, creates a non-root user, and checks the toolchain as that user. Docker's build guidance recommends multi-stage builds for this kind of separation, because build-only artifacts and temporary archives do not belong in the final image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="c"&gt;# syntax=docker/dockerfile:1&lt;/span&gt;

&lt;span class="k"&gt;ARG&lt;/span&gt; &lt;span class="nv"&gt;TEMURIN_IMAGE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;eclipse-temurin:8-jdk-jammy@sha256:d47056146401dbffde28978d4ccb2d54dbcf52935881a6693f137bb92bfca63e
&lt;span class="k"&gt;ARG&lt;/span&gt; &lt;span class="nv"&gt;MAVEN_VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3.10.2
&lt;span class="k"&gt;ARG&lt;/span&gt; &lt;span class="nv"&gt;MAVEN_SHA512&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;57d2db6b37e7582119137ade544557bba741b29e62109ef81539a2bdfd6d0e641fdd5d8edb014af1816d0510deac6fac8f347433b3a1aa36316ba85aa77b8119

&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="nv"&gt;${TEMURIN_IMAGE}&lt;/span&gt; AS maven

&lt;span class="k"&gt;ARG&lt;/span&gt; MAVEN_VERSION
&lt;span class="k"&gt;ARG&lt;/span&gt; MAVEN_SHA512

&lt;span class="k"&gt;RUN&lt;/span&gt; curl --fail --silent --show-error --location \
        --output /tmp/apache-maven.tar.gz \
        &lt;span class="s2"&gt;"https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz"&lt;/span&gt; \
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"${MAVEN_SHA512}  /tmp/apache-maven.tar.gz"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; sha512sum --check --status \
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; mkdir -p /opt/maven \
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; tar --extract --gzip --file /tmp/apache-maven.tar.gz \
        --directory /opt/maven --strip-components=1 \
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; rm -f /tmp/apache-maven.tar.gz


&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="nv"&gt;${TEMURIN_IMAGE}&lt;/span&gt; AS ci

&lt;span class="k"&gt;ARG&lt;/span&gt; &lt;span class="nv"&gt;CI_UID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;10001
&lt;span class="k"&gt;ARG&lt;/span&gt; &lt;span class="nv"&gt;CI_GID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;10001

&lt;span class="k"&gt;ENV&lt;/span&gt; &lt;span class="nv"&gt;JAVA_HOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/opt/java/openjdk \
    &lt;span class="nv"&gt;MAVEN_HOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/opt/maven \
    &lt;span class="nv"&gt;HOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/home/ci \
    &lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/opt/maven/bin:/opt/java/openjdk/bin:${PATH}"&lt;/span&gt;

&lt;span class="k"&gt;COPY&lt;/span&gt; --from=maven /opt/maven /opt/maven

&lt;span class="k"&gt;RUN&lt;/span&gt; groupadd --gid &lt;span class="s2"&gt;"${CI_GID}"&lt;/span&gt; ci \
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; useradd --uid &lt;span class="s2"&gt;"${CI_UID}"&lt;/span&gt; --gid &lt;span class="s2"&gt;"${CI_GID}"&lt;/span&gt; \
        --create-home --shell /bin/bash ci \
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; mkdir -p /workspace /home/ci/.m2 \
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; chown -R &lt;span class="s2"&gt;"${CI_UID}:${CI_GID}"&lt;/span&gt; /workspace /home/ci

&lt;span class="k"&gt;USER&lt;/span&gt; ci

&lt;span class="k"&gt;RUN&lt;/span&gt; java -version \
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; javac -version \
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; mvn -version

&lt;span class="k"&gt;WORKDIR&lt;/span&gt; /workspace

&lt;span class="k"&gt;CMD&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"/bin/bash"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few details are worth calling out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The base is pinned twice, in effect.&lt;/strong&gt; The readable tag says &lt;code&gt;8-jdk-jammy&lt;/code&gt;; the digest says exactly which image that tag resolved to. The digest above is an index digest, so Docker picks the right platform for the runner. Refresh it before you rely on it, as shown in the update section below.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maven is pinned and checked.&lt;/strong&gt; &lt;code&gt;MAVEN_VERSION&lt;/code&gt; and &lt;code&gt;MAVEN_SHA512&lt;/code&gt; are build arguments, so a version bump is a one-line change. The checksum is verified before extraction, and a mismatch fails the build before Maven ever runs. The &lt;a href="https://maven.apache.org/download.cgi" rel="noopener noreferrer"&gt;Apache Maven download page&lt;/a&gt; lists the current release and its checksum; Maven 3.10.2 requires JDK 8 or later to execute. If the project is validated against an older Maven line, pin that version and its checksum instead of changing the build tool as part of the container change.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;JAVA_HOME&lt;/code&gt; and &lt;code&gt;PATH&lt;/code&gt; are explicit.&lt;/strong&gt; The image does not depend on a login shell to find &lt;code&gt;java&lt;/code&gt; or &lt;code&gt;javac&lt;/code&gt;. &lt;code&gt;PATH&lt;/code&gt; puts Maven's &lt;code&gt;bin&lt;/code&gt; directory first, then the pinned JDK.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The build runs as a fixed non-root user.&lt;/strong&gt; UID and GID 10001 avoid the ambiguity of a dynamically assigned user, and &lt;code&gt;/workspace&lt;/code&gt; and the Maven local repository are owned by that user. Docker's own guidance recommends an explicit UID/GID and a non-root &lt;code&gt;USER&lt;/code&gt; when the process does not need privileges.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The verification runs as the same user that will run CI.&lt;/strong&gt; If &lt;code&gt;java&lt;/code&gt;, &lt;code&gt;javac&lt;/code&gt;, or &lt;code&gt;mvn&lt;/code&gt; only works as root, the image build fails now rather than during a pipeline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The command is a shell.&lt;/strong&gt; This is a build environment, not a long-running service. The base image's CA-certificate entrypoint is inherited, but it simply executes the command you pass when no extra certificates are requested.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your CI system requires a different UID, override &lt;code&gt;CI_UID&lt;/code&gt; and &lt;code&gt;CI_GID&lt;/code&gt; at build time and make sure the workspace ownership matches. The next step is to prove the image actually contains the toolchain you expect.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verify the toolchain inside the image
&lt;/h2&gt;

&lt;p&gt;Build the image and run a short verification script. The script fails on the first mismatch, which makes it suitable for a CI smoke test.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build -t legacy-jdk8-ci:local .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the runner's default platform is not the one you want, add &lt;code&gt;--platform linux/amd64&lt;/code&gt; or &lt;code&gt;--platform linux/arm64&lt;/code&gt;. The index digest lets Docker select the matching manifest for that platform.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run --rm legacy-jdk8-ci:local bash -c &lt;span class="s1"&gt;'
  set -euo pipefail
  test "$(id -u)" -eq 10001
  test "$JAVA_HOME" = "/opt/java/openjdk"
  java -version
  javac -version
  mvn -version
  readlink -f "$(command -v javac)"
'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output should look like this, with the patch release matching the base image you pinned:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Check&lt;/th&gt;
&lt;th&gt;Expected result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;id -u&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;10001&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$JAVA_HOME&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/opt/java/openjdk&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;java -version&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;openjdk version "1.8.0_..."&lt;/code&gt;, with &lt;code&gt;Temurin&lt;/code&gt; in the runtime line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;javac -version&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;javac 1.8.0_...&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mvn -version&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Apache Maven 3.10.2&lt;/code&gt; and &lt;code&gt;Java version: 1.8.0_...&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;readlink -f "$(command -v javac)"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/opt/java/openjdk/bin/javac&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Now run the command your pipeline actually uses, not just the version checks. For a Maven project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run --rm \
  -v &lt;span class="s2"&gt;"$PWD"&lt;/span&gt;:/workspace \
  -w /workspace \
  legacy-jdk8-ci:local \
  mvn -B -ntp -DskipTests package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On a workstation, the checkout is usually owned by your user, while the container runs as UID 10001. Add &lt;code&gt;--user&lt;/code&gt; and mount your Maven cache so the container can write the workspace and reuse dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p &lt;span class="s2"&gt;"$HOME/.m2"&lt;/span&gt;
docker run --rm \
  --user &lt;span class="s2"&gt;"$(id -u):$(id -g)"&lt;/span&gt; \
  -v &lt;span class="s2"&gt;"$PWD"&lt;/span&gt;:/workspace \
  -v &lt;span class="s2"&gt;"$HOME/.m2"&lt;/span&gt;:/home/ci/.m2 \
  -w /workspace \
  legacy-jdk8-ci:local \
  mvn -B -ntp -DskipTests package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In CI, make the workspace writable by the container UID, or run the container with the CI user's UID. In Kubernetes, an &lt;code&gt;fsGroup&lt;/code&gt; can handle group ownership for mounted volumes. If your project uses the Gradle wrapper, run &lt;code&gt;./gradlew --version&lt;/code&gt; and &lt;code&gt;./gradlew build&lt;/code&gt; with the wrapper version the project already pins; changing the wrapper is a separate migration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pin, update, and audit the image
&lt;/h2&gt;

&lt;p&gt;Pinning a digest solves reproducibility, but it also opts you out of automatic base image updates. The maintenance plan has to be explicit.&lt;/p&gt;

&lt;p&gt;First, inspect the current tag and copy the digest you need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker buildx imagetools inspect eclipse-temurin:8-jdk-jammy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output shows a top-level &lt;code&gt;Digest&lt;/code&gt; for the multi-platform index and a digest for each platform manifest. Use the index digest when you want one Dockerfile to work on both amd64 and arm64; use a platform manifest digest when you need a strict single-architecture pin.&lt;/p&gt;

&lt;p&gt;Then keep the update path short:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Track the JDK.&lt;/strong&gt; Temurin ships security updates on the upstream quarterly cadence. Revisit the digest after each release, or sooner if Adoptium publishes a critical security update.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Update the digest, not just the tag.&lt;/strong&gt; Change &lt;code&gt;TEMURIN_IMAGE&lt;/code&gt; in one place. Keep the previous digest in your deployment history so you can roll back.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Update Maven separately.&lt;/strong&gt; Change &lt;code&gt;MAVEN_VERSION&lt;/code&gt; and &lt;code&gt;MAVEN_SHA512&lt;/code&gt; together. A stale checksum will fail the build before Maven runs, which is the desired behavior.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rebuild and verify.&lt;/strong&gt; Run the verification script and the real project build on a branch before promoting the image.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Record what is inside.&lt;/strong&gt; Read &lt;code&gt;JAVA_VERSION&lt;/code&gt; from the running image with &lt;code&gt;docker run --rm legacy-jdk8-ci:local printenv JAVA_VERSION&lt;/code&gt;, and keep that value in the image label or release notes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Docker's best practices also recommend automating this with Dependabot's Docker ecosystem support. A small configuration file is enough:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# .github/dependabot.yml
&lt;/span&gt;&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="na"&gt;updates&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;package-ecosystem&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"docker"&lt;/span&gt;
    &lt;span class="na"&gt;directory&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/"&lt;/span&gt;
    &lt;span class="na"&gt;schedule&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;interval&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"weekly"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not treat &lt;code&gt;docker build --pull&lt;/code&gt; as your update mechanism when the base is pinned by digest. &lt;code&gt;--pull&lt;/code&gt; refreshes tags, but a digest still resolves to the same content. To pick up a new JDK release, change the digest deliberately, rebuild, and run the same checks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reproduce the JDK 8 toolchain locally
&lt;/h2&gt;

&lt;p&gt;When a build fails only in CI, the fastest path is usually to reproduce the toolchain on a workstation. Install Temurin 8 from Adoptium's package repository; the &lt;a href="https://adoptium.net/installation/linux/" rel="noopener noreferrer"&gt;Adoptium Linux installation instructions&lt;/a&gt; show the repository setup and the &lt;code&gt;temurin-8-jdk&lt;/code&gt; package name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo apt update
sudo apt install temurin-8-jdk
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;JAVA_HOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/lib/jvm/temurin-8-jdk-amd64
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$JAVA_HOME/bin:$PATH"&lt;/span&gt;
java -version
javac -version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On arm64, the directory usually ends in &lt;code&gt;-arm64&lt;/code&gt; rather than &lt;code&gt;-amd64&lt;/code&gt;. Confirm the path with &lt;code&gt;readlink -f "$(command -v javac)"&lt;/code&gt; before exporting it. For a full walkthrough that covers Windows, macOS, and Linux, including &lt;code&gt;JAVA_HOME&lt;/code&gt; configuration and switching between JDK versions, see this &lt;a href="https://javathinking.com/blog/install-jdk-8/" rel="noopener noreferrer"&gt;guide to installing JDK 8 locally to reproduce the build environment&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can also debug against the same container image without copying the toolchain to the host:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run --rm -it \
  -v &lt;span class="s2"&gt;"$PWD"&lt;/span&gt;:/workspace \
  -w /workspace \
  legacy-jdk8-ci:local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the container, run &lt;code&gt;mvn -version&lt;/code&gt; and compare it with the host output. The JDK vendor, version, and Maven version should match. If they do not, fix the image or the local install before debugging the application.&lt;/p&gt;

&lt;p&gt;When behavior still differs, check the environment rather than the compiler. The Temurin image sets &lt;code&gt;LANG&lt;/code&gt; and &lt;code&gt;LC_ALL&lt;/code&gt; to &lt;code&gt;en_US.UTF-8&lt;/code&gt;, so compare &lt;code&gt;locale&lt;/code&gt; output if the build is encoding-sensitive. Also compare &lt;code&gt;MAVEN_OPTS&lt;/code&gt;, timezone, any mounted &lt;code&gt;settings.xml&lt;/code&gt;, and file ownership on the workspace. Those differences are common causes of "works in the container, fails on my laptop" puzzles.&lt;/p&gt;

&lt;h2&gt;
  
  
  Jenkins agents: keep the agent JVM separate
&lt;/h2&gt;

&lt;p&gt;A JDK 8 build image is not automatically a valid Jenkins agent image. Jenkins' &lt;a href="https://www.jenkins.io/doc/book/platform-information/upgrade-java-to-11/" rel="noopener noreferrer"&gt;upgrade guide for Java 11&lt;/a&gt; explains that agents must run at least the minimum Java version required by the controller. Jenkins 2.361.1 LTS requires Java 11 or 17 for the controller and agents. Keep the agent process on that supported JVM even when the job compiles with JDK 8.&lt;/p&gt;

&lt;p&gt;The job toolchain is a different setting. Jenkins can launch an agent with Java 11 or 17 while a build step uses JDK 8, as long as the agent process itself stays on the supported JVM. That is the distinction behind most "Jenkins no longer supports JDK 8" migration questions.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Approach&lt;/th&gt;
&lt;th&gt;How it works&lt;/th&gt;
&lt;th&gt;Best for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Docker pipeline agent&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;agent { docker { image ... } }&lt;/code&gt; runs the stage in the JDK 8 container while the Jenkins agent JVM stays outside it&lt;/td&gt;
&lt;td&gt;Most Jenkinsfile pipelines&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Kubernetes pod&lt;/td&gt;
&lt;td&gt;A &lt;code&gt;jnlp&lt;/code&gt; container runs Java 11 or 17; a separate &lt;code&gt;jdk8&lt;/code&gt; container runs the build&lt;/td&gt;
&lt;td&gt;Kubernetes plugin users&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Single image with two JDKs&lt;/td&gt;
&lt;td&gt;Keep Java 11 or 17 as the default for remoting; expose JDK 8 at a separate path and set it only in build steps&lt;/td&gt;
&lt;td&gt;Constrained environments&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A declarative pipeline can use the pinned image as a stage-level build environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt;
  &lt;span class="n"&gt;stages&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Build on JDK 8'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;docker&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="n"&gt;image&lt;/span&gt; &lt;span class="s1"&gt;'registry.example.com/legacy-jdk8-ci@sha256:&amp;lt;image-digest&amp;gt;'&lt;/span&gt;
          &lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="s1"&gt;'-u 10001:10001'&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;sh&lt;/span&gt; &lt;span class="s1"&gt;'java -version &amp;amp;&amp;amp; mvn -B -ntp verify'&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you use the Docker plugin's "Connect with SSH" mode, the SSH-launched agent process runs with the image's Java unless you override the agent's Java path. A JDK 8-only image will fail to launch that agent on Jenkins 2.361.1 and later. Point the agent template at a JDK 11 or 17 image and run the JDK 8 image as a build container, or keep a separate supported JDK in the image for the agent process. Do not set &lt;code&gt;JAVA_HOME&lt;/code&gt; to JDK 8 for the agent itself just to make the job compile; that breaks the remoting layer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;A Docker image with JDK 8 for a legacy CI build does not have to be an abandoned image. Use Eclipse Temurin 8, pin the base by digest, set &lt;code&gt;JAVA_HOME&lt;/code&gt; and &lt;code&gt;PATH&lt;/code&gt; explicitly, run the build as a non-root user, and verify &lt;code&gt;java&lt;/code&gt;, &lt;code&gt;javac&lt;/code&gt;, and the real Maven or Gradle command inside the image. Keep the Jenkins agent JVM on a supported Java version and use the JDK 8 image only as the build environment. Finally, schedule deliberate digest and Maven updates, and reproduce the same toolchain locally when you need to debug. That gives legacy builds the stability they need without relying on stale, mutable tags.&lt;/p&gt;

</description>
      <category>ci</category>
      <category>devops</category>
      <category>docker</category>
      <category>java</category>
    </item>
  </channel>
</rss>
