简体   繁体   English

Intellij Idea不会编译kotlin但maven会编译

[英]Intellij Idea won't compile kotlin but maven does

I have project, which contains mixed kotlin and java code based on maven. 我有项目,其中包含基于maven的混合kotlin和java代码。 If I compile that project by maven (from command line), it is ok 如果我通过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的:

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)

Idea: 理念:

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: 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 configuration: 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>

The problem is that if I build this project in idea, I get following error and many sub errors related to this one: 问题是如果我在构思中构建这个项目,我会得到以下错误和许多与此相关的子错误:

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

Please, do you have any idea how to make it work in IntelliJ Idea as well? 请问,您是否知道如何使其在IntelliJ Idea中运行?

Sometimes things get set in project settings under .idea and/or in *.iml files and the simplest thing to do is to start the IntelliJ IDEA project over from scratch. 有时,在.idea和/或*.iml文件下的项目设置中设置事物,最简单的方法是从头开始启动IntelliJ IDEA项目。

If your project is under source control (eg using git-scm) then you can simply delete your local clone, clone it again, and recreate the project. 如果您的项目受源代码控制(例如使用git-scm),那么您只需删除本地克隆,再次克隆它,然后重新创建项目。

If you can't do that then you can manually delete the .idea folder and any *.iml files. 如果您不能这样做,那么您可以手动删除.idea文件夹和任何*.iml文件。 Note that IML files may be at the root of your project and in sub directories. 请注意,IML文件可能位于项目的根目录和子目录中。 You need to delete these while the project is not open in IntelliJ IDEA because otherwise when you close the project it may write some of these files back out to the file system. 在IntelliJ IDEA中未打开项目时需要删除这些项,因为否则当您关闭项目时,它可能会将其中一些文件写回文件系统。

Recreating the project is usually a last resort but sometimes it is the easiest thing to do when your project isn't working right and you can't figure out why. 重新创建项目通常是最后的手段,但有时候当项目工作不正常并且无法弄清楚原因时,这是最简单的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM