我正在尝试从Intellij Idea运行Kotlin脚本,但是pom.xml中定义的依赖项未添加到类路径中。在运行配置页面上没有使用模块的类路径选项,就像它用于Kotlin或Java一样。我希望IDE将-classpath
参数传递给org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
因为如果我手动完成所有工作正常。
这是一个错误还是我错过了什么?
noclasspath.kts
import org.slf4j.MDC
val osf = MDC.getMDCAdapter()
val a = "Monkey"
println("$a is big")
的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>org.whatever</groupId>
<artifactId>whyunowork</artifactId>
<version>1.2.3</version>
<properties>
<kotlin.version>1.0.4</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals> <goal>compile</goal> </goals>
<configuration>
<sourceDirs><sourceDir>${project.basedir}/src/main/kotlin</sourceDir><sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs><sourceDir>${project.basedir}/src/main/kotlin</sourceDir><sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals> <goal>compile</goal> </goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals> <goal>testCompile</goal> </goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
这是我从IDEA运行时得到的结果:
/usr/lib/jvm/jdk1.8.0_92/bin/java -Dfile.encoding=UTF-8 -classpath /home/Development/.IdeaIC2016.2/config/plugins/Kotlin/kotlinc/lib/kotlin-compiler.jar:/home/Development/.IdeaIC2016.2/config/plugins/Kotlin/kotlinc/lib/kotlin-reflect.jar:/home/Development/.IdeaIC2016.2/config/plugins/Kotlin/kotlinc/lib/kotlin-runtime.jar org.jetbrains.kotlin.cli.jvm.K2JVMCompiler -script /home/Development/project/src/main/kotlin/noclasspath.kts
noclasspath.kts:1:12: error: unresolved reference: slf4j
import org.slf4j.MDC
^
onyad.kts:3:11: error: unresolved reference: MDC
val osf = MDC.getMDCAdapter()
^
Process finished with exit code 1
IDEA关于页面:
IntelliJ IDEA 2016.2.5
Build #IC-162.2228.15, built on October 14, 2016
JRE: 1.8.0_112-release-287-b2 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Kotlin插件版
1.0.4-release-IJ2016.1-112