javaspringspring-bootmavenintellij-idea

Error: java: package org.springframework.boot does not exist


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:

Any other ideas?


Solution

  • 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.