Class 'kotlin.KotlinPackage' was compiled with an incompatible version of Kotlin

I tried to invoke kotlin compiler from Java code, and when I execute it from IDEA, it reports such error:

> ERROR: X:WORKSPACEdive_in_playInvokeCompilerslibkotlin-runtime.jar!/kotlin/KotlinPackage.class: (-1, 136) Class 'kotlin.KotlinPackage' was compiled with an incompatible version of Kotlin. Its ABI version is 2, expected ABI version is 1 > ERROR: X:WORKSPACEdive_in_playInvokeCompilerslibkotlin-runtime.jar!/kotlin/io/IoPackage.class: (-1, 139) Class 'kotlin.io.IoPackage' was compiled with an incompatible version of Kotlin. Its ABI version is 2, expected ABI version is 1

My code is simple:

import org.jetbrains.jet.cli.common.CLICompiler; import org.jetbrains.jet.cli.common.ExitCode; import org.jetbrains.jet.cli.jvm.K2JVMCompiler; import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments;

import java.util.ArrayList;
import java.util.List;

/**

  • User: Administrator

  • Date: 13-4-1

  • Time: 下午12:33
    */
    public class CompileByKotlin {

      private static final String ROOT = “X:\WORKSPACE\dive_in_play\InvokeCompilers”;
      private static final String SOURCES = ROOT + “\kotlin-data\sources”;
      private static final String BYTECODES = ROOT + “\kotlin-data\bytecodes”;

      public static void main(String args) {
      K2JVMCompilerArguments arguments = new K2JVMCompilerArguments();
      List<String> sourcesList = new ArrayList();
      sourcesList.add(SOURCES);
      arguments.setSourceDirs(sourcesList);
      arguments.setOutputDir(BYTECODES);
      arguments.noJdkAnnotations = true;
      arguments.setClasspath(ROOT + “\lib”);

    &nbsp;&nbsp;CLICompiler compiler = new K2JVMCompiler();
    &nbsp;&nbsp;final ExitCode exitCode = compiler.exec(System.err, arguments);
    &nbsp;&nbsp;if (exitCode != ExitCode.OK) {
    

           System.out.println("Error: " + exitCode);
  }
  }
}

And there are a sources dir which contains 2 kotlin files:

Sorry, it submits before I complete.

AAA.kt

``

fun main(args: Array<String>) {
  BBB().hello();
}

BBB.kt

``

class BBB {
  fun hello(){
  println(“Hello, Kotlin!”)
  }
}

And in my “lib” directory, there are two kotlin jars:

  • kotlin-compiler.jar
  • kotlin-runtime.jar
Which comes from "kotlin-compiler-0.5.1".

And I have installed Kotlin-plugin in my IDEA.

I have tried to find the solution more than 1 hour, still not found the reason yet. So I ask it here for help.

You kotlin-compiler.jar and kotlin-runtime.jar a re out of sync: they come from different version sof Kotlin

Also, you can use forward slashes in paths inside Java strings

Thank you so much!

I just deleted them, and copy the two files from kotlin-compiler-0.5.1 again, everything work well this time!