I have a Multi-module Maven project. I had to import a maven module Vader (which uses a mix of Kotlin 1.5.0 and Java 11) and use it as a dependency for one of my modules which purely uses java 11. The code compiles well but at runtime I get this error:
java.lang.UnsupportedClassVersionError: org/revcloud/vader/matchers/AnyMatchers has been compiled by a more recent version of the Java Runtime (class file version 59.0), this version of the Java Runtime only recognizes class file versions up to 55.0
The file for which I get this error is a .kt
file in my dependency module. I don’t get this error for java files. On the dependency module (vader) I made sure jvmTarget is set to java 11 and jdkHome points to java 11. I even confirmed by running javap -verbose AnyMatchers.class | grep “major”
which gives me major version: 55
I am clueless as to what am I missing, where is this 59.0 coming from? Even my system only has JDK 11 and JDK 15 is not installed.
PFB the <build>
section of pom.xml for dependency project(vader). (This has lombok too. So I delombok first into target/delombok and kotlin-maven-plugin picks up sources from this place. However none of the lombok annotations are used in Kotlin classes)
<build>
<sourceDirectory>${project.build.directory}/delombok</sourceDirectory>
<testSourceDirectory>${project.build.directory}/delombok-test</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<configuration>
<jvmTarget>${kotlin.compiler.jvmTarget}</jvmTarget>
<jdkHome>${kotlin.compiler.jdkHome}</jdkHome>
</configuration>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.build.directory}/delombok</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.build.directory}/delombok-test</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>${lombok.version}.0</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>delombok</id>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
<configuration>
<sourceDirectory>src/main/java</sourceDirectory>
<outputDirectory>${project.build.directory}/delombok</outputDirectory>
<addOutputDirectory>false</addOutputDirectory>
</configuration>
</execution>
<execution>
<id>delombok-test</id>
<phase>generate-test-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
<configuration>
<sourceDirectory>src/test/java</sourceDirectory>
<outputDirectory>${project.build.directory}/delombok-test</outputDirectory>
<addOutputDirectory>false</addOutputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${kotlin.compiler.jvmTarget}</source>
<target>${kotlin.compiler.jvmTarget}</target>
</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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
</plugins>
</build>
Figured it out, had to change the Target JVM version for the Kotlin Compiler in Intellij