Failed kotlin compilation in submodule

1 week ago 8
ARTICLE AD BOX

I have a multi module project. All working fine with java 8 and kotlin 2.3.0. I want to upgrade java up to 21.

After upgrading java kotlin compilatin failing in one of submodules. But in another submodule compiled successfully.

In parent POM kotlin-maven-plugin config:

<plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> <version>${kotlin.version}</version> <configuration> <args> <arg>-Xjsr305=strict</arg> <arg>-Xcontext-parameters</arg> <arg>-Xcontext-sensitive-resolution</arg> <arg>-Xannotation-default-target=param-property</arg> <arg>-Xconsistent-data-class-copy-visibility</arg> <arg>-Xdata-flow-based-exhaustiveness</arg> <arg>-Xallow-reified-type-in-catch</arg> <arg>-Xreturn-value-checker=check</arg> </args> <languageVersion>2.3</languageVersion> <jvmTarget>${java.version}</jvmTarget> <javaParameters>true</javaParameters> <compilerPlugins> <plugin>spring</plugin> <plugin>jpa</plugin> </compilerPlugins> </configuration> <executions> <execution> <id>kotlin-compile</id> <phase>compile</phase> <goals> <goal>compile</goal> </goals> <configuration> <sourceDirs> <sourceDir>${project.basedir}/src/main/kotlin</sourceDir> <sourceDir>${project.basedir}/src/main/java</sourceDir> </sourceDirs> </configuration> </execution> <execution> <id>kotlin-test-compile</id> <phase>test-compile</phase> <goals> <goal>test-compile</goal> </goals> <configuration> <sourceDirs> <sourceDir>${project.basedir}/src/test/kotlin</sourceDir> </sourceDirs> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-allopen</artifactId> <version>${kotlin.version}</version> </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-noarg</artifactId> <version>${kotlin.version}</version> </dependency> </dependencies> </plugin>

maven-compiler-plugin:

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.15.0</version> <configuration> <release>${java.version}</release> <encoding>${project.build.sourceEncoding}</encoding> <compilerArgs> <arg>-parameters</arg> <arg>-Xlint:all,-unchecked,-varargs,-rawtypes</arg> </compilerArgs> </configuration> <executions> <!-- Replacing default-compile as it is treated specially by maven --> <execution> <id>default-compile</id> <phase>none</phase> </execution> <!-- Replacing default-testCompile as it is treated specially by maven --> <execution> <id>default-testCompile</id> <phase>none</phase> </execution> <execution> <id>java-compile</id> <phase>compile</phase> <goals> <goal>compile</goal> </goals> </execution> <execution> <id>java-test-compile</id> <phase>test-compile</phase> <goals> <goal>testCompile</goal> </goals> </execution> </executions> </plugin>

In problematic submodule no overriding by other plugins, only this:

<plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> </plugin>

In successful submodule:

<plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <executions> <execution> <id>java-compile</id> <phase>compile</phase> <goals> <goal>compile</goal> </goals> </execution> </executions> </plugin>

Kotlin compilation failed with many erros in problematic submodule, for example:

"Unresolved reference 'toInstant'. (java.util.Date().toInstant)"

"Argument type mismatch: actual type is '(Mutable)List!', but '(Mutable)List!' was expected."

"Unresolved reference 'isAfter'"

Any suggestions? I tried to completely copy the plugin configuration from the parent POM, still not working.

"mvn -version" output: Apache Maven 3.9.13 (39d686bd50d8e054301e3a68ad44781df6f80dda) Maven home: /opt/maven Java version: 21.0.7, vendor: Azul Systems, Inc., runtime: /usr/lib/jvm/zulu-21-amd64 OS name: "linux", version: "6.11.0-25-generic", arch: "amd64", family: "unix" "mvn clean compile -DskipTests=true -X | grep jvmTarget" output: <jvmTarget>21</jvmTarget> [DEBUG] kotlin.compiler.jvmTarget: 21 [DEBUG] (f) jvmTarget = 21 <jvmTarget>21</jvmTarget> [DEBUG] kotlin.compiler.jvmTarget: 21 [DEBUG] (f) jvmTarget = 21 <jvmTarget>21</jvmTarget> [DEBUG] kotlin.compiler.jvmTarget: 21 [DEBUG] (f) jvmTarget = 21
Read Entire Article