9

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,556
  • 1
  • 20
  • 39
Jan Kreischer
  • 679
  • 3
  • 8
  • 21
  • 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
  • Does this answer your question? [package org.springframework.boot does not exist](https://stackoverflow.com/questions/48847951/package-org-springframework-boot-does-not-exist) – Gonçalo Peres Aug 08 '23 at 14:05

13 Answers13

14

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

wshow
  • 141
  • 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
14

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,426
  • 1
  • 12
  • 25
  • 2
    Was able to do a successful "mvn clean install" using terminal. But was getting error in IntelliJ. So I deleted .idea folder from repo, loaded project again in intellij and it worked :) – Tarun Kumar Aug 28 '22 at 07:03
3

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,158
  • 1
  • 11
  • 19
2

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,433
  • 11
  • 23
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
  • 5,021
  • 8
  • 41
  • 57
  • 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

Follow these steps, your problem should be solved. You just need to add Spring-framework-starter-web and Spring-framework-starter-tester from your pom.xml file.

  1. Got to generate(ALT+Insert)
  2. Add dependencies
  3. Search "springframwork"
  4. Add...

Here is the link

Saeid Amini
  • 1,313
  • 5
  • 16
  • 26
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
0

You need to change Maven's JDK for importing option from Project JDK to the Path variable for Java on your machine.

You can get to this by going to Settings -> Build, Execution, Deployment -> Build Tools -> Maven -> Importing. Scroll down to the bottom and look for JDK for importing:. Select from the list the path variable for JAVA.

Above image shows how to change the JDK for importing with Maven.

For Windows users, JAVA_HOME should be an option in the drop-down list.

Khalil
  • 175
  • 2
  • 8
0

In my case, adding the project as maven project helped .

Pooja
  • 1
  • 1
0

For my case, had to change the maven importing settings from the JRE path to the JDK path on my local machine

mozway
  • 194,879
  • 13
  • 39
  • 75
Daphne
  • 1
  • 2
0

I had the same issue , only to find out I made a very careless mistake of having 2 versions of IntelliJ.

I uninstalled all of them and did a new installation, now everything works.

0

I have the same error. I removed all folder and file in this path below:

C:\Users\Lenovo.m2\repository

I opend the intelij IDE and opened the maven:

View -> Tool Windows ->Maven

and clicked on the "Reload All Maven Project". it downloaded the dependencies and run the project again. check before the path below:

C:\Users\Lenovo.m2\repository

it should download all the dependencies.

I hope it is helpfull.

0

I had same issue. I was using IntelliJ IDEA. In my case I deleted .idea folder and re-build the project then it worked well.