2

I have the following problem with a multi module maven project:

The project was initially created in Eclipse and can be compiled and run there. It also can be built with mvn install.

Now when I import the project into Intellij using the following import options the parent pom.xml is recognized and the project and its modules are imported.

Everything looks fine, but when I try to compile it, one class, that has a class from another module as a dependency, cannot be found.

I tried a lot of solutions and the ONLY one that worked for me is the outdated maven idea plugin mvn idea:idea as suggested in this thread. Now every time something in any of the projects poms changes, I have to rerun mvn idea:idea and hope that it works - otherwise I have to import the whole project again.

What am I doing wrong in the import process? Why does mvn install on the command line work, but building the project in Intellij does not?

Infire
  • 41
  • 1
  • 6
  • 2
    The $64 question is "Can it be built with `mvn clean install` outside of Eclipse?". If the answer is "no", then you will know why Intellij cannot build it. Note that the `clean` is important - don't leave it out. – Steve C Apr 16 '18 at 13:02
  • This is a good point. I can build it with `mvn clean install`outside of Eclipse, so I suppose I made some mistake during the Intellij import. – Infire Apr 16 '18 at 15:53
  • Possible duplicate of [IDEA JetBrains IntelliJ - Compile error on 'make' but fine when compiled using Maven and no errors reported by IntelliJ in the class file](https://stackoverflow.com/questions/3677174/idea-jetbrains-intellij-compile-error-on-make-but-fine-when-compiled-using-m) – OhadR Feb 06 '19 at 14:43

1 Answers1

4

Try to clear the Intellj Cache once by going to File -> Invalidate Caches/Restart click it. You will get an options, In there select Invalidate and Restart.

Re-import the maven project and compile again it should work.

Rohan S Raju
  • 426
  • 3
  • 7
  • 20
  • 2
    This and 'mvn idea:idea' is basically what I do now after EVERY pom change and I hope this is not the only solution. ;-) – Infire Apr 16 '18 at 09:24
  • 1
    No intellj will build cache so may be some times it get corrupted. Its only required once.. Once you have done it. it will work flawlessly. There will be cache folder under .intellj in linux or windows which need to be cleaned up. After invalidating the cache every pom change will work get updated automically based on seetings – Rohan S Raju Apr 16 '18 at 09:26
  • make sure to "enable auto-import" – BitfulByte Apr 16 '18 at 10:54