【发布时间】:2017-10-19 04:55:36
【问题描述】:
我有一个项目,其中包含基于 maven 的混合 kotlin 和 java 代码。如果我通过 maven(从命令行)编译该项目,就可以了
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 30.830 s
[INFO] Finished at: 2017-05-19T07:42:55+01:00
[INFO] Final Memory: 44M/482M
[INFO] ------------------------------------------------------------------------
Java:
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
想法:
IntelliJ IDEA 2017.1.3
Build #IU-171.4424.56, built on May 12, 2017
JRE: 1.8.0_112-release-736-b21 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.12.3
马文:
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T17:41:47+01:00)
Maven home: /Library/apache-maven-3.3.9/apache-maven-3.3.9
Java version: 1.8.0_91, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre
Default locale: cs_CZ, platform encoding: UTF-8
OS name: "mac os x", version: "10.12.3", arch: "x86_64", family: "mac"
Maven 配置:
<project>
..
<properties>
<kotlin.version>1.1.2-2</kotlin.version>
</properties>
..
<dependencies>
..
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jre8</artifactId>
<version>${kotlin.version}</version>
</dependency>
..
</dependencies>
<build>
<plugins>
..
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<configuration>
<jvmTarget>1.8</jvmTarget>
<languageVersion>1.1</languageVersion>
<apiVersion>1.1</apiVersion>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/main/java</source>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>process-test-sources</phase>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/test/java</source>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
..
<plugins>
</build>
</project>
问题是如果我在idea中构建这个项目,我会得到以下错误和许多与这个相关的子错误:
Error:Kotlin: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
class kotlin.reflect.KDeclarationContainer, unresolved supertypes: kotlin.Any
class kotlin.reflect.KAnnotatedElement, unresolved supertypes: kotlin.Any
class kotlin.reflect.KClassifier, unresolved supertypes: kotlin.Any
请问,您知道如何使其在 IntelliJ Idea 中也能正常工作吗?
【问题讨论】:
-
请尝试文件 |使缓存失效作为快速的第一步;这可能会有所帮助。
-
感谢您的建议,但不幸的是这不起作用 - 它的行为完全相同。 (我尝试过使缓存无效并重新启动)
-
下一个快速尝试是重新导入 Maven 项目(Maven 项目工具窗口中的“重新导入所有 Maven 项目”)。
-
您可能还想在 IntelliJ IDEA 中检查您的 Kotlin 插件版本。
-
@mfulton26 这解决了我的问题仅供参考,问题出在 .iml 文件中,如果我只删除 .idea 文件夹,它的行为方式相同,但如果我删除所有想法的东西(包括那个 .iml),它就可以工作就像一个魅力:-) 非常感谢你
标签: java maven intellij-idea kotlin