0

When building a Kotlin project using IntelliJ IDEA, there are many options all over the place that appear to be specifying the target JVM version. I've appended the value that each item is currently showing in my project:

Settings > Build, Ex, Dep > Compiler > Kotlin Compiler > Target JVM version  (1.6)
- (above page shows warning: Following modules override project settings: MyProject.main, MyProject.test)
Settings > Build, Ex, Dep > Compiler > Java Compiler > Project bytecode version  (13)
Settings > Build, Ex, Dep > Build Tools > Gradle > Gradle JVM  (Project SDK 13)
Project Structure > Project Settings > Project > Project language level (SDK default)
Project Structure > Project Settings > Modules > [project name] > [main] > Kotlin > Target platform (JVM 1.8)
Project Structure > Project Settings > Facets > Target platform (Multiplatform)
(in build.gradle.kts file) tasks.withType<KotlinCompile> { kotlinOptions.jvmTarget = "11" }

This is addition to a variety of places where I can specify the JRE:

Settings > Build, Ex, Dep > Build Tools > Maven > Runner > JRE (Use Project JDK)
Project Structure > Project > Project SDK (13 java version "13.0.2")
Project Structure > Project Settings > Modules > [project name, or main, test, etc] (Project default)

Which of the above settings takes top priority? If I want to compile my program to target JVM version 11, which setting is essential and won't be overridden by something else?

ExactaBox
  • 3,235
  • 16
  • 27

1 Answers1

1

In a Maven-based JVM project to set the target JVM version - use Maven means - IDE will automatically pick up these settings:

<plugins>
    <plugin>    
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>11</source>
            <target>11</target>
        </configuration>
    </plugin>
</plugins>

or:

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

See also Specifying java version in maven - differences between properties and compiler plugin

Andrey
  • 15,144
  • 25
  • 91
  • 187
  • gradle appears to have similar, but even then not sure what is the highest priority: `tasks.withType { kotlinOptions.jvmTarget = "11" }` or `compileKotlin.kotlinOptions { jvmTarget = "1.8" }` . So confusing. – ExactaBox Jun 12 '21 at 08:13
  • @ExactaBox those two both set the same setting, but one of them only sets it for compileKotlin, while the other sets it for all KotlinCompile tasks (including compileKotlin). So it might depend on the order the two statements execute in your build script. I find the best policy is only to set a given property in one place to remove that sort of question. :) – Hakanai Aug 31 '22 at 01:41