7

Dear Stackoverflow Community, I have the following problem with my spring boot starter application. I imported the starter project as a new maven project into IntelliJ. But IntelliJ does not find the dependencies I specified in the pom.

Image of my Application Class:

If I try to run the project I get the following error message.

Image of the Error Message:

I already tried everything from re-installing IntelliJ to re-importing the project or redownloading the dependencies. I simply dont know why IntelliJ doesn´t find the dependencies.

My pom.xml looks as following

Image of my pom.xml:

The first time I tried to edit the pom.xml it said to me "this file does not belong to the project". Maybe this might be one reason.

Running the whole thing with 'mvn install' or 'mvn clean verify' works.

Majid Roustaei
  • 1,194
  • 1
  • 14
  • 31
Jan Kreischer
  • 591
  • 3
  • 6
  • 18
  • Thank you for your suggestion. I tried it but it did not work out when i tried without "importing as maven". I am going to try it with a new project if I get the same error. – Jan Kreischer Dec 20 '18 at 13:00
  • Go to the project settings (the drop down located at the top right corner in intelliji). Make sure that your application is selected – Diallo Dec 31 '20 at 13:48

6 Answers6

10

Try this and then build: mvn -U idea:idea

wshow
  • 101
  • 1
  • 3
  • 1
    Welcome to Stack Overflow. In your answer *Try this and then build: mvn -U idea:idea* – please elaborate what you refer to by *try this*. Also when answering an old question having an accepted answer (look for the green ✓) ensure your answer adds something new or is otherwise helpful in relation to it. You're not explaining why your answer solves the problem. Please refer to this [contribution guide](https://stackoverflow.com/help/how-to-answer) for details. – Ivo Mori Sep 25 '20 at 00:04
  • Thanks @wshow for your answer. Do you know how automatically run this command ? Because I have to fix this everytime I add a maven dependency. – Damien C May 06 '21 at 13:24
  • I use this and it worked! thank you @wshow. For the others wondering write it exactly as it is! – Bryan J. Diaz Nov 17 '21 at 14:47
  • For anyone wondering what does this mvn build does: it installs all the plugins and downloads all dependencies, as well as setting project wise files. – SkiiNet Jan 21 '22 at 21:59
6

Had the same problem. I have tried everything: invalidating cache, deleting the whole .m2 folder, changing settings, reloding the project, nothing helped.

The solution for me was to delete the .iml files which are IntelliJ module files used for keeping module configuration. After reopening the project it worked.

The idea was not mine, I found the hint here: https://intellij-support.jetbrains.com/hc/en-us/community/posts/203365204--package-does-not-exist-error-despite-autocomplete-being-aware-of-them

Márk Farkas
  • 1,144
  • 1
  • 10
  • 20
1

Here is how my IntelliJ settings for spring boot application looks like

Click open -> browse your workspace -> and select POM.xml file Click open -> browse your workspace -> and select POM.xml file

Check this in your intelliJ settings Check this in your intelliJ settings

Do this too [Settings --> Maven --> Importing]

enter image description here

smilyface
  • 4,259
  • 7
  • 40
  • 49
  • 1
    I tried it like you described. My IntelliJ said "Non-managed pom.xml file found". I clicked "add as maven project" but the error still persists – Jan Kreischer Dec 20 '18 at 13:16
  • See the right (green tick) answer and first comment of that answer in this post - https://stackoverflow.com/questions/15727356/intellij-idea-cannot-resolve-anything-in-maven – smilyface Dec 20 '18 at 13:19
  • If that doesn't fix the issue try to replace your maven pox xml file - by creating a new one https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html – smilyface Dec 20 '18 at 13:19
  • Edited my post to add that screenshot too – smilyface Dec 20 '18 at 13:24
  • Thanks i am going to read through those two articles. I just wanted to mention that 'mvn install' creates a runnable jar file – Jan Kreischer Dec 20 '18 at 13:35
  • 1
    We managed to get it running by creating a new project with spring initializr like we did the first time. I dont know why it works now – Jan Kreischer Dec 20 '18 at 13:57
  • Great to know ! – smilyface Dec 21 '18 at 06:22
1

in my case changed JDK version in Maven importer from JDK 11 to my local JDK version 1.8

enter image description here

Anand saga
  • 1,313
  • 9
  • 22
0

Sometimes your workspace could get corrupted. In my case, I tried to Reload the project and it worked

enter image description here

Anupama Boorlagadda
  • 1,058
  • 1
  • 10
  • 18
0

I just had the same issue. My solution was to remove all dependencies from the pom, reload via maven -> Reload All Maven Projects. Run mvn compile. Add dependencies back to the pom, maven -> Reload All Maven Projects. Run mvn compile. Now the Intellij build works.

Dan Poulos
  • 41
  • 2