java - Maven dependencies not recognized by Intellij after they are downloaded with success when running maven clean and install

admin2025-04-29  1

I have a strange problem in IntelliJ IDEA not recognizing dependencies when using an existing (working) maven application. The dependencies are successfully downloaded when building the application so they should be recognized by the application. Also not all dependencies the project uses are not recognized, only a small part.

I assume that the dependencies are not recognized because they are displayed in red in IntelliJ

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.MultipartBodyBuilder;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.ObjectMapper;

Below a summary of the things I did so far in the same order:

  1. I imported the maven project from git to my local file system and I opened the project in IntelliJ IDEA 2024.1.2
  2. I ran maven clean with success. (all dependencies were downloaded successfully at the maven nexus repository manager and I received the BUILD SUCCESS at the end)
  3. I ran maven install with success. (all dependencies were downloaded successfully at the maven nexus repository manager and I received the BUILD SUCCESS at the end)
  4. After maven clean and maven install I successfully reloaded the project.
  5. I created a Maven Run configuration for the execution of the project
  6. When running the created maven run configuration I receive a lot of errors when I am actually running it like:
package com.fasterxml.jackson.databind does not exist
package org.springframework.boot does not exist
package org.springframework.boot does not exist
package org.springframework.boot.autoconfigure does not exist
package org.springframework.http.client does not exist
package org.springframework.http.client does not exist
package org.springframework.http.client does not exist
package org.springframework.web.client does not exist
cannot find symbol class CommandLineRunner
cannot find symbol class SpringBootApplication
cannot find symbol class RestTemplate
cannot find symbol class HttpHeaders
cannot find symbol class RestTemplate
package org.springframework.http does not exist

Below the dependency section of my pom.xml

    <dependencies>
        <dependency>
            <groupId>org.apachemons</groupId>
            <artifactId>commons-csv</artifactId>
            <version>1.5</version>
        </dependency>

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

    </dependencies>

As said above the dependencies which are listed in red by IntelliJ are successfully downloaded and stored under the .m2 folder

Another thing I notified and which seems very strange is that when creating a run configuration there is no section of spring boot under the run options section. It should look like this:

enter image description here

But in my IDEA the section of spring boot options is missing. It seems that the application is not recognized as spring boot application.

Things I tried so far to solve the issue:

  • Running maven Generate sources and update folders for all projects
  • Running Maven Reload Project
  • Reload caches using the invalidate caches section in intelliJ IDEA
转载请注明原文地址:http://anycun.com/QandA/1745934939a91336.html