Failed kotlin compilation in submodule
07:27 10 Mar 2026

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:


                    org.jetbrains.kotlin
                    kotlin-maven-plugin
                    ${kotlin.version}
                    
                        
                            -Xjsr305=strict
                            -Xcontext-parameters
                            -Xcontext-sensitive-resolution
                            -Xannotation-default-target=param-property
                            -Xconsistent-data-class-copy-visibility
                            -Xdata-flow-based-exhaustiveness
                            -Xallow-reified-type-in-catch
                            -Xreturn-value-checker=check
                        
                        2.3
                        ${java.version}
                        true
                        
                            spring
                            jpa
                        
                    
                    
                        
                            kotlin-compile
                            compile
                            
                                compile
                            
                            
                                
                                    ${project.basedir}/src/main/kotlin
                                    ${project.basedir}/src/main/java
                                
                            
                        
                        
                            kotlin-test-compile
                            test-compile
                            
                                test-compile
                            
                            
                                
                                    ${project.basedir}/src/test/kotlin
                                
                            
                        
                    
                    
                        
                            org.jetbrains.kotlin
                            kotlin-maven-allopen
                            ${kotlin.version}
                        
                        
                            org.jetbrains.kotlin
                            kotlin-maven-noarg
                            ${kotlin.version}
                        
                    
                

maven-compiler-plugin:


    org.apache.maven.plugins
    maven-compiler-plugin
    3.15.0
    
        ${java.version}
        ${project.build.sourceEncoding}
        
            -parameters
            -Xlint:all,-unchecked,-varargs,-rawtypes
        
    
    
        
        
            default-compile
            none
        
        
        
            default-testCompile
            none
        
        
            java-compile
            compile
            
                compile
            
        
        
            java-test-compile
            test-compile
            
                testCompile
            
        
    

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


    org.jetbrains.kotlin
    kotlin-maven-plugin

In successful submodule:


    org.jetbrains.kotlin
    kotlin-maven-plugin


    org.apache.maven.plugins
    maven-compiler-plugin
    
        
            java-compile
            compile
            
                compile
            
        
    

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:

  21
[DEBUG] kotlin.compiler.jvmTarget: 21
[DEBUG]   (f) jvmTarget = 21
  21
[DEBUG] kotlin.compiler.jvmTarget: 21
[DEBUG]   (f) jvmTarget = 21
  21
[DEBUG] kotlin.compiler.jvmTarget: 21
[DEBUG]   (f) jvmTarget = 21
java kotlin maven