从我的Maven项目的上下文中运行Kotlin REPL?

Jac*_*own 9 read-eval-print-loop kotlin

如何在我的Maven项目中运行Kotlin REPL?

这有效,但很难看:

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

我在下面尝试了不同的变体(在使用Maven将编译器JAR复制为依赖项之后),但没有任何作用(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>
Run Code Online (Sandbox Code Playgroud)

Ale*_*lov 5

请尝试K2JVMCompiler改为,因为它目前是REPL的入口点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>
Run Code Online (Sandbox Code Playgroud)