我尝试将Kotlin与Maven一起使用,所以我遵循了documentation
我在pom.xml
文件中有这个配置
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<kotlin.version>1.2.10</kotlin.version>
</properties>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<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>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
来源文件夹为src/main/kotlin
和src/test/kotlin
当我mvn clean install
时,我收到了此错误
[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.2.10:compile (compile) on project kotlin-starter: Execution compile of goal org.jetbrains.kotlin:kotlin-maven-plugin:1.2.10:compile failed: A required class was missing while executing org.jetbrains.kotlin:kotlin-maven-plugin:1.2.10:compile: kotlin/reflect/KDeclarationContainer
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.jetbrains.kotlin:kotlin-maven-plugin:1.2.10
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
...
我也尝试使用kotlin-stdlib
代替kotlin-stdlib-jdk8
,但我遇到了同样的错误。当我打开库时,我在包KDeclarationContainer
中看到了类kotlin.reflect
,所以我不明白为什么会出现这个错误?
编辑:当我将kotlin版本更改为<kotlin.version>1.1.61</kotlin.version>
时,一切正常...
答案 0 :(得分:2)
我和kotlin-maven-plugin / 1.2.20有一个非常类似的问题,在我从我当地的maven repo中删除org / jetbrains并重新运行构建后,它就消失了。我只能认为某些内容已损坏或丢失。