如何在Maven项目的上下文中运行Kotlin REPL?
这很有效,但很难看:
kotlinc-jvm -cp target/classes/:`ruby -e "puts Dir['target/**/*.jar'].join(':')"`
我在下面尝试了不同的变体(在使用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>
答案 0 :(得分:5)
请尝试K2JVMCompiler
,因为它目前是kotlin-compiler.jar
中REPL的入口点:
<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>