使用IntelliJ IDEA构建Kotlin项目时,到处都有许多选项似乎在指定目标JVM版本。我已经附加了每个项目当前在我的项目中显示的值:
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" }
这是对我可以指定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)
以上哪项设置最优先?如果我想将程序编译到JVM版本11的目标,那么哪个设置是必不可少的并且不会被其他设置覆盖?
在基于Maven的JVM项目中,要设置目标JVM版本-使用Maven意味着-IDE将自动获取这些设置:
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
或:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
另请参阅在maven中指定java版本-属性和编译器插件之间的差异