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”);
CLICompiler compiler = new K2JVMCompiler();
final ExitCode exitCode = compiler.exec(System.err, arguments);
if (exitCode != ExitCode.OK) {
System.out.println("Error: " + exitCode);
}
}
}
And there are a sources dir which contains 2 kotlin files: