DEV Community

Query Filter
Query Filter

Posted on

docker112

// Define the path to your IntelliJ JDK
def intellijJbrPath = "C:/Program Files/JetBrains/IntelliJ IDEA/jbr"

// Hardcode the default to 'true' if not provided via command line
if (!project.hasProperty('useJava21')) {
    project.ext.useJava21 = "true" 
}

java {
    toolchain {
        // Now it defaults to 21 unless you explicitly pass -PuseJava21=false
        if (project.property('useJava21') == "true") {
            languageVersion = JavaLanguageVersion.of(21)
        } else {
            languageVersion = JavaLanguageVersion.of(8)
        }
    }
}

// Ensure the Toolchain knows where to look for Java 21
if (project.property('useJava21') == "true") {
    tasks.withType(JavaCompile).configureEach {
        javaCompiler = javaToolchains.compilerFor {
            languageVersion = JavaLanguageVersion.of(21)
        }
    }
    // This is the "internal" way to register that path without a properties file
    System.setProperty("org.gradle.java.installations.paths", intellijJbrPath)
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)