8

I made a simple application today that gives me a few errors when I run. I made another application very similar to this one yesterday which was working fine but is now broke as well

I am getting these errors:

Error:(4, 32) java: package org.springframework.boot does not exist Error:(5, 46) java: package org.springframework.boot.autoconfigure does not exist Error:(6, 35) java: package org.springframework.context does not exist Error:(9, 2) java: cannot find symbol symbol: class SpringBootApplication Error:(13, 17) java: cannot find symbol symbol: class ApplicationContext location: class com.example.dependencyinjection.DependencyInjectionApplication Error:(13, 42) java: cannot find symbol symbol: variable SpringApplication location: class com.example.dependencyinjection.DependencyInjectionApplication Error:(3, 38) java: package org.springframework.stereotype does not exist Error:(5, 2) java: cannot find symbol symbol: class Controller 

Here is my pom.xml

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.7.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>dependency-injection</artifactId> <version>0.0.1-SNAPSHOT</version> <name>dependency-injection</name> <description>Example project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot</artifactId> <version>1.2.3.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 

I have tried:

  • Reimporting all Maven projects
  • Generating sources and updating all folders for all projects
  • Creating a new project using Spring initalizer
  • Checking settings path for settings.xml
  • Deleting the .m2 folder
  • Invalidating caches and restarting
  • Reopening the project with auto imports on
  • Removing/altering VM options for imports
  • Forcing Intellij to reread all maven dependencies
  • Confirming that the dependencies are in Modules
  • Updating Maven repositories
  • Many different pom.xml configurations
  • Cloning and building a project which is known to work
  • Changing Maven's default executable
  • Turning auto sync completely off
  • Reinstalling Intellij

Any other ideas?

3

7 Answers 7

7

There is a known bug in IntelliJ IDEA 2020.1 and 2020.1.1 versions (will be fixed in 2020.1.2) where Maven dependencies are not found by the compiler because the path macros are not resolved properly.

You can use a workaround until the fix is released or downgrade to 2019.3.x version.

The workaround is to override the default setting for Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Maven | Local repository (set it to some other value different from default).

Or else make sure the path.macros.xml file exists in <IDE config>/options directory with the following content:

<application> <component name="PathMacrosImpl"> <macro name="KOTLIN_BUNDLED" value="<path to IDE installation>\plugins\Kotlin\kotlinc" /> <macro name="MAVEN_REPOSITORY" value="<path to>/.m2/repository" /> </component> </application> 

Where the <path to>/.m2/repository - is the path to your local Maven repository and the <path to IDE installation> - the path to IDE installation home.

Sign up to request clarification or add additional context in comments.

1 Comment

You pointed me in the right direction. Mine worked by changing the Maven Home Path to my locally installed maven, instead of using the default Wrapper.
3

in my case have changed Maven import JDK version. In latest version in intellij its pointing to JDK11. then changes to my internal JDK version resolved issueenter image description here

Comments

2

I followed these steps and my project built successfully.

  1. run mvn clean
  2. go to Settings -> Build, Execution, Deployment -> Maven -> Repositories and update them.(not sure if this is nessasary)
  3. Refresh your maven dependancies by clicking the reload button on the maven tab.
  4. Go to build and click on rebuild project.

Comments

1

Add spring-boot-starter-web dependency to your POM

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> 

1 Comment

Thank you for your answer but I'm certain that it doesn't have anything to do with the pom file
0

You don't need the spring-boot dependency in your pom.xml

 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot</artifactId> <version>1.2.3.RELEASE</version> </dependency> 

1 Comment

Thank you for the answer but it's still giving me the error
0

Well, I was able to solve the issue by simply restarting my laptop having all required dependencies and JDK setup.

Comments

0

This worked for me

Delete the .idea folder from your workspace

do invalidate cache

Go to File -> Project Structure

Under Project -> Check SDK, Language Level

Under Modules -> Mark respective directories as Source, Resources and Tests

Under SDK -> Select your required JDK version

Click Apply

Perform clean install to delete Target folder

And you are good to go.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.