javakotlinmavenintellij-ideajvm

What determines how IntelliJ chooses the target platform for submodules?


I have a maven project in IntelliJ. The project uses Java and Kotlin, and it is configured to use Java 11 in the pom:

<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

However, in IntellJ, when I open the submodules in the project structure: The IntelliJ submodule screen, showing Kotlin in the Integ-test submodule IntelliJ project structure, showing version 1.8 begin used by Kotlin.

The target platform is set to use 1.8, even though the source and target level in the pom is set to 11. Furthermore, these settings revert to 1.8 when I do maven reimport, which implies they are determined by maven in some way.

I've checked the submodules' poms, and none of them refer to the target plaform or to 1.8 in any way.

How are these values determined in from the pom.xml files?

How can I configure Maven so that Kotlin will be set to use the project's JVM inside the submodules?


Solution

  • This is really confusing at first. The standard configuration in maven you have shown

    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    

    ... is not really seen by Kotlin as this configuration is determined for Java.

    Small hint, you can do this now:

    <maven.compiler.release>11</maven.compiler.release>
    

    Coming back to your question:

    The fallback for Kotlin is Java 1.8 if no other configuration can be found. If you really need to set the Java version, you can use the kotlin-maven-plugin:

    <plugin>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-maven-plugin</artifactId>
        <version>1.9.10</version> <!-- or whichever version you're using -->
        <executions>
            <execution>
                <id>compile</id>
                <phase>compile</phase>
                <goals>
                    <goal>compile</goal>
                </goals>
            </execution>
            <execution>
                <id>test-compile</id>
                <phase>test-compile</phase>
                <goals>
                    <goal>test-compile</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <jvmTarget>11</jvmTarget>
        </configuration>
    </plugin>
    

    For more details and settings have a look here: https://kotlinlang.org/docs/maven.html#compile-kotlin-only-source-code