[英]Intellij Idea won't compile kotlin but maven does
我有項目,其中包含基於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
Maven的:
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>
問題是如果我在構思中構建這個項目,我會得到以下錯誤和許多與此相關的子錯誤:
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中運行?
有時,在.idea
和/或*.iml
文件下的項目設置中設置事物,最簡單的方法是從頭開始啟動IntelliJ IDEA項目。
如果您的項目受源代碼控制(例如使用git-scm),那么您只需刪除本地克隆,再次克隆它,然后重新創建項目。
如果您不能這樣做,那么您可以手動刪除.idea
文件夾和任何*.iml
文件。 請注意,IML文件可能位於項目的根目錄和子目錄中。 在IntelliJ IDEA中未打開項目時需要刪除這些項,因為否則當您關閉項目時,它可能會將其中一些文件寫回文件系統。
重新創建項目通常是最后的手段,但有時候當項目工作不正常並且無法弄清楚原因時,這是最簡單的事情。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.