Instead of building a Java project on every JDK version in CI, compile once on the latest JDK and use Gradle toolchains to run tests across all supported versions. This reduces CI overhead while still verifying compatibility. A Gradle build script snippet shows how to register separate test tasks for each JDK version (8–17), all sharing the same compiled classes. The approach is especially important for projects using multi-release JARs or version-conditional API usage.