Even when Java-21 is configured, looks like gradle...
# community-support
a
Even when Java-21 is configured, looks like gradle is compiling code with JDK-17. Can someone please help. More info in thread
Copy code
$ java --version
openjdk 21.0.3 2024-04-16 LTS
OpenJDK Runtime Environment Corretto-21.0.3.9.1 (build 21.0.3+9-LTS)
OpenJDK 64-Bit Server VM Corretto-21.0.3.9.1 (build 21.0.3+9-LTS, mixed mode, sharing)
Copy code
$ echo $JAVA_HOME
/usr/lib/jvm/java-21-amazon-corretto
Copy code
java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
}
This ⬇️ should be unrelated, since failure is with
compileJava
Copy code
kotlin {
        jvmToolchain {
            languageVersion.set(JavaLanguageVersion.of(17))
        }
    }
Copy code
$ ./gradlew --version

------------------------------------------------------------
Gradle 8.7
------------------------------------------------------------

Build time:   2024-03-22 15:52:46 UTC
Revision:     650af14d7653aa949fce5e886e685efc9cf97c10

Kotlin:       1.9.22
Groovy:       3.0.17
Ant:          Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM:          21.0.3 (<http://Amazon.com|Amazon.com> Inc. 21.0.3+9-LTS)
OS:           Linux 5.15.160-104.158.amzn2.x86_64 amd64
Error log:
Copy code
> Task :proto-library:compileJava
An exception has occurred in the compiler (17.0.9). Please file a bug against the Java compiler via the Java bug reporting page (<https://bugreport.java.com>) after checking the Bug Database (<https://bugs.java.com>) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.OutOfMemoryError: Java heap space
Copy code
org.gradle.jvmargs=-Xmx8g -XX:MaxMetaspaceSize=4096m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
Also, I have monitored heap space of my machine; its not eating up complete 8 G
Untitled
v
This ⬇️ should be unrelated, since failure is with
compileJava
I don't think it is unrelated. The Kotlin Gradle Plugin most probably is configuring the
compileJava
task to be consistent with the KGP configuration otherwise you get complaints that
compileJava
and
compileKotlin
are not configured consistently.
Also, I have monitored heap space of my machine; its not eating up complete 8 G
You are not monitoring the "heap space of your machine", you are monitoring the "RAM of your machine". But the
compileJava
task by default is configured to have
256m
iirc, so you need to set
options.forkOptions.memoryMaximumSize
on it if your compilation needs more.
a
But I can't go beyond this, right ?
Copy code
kotlin {
        jvmToolchain {
            languageVersion.set(JavaLanguageVersion.of(17))
        }
    }
like, I can't configure 21 for kotlin too, right ?
Added this
Copy code
tasks.withType(JavaCompile).configureEach {
        // Override the compile task behavior here
        // For example, disabling warnings
        options.compilerArgs << "-Xlint:none"
        options.setWarnings(false)
        options.fork = true
        options.forkOptions.memoryMaximumSize = '3g'
    }
v
Why can't you use 21 for Kotlin? Well, you need to be at least on 1.9.20 I think.
options.fork = true
should be the default, you should not need that
🆗 1
a
Okay. I was using
1.9.0
version, let me try upgrading to
1.9.20
& move kotlin to 21
v
You can even remove the kotlin specific toolchain config, it should pick up the global one automatically iirc
a
okay.. Few things started working after fixing version compatibility issues. Thanks!
👌 1