3

I have project, which contains mixed kotlin and java code based on maven. If I compile that project by maven (from command line), it is ok

[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)

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:

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:

<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?

  • 2
    Please try File | Invalidate Caches as the quick first step; this might help. – yole May 19 '17 at 07:12
  • Thank you for suggestion, but unfortunatelly this doesn't work - it behaves exactly same. (I tried Invalidate Caches and Restart) – Jaroslav Strouhal May 19 '17 at 11:09
  • Next quick thing to try is reimporting the Maven project ("Reimport All Maven Projects" in the Maven Projects toolwindow). – yole May 19 '17 at 11:19
  • You may want to check your Kotlin Plugin version in IntelliJ IDEA as well. – mfulton26 May 19 '17 at 17:55
  • @yole Unfortunately, reimporting the Maven project doesn't help as well – Jaroslav Strouhal May 20 '17 at 05:09
  • @mfulton26 I have Version: 1.1.2-release-IJ2017.1-2, which seems to be the latest one – Jaroslav Strouhal May 20 '17 at 05:14
  • The last time I had an issue like this I closed the project, removed it from IntelliJ IDEA's recent projects list, went and found the .idea folder and completely deleted it, and finally recreated the IntelliJ IDEA project as if I had just cloned those sources from a guy repository or something. This forced IntelliJ IDEA to inspect the sources and create the project fresh which seemed to resolve my problem. You're mileage may vary though. :-) – mfulton26 May 20 '17 at 12:01
  • 1
    @mfulton26 this solves my problemFYI the problem was in .iml file, if I remove only .idea folder it behaves in same way but if I remove all idea stuff (including that .iml), it works like a charm :-) thank you very much – Jaroslav Strouhal May 21 '17 at 05:04

1 Answers1

4

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.

If your project is under source control (e.g. using git-scm) then you can simply delete your local clone, clone it again, and recreate the project.

If you can't do that then you can manually delete the .idea folder and any *.iml files. Note that IML files may be at the root of your project and in sub directories. 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.

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.

mfulton26
  • 29,956
  • 6
  • 64
  • 88