I have a GitHub Action running a build that happen...
# community-support
s
I have a GitHub Action running a build that happens to be configured to start the build with JDK 17, it is shared among a few projects. I have a project that needs JDK 21 and uses the foojay-resolver combined with specifying the toolchain in the build file.. this is failing though. It seems that my Kotlin-based convention plugin that is added as an included is still trying to run with JDK 17. ./build-logic/settings.gradle.kts:
Copy code
plugins {
    id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
    id("dev.panuszewski.typesafe-conventions") version "0.7.3"
}
./build-logic/build.gradle.kts:
Copy code
plugins {
    `kotlin-dsl`
}

kotlin {
    jvmToolchain(21)
}

repositories {
    mavenCentral()
    gradlePluginPortal()
}

dependencies {
    implementation(libs.commons.lang3)
}
./settings.gradle:
Copy code
plugins {
    id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0'
}
// This is to propagate the backendPlatformVersion property to the build-logic convention plugin
gradle.beforeProject { project ->
    if (project.hasProperty('backendPlatformVersion')) {
        System.setProperty('backendPlatformVersion', project.backendPlatformVersion)
    }
}
rootProject.name = 'main-project'
includeBuild("build-logic")
include 'sub-project-1'
include 'sub-project-2
include 'sub-project-3'
When I build with JAVA_HOME pointing to JDK 17:
Copy code
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':sub-project-1'.
> Could not resolve all dependencies for configuration 'classpath'.
   > Could not resolve project :build-logic.
     Required by:
         project :sub-project-1
      > Dependency requires at least JVM runtime version 21. This build uses a Java 17 JVM.
Shouldn't the resolver plugin cause the build to use JDK 21?
e
only for the Kotlin compile, it is too late to affect the JVM that runs the build scripts that your plugin applies to
s
Yeah, but isn't that what I need - the JDK for building the kotlin convention plugin? I didn't even think there was a way to specify the JDK version required for a build script.
v
The question is, why do you set the toolchain to 21 in
build-logic/build.gradle.kts
actually? Does the build logic built in there really need Java 21? If so, then, well, you also need to run the consuming build with Java 21 or use the daemon toolchain feature @ephemient pointed at to run the daemon with 21 even if you start the CLI using 17. Or did you mean to set the tool chain for your actual production code to 21. Then the location you did it is wrong and you probably intended to do that in your convention plugin that you apply to your main build.
s
The build logic doesn't need JDK 21. That was just to be consistent with the sub-projects. I guess I can just remove the toolchain specification from the convention plugin entirely.
👌 1
Okay. So I've fixed it by simply removing the toolchain requirement from the convention plugin, but I am curious what it was trying to do and if it was supposed to work the way I had it. I.e. if the convention plugin did need JDK 21, was I still doing something wrong?
v
As I said, it is all about target environments. The target environment of the things built in your
build-logic
project is the Gradle daemon that builds the project that uses those
build-logic
things. If you there configure the target JVM to be 21, then it needs at least JVM 21 for the Gradle daemon.
s
Got it 👍