Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Kotlin REPL from context of my Maven project?

How can I run the Kotlin REPL in the context of my Maven project?

This works, but is ugly:

kotlinc-jvm -cp target/classes/:`ruby -e "puts Dir['target/**/*.jar'].join(':')"`

I've tried different variations on the following (after using Maven to copy the compiler JAR as a dependency), but nothing works (Error: Could not find or load main class org.jetbrains.kotlin.runner.Main):

<plugin>  
  <groupId>org.codehaus.mojo</groupId> 
  <artifactId>exec-maven-plugin</artifactId> 
  <version>1.1.1</version> 
  <executions>
    <execution>
    <goals>
      <goal>exec</goal> 
    </goals>
    </execution>
  </executions>
  <configuration>
    <executable>java</executable>
    <arguments>
      <argument>-classpath</argument>
      <classpath/>
      <argument>-classpath</argument>
      <argument>${project.basedir}/target/dependency/kotlin-compiler-1.0.0.jar</argument>
      <argument>org.jetbrains.kotlin.runner.Main</argument>
    </arguments>
  </configuration>
</plugin>
like image 609
Jacob Brown Avatar asked Feb 23 '16 23:02

Jacob Brown


1 Answers

Please try K2JVMCompiler instead, since it's currently the entrypoint for REPL in kotlin-compiler.jar:

<configuration>
    <executable>java</executable>
    <arguments>
      <argument>-classpath</argument>
      <classpath/>
      <argument>-classpath</argument>
      <argument>${project.basedir}/target/dependency/kotlin-compiler-1.0.0.jar</argument>
      <argument>org.jetbrains.kotlin.cli.jvm.K2JVMCompiler</argument>
    </arguments>
  </configuration>
like image 139
Alexander Udalov Avatar answered Nov 20 '22 02:11

Alexander Udalov