Part 2 of 16

Setting Up Java 8: JDK Options, Maven/Gradle, and IDE Configuration

Choosing a Java 8 Distribution

Oracle stopped providing free Java 8 updates for commercial use in January 2019. Multiple vendors now ship free, production-quality Java 8 builds:

DistributionVendorFree forever?Notes
Amazon Corretto 8AmazonYesProduction-hardened; used in AWS Lambda
Eclipse Temurin 8 (Adoptium)Eclipse FoundationYesMost widely used open build
Microsoft Build of OpenJDKMicrosoftYesOptimised for Azure; also works anywhere
Azul Zulu 8Azul SystemsYes (community)Long LTS commitment
Oracle JDK 8OracleNo (for commercial)Requires license for production use

Recommendation: Use Amazon Corretto 8 or Eclipse Temurin 8. Both are free, widely tested in production, and receive security patches. Avoid Oracle JDK 8 in commercial environments unless you have a license.


Installing Java 8

SDKMAN lets you manage multiple Java versions side-by-side:

# Install SDKMAN
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"

# List available Java 8 builds
sdk list java | grep "8\."

# Install Amazon Corretto 8
sdk install java 8.422.05.1-amzn

# Install Eclipse Temurin 8
sdk install java 8.0.412-tem

# Set as default
sdk default java 8.422.05.1-amzn

# Verify
java -version
# openjdk version "1.8.0_422"
# OpenJDK Runtime Environment Corretto-8.422.05.1 (build 1.8.0_422-b05)

macOS — Homebrew

brew tap homebrew/cask-versions
brew install --cask temurin8

Linux (Ubuntu/Debian)

# Amazon Corretto 8
wget -O - https://apt.corretto.aws/corretto.key | sudo gpg --dearmor -o /usr/share/keyrings/corretto-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/corretto-keyring.gpg] https://apt.corretto.aws stable main" | sudo tee /etc/apt/sources.list.d/amazon-corretto.list
sudo apt-get update
sudo apt-get install -y java-8-amazon-corretto-jdk

# Eclipse Temurin 8
sudo apt-get install -y temurin-8-jdk

Windows

Download the MSI installer from:

After installation, set JAVA_HOME:

