L. Blanc
L. Blanc

Reputation: 2310

Why does my Kotlin compilation fail using Kotlin-Maven-Plugin?

While trying to compile a Java/Kotlin hybrid project, I received the following error:

[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.1.3-2:compile (compile) on project tablesaw-core: Compilation failure
[ERROR] java.lang.ArrayIndexOutOfBoundsException: 32
[ERROR] at org.jetbrains.org.objectweb.asm.ClassReader.readUTF8(ClassReader.java:2529)
[ERROR] at org.jetbrains.org.objectweb.asm.ClassReader.readModule(ClassReader.java:777)
[ERROR] at org.jetbrains.org.objectweb.asm.ClassReader.accept(ClassReader.java:646)
[ERROR] at org.jetbrains.org.objectweb.asm.ClassReader.accept(ClassReader.java:507)
[ERROR] at org.jetbrains.kotlin.resolve.jvm.modules.JavaModuleInfo$Companion.read(JavaModuleInfo.kt:51)
[ERROR] at org.jetbrains.kotlin.cli.jvm.modules.CliJavaModuleFinder.computeAllSystemModules$kotlin_compiler(CliJavaModuleFinder.kt:28)
[ERROR] at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.computeRootModules(KotlinCoreEnvironment.kt:298)
[ERROR] at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.addModularRoots(KotlinCoreEnvironment.kt:277)
[ERROR] at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.convertClasspathRoots(KotlinCoreEnvironment.kt:269)
[ERROR] at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:197)
[ERROR] at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:109)
[ERROR] at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:423)
[ERROR] at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createCoreEnvironment(K2JVMCompiler.kt:240)
[ERROR] at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createEnvironmentWithScriptingSupport(K2JVMCompiler.kt:230)
[ERROR] at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:189)
[ERROR] at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:55)
[ERROR] at org.jetbrains.kotlin.cli.common.CLICompiler.exec(CLICompiler.java:182)
[ERROR] at org.jetbrains.kotlin.maven.KotlinCompileMojoBase.execCompiler(KotlinCompileMojoBase.java:236)
[ERROR] at org.jetbrains.kotlin.maven.K2JVMCompileMojo.execCompiler(K2JVMCompileMojo.java:184)
[ERROR] at org.jetbrains.kotlin.maven.K2JVMCompileMojo.execCompiler(K2JVMCompileMojo.java:43)
[ERROR] at org.jetbrains.kotlin.maven.KotlinCompileMojoBase.execute(KotlinCompileMojoBase.java:219)
[ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
[ERROR] at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
[ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
[ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
[ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
[ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
[ERROR] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base@9-ea/Native Method)
[ERROR] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base@9-ea/NativeMethodAccessorImpl.java:62)
[ERROR] at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9-ea/DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.lang.reflect.Method.invoke(java.base@9-ea/Method.java:533)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

I am using Maven 3.3.9 with Kotlin 1.1.3-2, and Java 1.8

In googling for similar problems I saw similar results from other code using ClassReader. Those issues were attributed to a version mismatch, but the examples were not using Kotlin and I think my versions are ok.

My pom file is:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>tech.tablesaw</groupId>
    <artifactId>tablesaw-parent</artifactId>
    <version>0.8-SNAPSHOT</version>
</parent>

<artifactId>tablesaw-core</artifactId>
<version>0.8-SNAPSHOT</version>

<packaging>jar</packaging>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.2</version>
            <executions>
                <execution>
                   <goals>
                       <goal>test-jar</goal>
                   </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.sonatype.plugins</groupId>
            <artifactId>nexus-staging-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib-jre8</artifactId>
        <version>${kotlin.version}</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-test-junit</artifactId>
        <version>${kotlin.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Upvotes: 2

Views: 4940

Answers (1)

khmarbaise
khmarbaise

Reputation: 97359

This build is running on JDK9 and not on JDK 8 as mentioned based on the log output you can see things like this:

java.base@9-ea/Native Method...

which is the hint about JDK 9 usage.

Upvotes: 1

Related Questions