# Using Renovate to update build JDK

DevFeed: [Using Renovate to update build JDK](<https://devfeed.tech/articles/using-renovate-to-update-build-jdk-20982.md>)

Original publisher: [Read original article](<https://jakewharton.com/using-renovate-to-update-build-jdk/>)

Published: 2025-01-08T00:00:00Z

Content type: tutorial

Language: en

Sources: [Jake Wharton](<https://devfeed.tech/sources/jake-wharton.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [GitHub Actions](<https://devfeed.tech/topics/github-actions.md>), [ci](<https://devfeed.tech/topics/ci.md>), [Spring Boot](<https://devfeed.tech/topics/spring-boot.md>), [JSON](<https://devfeed.tech/topics/json.md>), [Development](<https://devfeed.tech/topics/development.md>), [Homebrew](<https://devfeed.tech/topics/homebrew.md>), [toolchains](<https://devfeed.tech/topics/toolchains.md>)

Tags: [build](<https://devfeed.tech/tags/build.md>), [ci](<https://devfeed.tech/tags/ci.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [github-actions](<https://devfeed.tech/tags/github-actions.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [java](<https://devfeed.tech/tags/java.md>), [jdk](<https://devfeed.tech/tags/jdk.md>), [json](<https://devfeed.tech/tags/json.md>), [jvm](<https://devfeed.tech/tags/jvm.md>), [renovate](<https://devfeed.tech/tags/renovate.md>), [toolchains](<https://devfeed.tech/tags/toolchains.md>), [update](<https://devfeed.tech/tags/update.md>)

## AI overview

This article explains how to use Renovate to keep the JDK used by a GitHub Actions CI build updated automatically. It moves the Java version into a .github/.java-version file, configures setup-java to read that file, and adds a custom regex manager in renovate.json to update the file. The approach allows local development with the latest JDK while preserving compatibility with older Java versions for targeting and testing.

## Source excerpt

You want to be using the latest JDK for development. Don't use Gradle toolchains, they'll needlessly force you to use old JDKs. You can still target and test on old JVM versions but develop with the latest and greatest. Java and the JDK are literally built for this. Locally this hasn't been a problem. Homebrew (or your favorite equivalent) will keep your default JDK at the latest. Keeping my GitHub actions up-to-date, however, frequently slips my mind. I find projects using 19 or 20 simply because I haven't touched the CI build in the two years since 19 or 20 was the latest. We're already using Renovate to keep dependencies up to date. With a little extra programming in JSON (wince) we can have the JDK version updated to latest as well. First, migrate the existing build JDK version in your GitHub Action to a .github/.java-version file1. 21 Next, change the setup-java action to use this file rather than a hard-coded version. - uses: actions/setup-java@v4 with: distribution: 'zulu' - java-version: 21 + java-version-file: .github/.java-version Finally, in your renovate.json52, add a custom manager to update this file3. ignorePresets: [ // Ensure we get the latest version and are not pinned to old versions. 'workarounds:javaLTSVersions', ], customManagers: [ // Update .java-version file with the latest JDK version. { customType: 'regex', fileMatch: [ '\\.java-version$', ], matchStrings: [ '(?<currentValue>.*)\\n', ], datasourceTemplate: 'java-version', depNameTemplate: 'java', // Only write the major version. extractVersionTemplate: '^(?<version>\\d+)', }, ], Commit, push, and wait for Renovate to send you a PR4. Now your CI build automatically tracks the latest JDK. I'm putting the .java-version file into the .github/ folder because I don't want to force this version on people using jenv or the like. The whole point of this setup is you can build with any version of Java newer than our very, very old baseline of Java 8 (although things like Gradle have a higher minimum