[System.Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Eclipse Adoptium\jdk-8.0.412.8-hotspot", "Machine")

Verifying Your Installation

java -version
# openjdk version "1.8.0_422"

javac -version
# javac 1.8.0_422

echo $JAVA_HOME
# /Users/abhay/.sdkman/candidates/java/8.422.05.1-amzn

Note: Java 8 reports its version as 1.8.0_xxx, not 8.x. java.version system property returns "1.8.0_422".


Maven Configuration

pom.xml — Compiler Plugin

Tell Maven to compile with Java 8 source and target compatibility:

<properties>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Or with the compiler plugin explicitly:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.13.0</version>
            <configuration>
                <source>8</source>
                <target>8</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
    </plugins>
</build>

Maven Wrapper

Add a Maven wrapper so the project doesn’t depend on the system Maven version:

mvn wrapper:wrapper -Dmaven=3.9.6

This generates mvnw / mvnw.cmd and a .mvn/wrapper/ directory.

Testing with JUnit 5 on Java 8

JUnit 5 requires Java 8+. Use junit-bom to manage versions:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.junit</groupId>
            <artifactId>junit-bom</artifactId>
            <version>5.10.3</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

Gradle Configuration

build.gradle (Groovy DSL)

plugins {
    id 'java'
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

repositories {
    mavenCentral()
}

dependencies {
    testImplementation platform('org.junit:junit-bom:5.10.3')
    testImplementation 'org.junit.jupiter:junit-jupiter'
}

test {
    useJUnitPlatform()
}

build.gradle.kts (Kotlin DSL)

plugins {
    java
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

repositories {
    mavenCentral()
}

dependencies {
    testImplementation(platform("org.junit:junit-bom:5.10.3"))
    testImplementation("org.junit.jupiter:junit-jupiter")
}

tasks.test {
    useJUnitPlatform()
}

Gradle Wrapper

gradle wrapper --gradle-version 8.7

Generates gradlew / gradlew.bat.


IntelliJ IDEA Configuration

Setting the Project SDK

  1. File → Project Structure (⌘;)
  2. Under Project, set SDK to your Java 8 JDK
  3. Set Language level to 8 - Lambdas, type annotations etc.
  4. Click Apply

Module SDK Override

Each module can use a different SDK:

  1. File → Project Structure → Modules
  2. Select your module → Dependencies tab
  3. Set Module SDK if needed

Import Order and Code Style

For a Java 8 codebase, configure IntelliJ to prefer lambda form over anonymous classes:

  1. Settings → Editor → Inspections → Java → Style issues
  2. Enable Anonymous type can be replaced with lambda
  3. Enable Anonymous type can be replaced with method reference

IntelliJ will then offer quick-fixes to modernise legacy Java 7 style to Java 8.

Live Templates for Streams

Add a custom live template for fast stream boilerplate:

  1. Settings → Editor → Live Templates → Java
  2. Add abbreviation strm$COLLECTION$.stream().filter($PRED$).collect(Collectors.toList())

VS Code Configuration

Required Extensions

Install from the Extensions panel (Ctrl+Shift+X):

  • Extension Pack for Java (Microsoft) — includes Language Support for Java, Debugger, Test Runner, Maven for Java, Project Manager
  • Gradle for Java (if using Gradle)

settings.json

{
    "java.jdt.ls.java.home": "/path/to/jdk8",
    "java.configuration.runtimes": [
        {
            "name": "JavaSE-1.8",
            "path": "/path/to/jdk8",
            "default": true
        }
    ],
    "java.compile.nullAnalysis.mode": "automatic"
}

Find your JDK path:

# macOS with SDKMAN
echo $JAVA_HOME

# macOS with Homebrew
/usr/libexec/java_home -v 1.8

Quick Smoke Test

Create a file Java8Test.java and verify all major Java 8 features compile:

import java.util.*;
import java.util.stream.*;
import java.util.function.*;
import java.time.*;

public class Java8Test {
    public static void main(String[] args) {
        // Lambdas + Streams
        List<String> names = Arrays.asList("Alice", "Bob", "Charlie", "Dave");
        names.stream()
            .filter(s -> s.length() > 3)
            .map(String::toUpperCase)
            .sorted()
            .forEach(System.out::println);

        // Optional
        Optional<String> opt = names.stream()
            .filter(s -> s.startsWith("C"))
            .findFirst();
        System.out.println(opt.orElse("none"));

        // Date/Time API
        LocalDate today = LocalDate.now();
        System.out.println("Today: " + today);

        // Default method
        List<Integer> nums = new ArrayList<>(Arrays.asList(3, 1, 4, 1, 5));
        nums.sort(Comparator.naturalOrder());
        System.out.println(nums);

        // Method reference
        Function<String, Integer> len = String::length;
        System.out.println(len.apply("hello"));
    }
}

Run it:

javac Java8Test.java && java Java8Test

Expected output:

ALICE
CHARLIE
CHARLIE
Today: 2026-05-04
[1, 1, 3, 4, 5]
5

Common Setup Problems

error: lambda expressions are not supported in -source 7

Your compiler is targeting Java 7. Fix: check your pom.xml or build.gradle has source/target set to 8. In Maven, setting maven.compiler.source=8 in properties is sufficient.

JAVA_HOME Points to Wrong Version

# Check what java is being used
which java
java -version

# SDKMAN: switch version
sdk use java 8.422.05.1-amzn

# Without SDKMAN: update JAVA_HOME manually
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)  # macOS

IntelliJ Showing Red Errors Despite Correct SDK

  1. File → Invalidate Caches / Restart
  2. Check Project Structure → Project → SDK and Language level are both set to Java 8
  3. For Maven projects: re-import the project (Maven → Reload All Maven Projects)

Summary

TaskCommand / Setting
Install (SDKMAN)sdk install java 8.422.05.1-amzn
Verifyjava -version1.8.0_xxx
Maven source/target<maven.compiler.source>8</maven.compiler.source>
Gradle source/targetsourceCompatibility = JavaVersion.VERSION_1_8
IntelliJ SDKFile → Project Structure → SDK = JDK 8
IntelliJ Language LevelFile → Project Structure → Language Level = 8

Next Step

Environment ready. Start with the core language feature: Lambda Expressions →

Part of the DevOps Monk Java tutorial series: Java 8Java 11Java 17Java 21