Maven 无法解析 Spring Boot 和 JUnit 的依赖关系

0 java spring pom.xml maven spring-boot

我正在尝试学习 Spring Boot 实践,并使用我的 IntelliJ IDE 通过 Spring Starter 导入基本 Spring Boot 应用程序的样板,但 Maven 无法解析所有依赖项,并且我的项目错过了重要的依赖项。我不明白这是什么原因。

首先,我认为问题出在使用 JDK8 作为较新版本的 SpringFramework,然后我安装了 JDK11,但同样的问题仍然存在,据我所知 POM.xml 列出了其中的所有依赖项。

IDE 的屏幕截图来了解一下

    <?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.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.selfspring</groupId>
    <artifactId>conference-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>conference-demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </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>```

here is all the dependencies it is unable to resolve:

Cannot resolve org.hibernate.validator:hibernate-validator:6.0.18.Final
Cannot resolve org.hamcrest:hamcrest:2.1
Cannot resolve org.ow2.asm:asm:5.0.4
Cannot resolve org.springframework:spring-expression:5.2.5.RELEASE
Cannot resolve org.junit.platform:junit-platform-engine:1.5.2
Cannot resolve net.minidev:accessors-smart:1.2
Cannot resolve net.bytebuddy:byte-buddy:1.10.8
Cannot resolve jakarta.xml.bind:jakarta.xml.bind-api:2.3.3
Cannot resolve org.springframework:spring-aop:5.2.5.RELEASE
Cannot resolve com.fasterxml:classmate:1.5.1
Cannot resolve org.junit.jupiter:junit-jupiter-api:5.5.2
Cannot resolve org.mockito:mockito-junit-jupiter:3.1.0
Cannot resolve org.opentest4j:opentest4j:1.2.0
Cannot resolve org.objenesis:objenesis:2.6
Cannot resolve org.springframework:spring-webmvc:5.2.5.RELEASE
Cannot resolve org.springframework.boot:spring-boot-test-autoconfigure:2.2.6.RELEASE
Cannot resolve net.bytebuddy:byte-buddy-agent:1.10.8
Cannot resolve org.junit.jupiter:junit-jupiter:5.5.2
Cannot resolve org.springframework.boot:spring-boot-test:2.2.6.RELEASE
Cannot resolve jakarta.validation:jakarta.validation-api:2.0.2
Cannot resolve org.jboss.logging:jboss-logging:3.4.1.Final
Cannot resolve net.minidev:json-smart:2.3
Cannot resolve org.springframework:spring-test:5.2.5.RELEASE
Cannot resolve org.assertj:assertj-core:3.13.2
Cannot resolve jakarta.activation:jakarta.activation-api:1.2.2
Cannot resolve org.skyscreamer:jsonassert:1.5.0
Cannot resolve org.springframework.boot:spring-boot-starter-test:2.2.6.RELEASE
Cannot resolve org.mockito:mockito-core:3.1.0
Cannot resolve com.vaadin.external.google:android-json:0.0.20131108.vaadin1
Cannot resolve com.jayway.jsonpath:json-path:2.4.0
Cannot resolve org.junit.jupiter:junit-jupiter-params:5.5.2
Cannot resolve org.xmlunit:xmlunit-core:2.6.4
Cannot resolve org.springframework:spring-jcl:5.2.5.RELEASE
Cannot resolve org.apiguardian:apiguardian-api:1.1.0
Cannot resolve org.springframework:spring-beans:5.2.5.RELEASE
Cannot resolve org.junit.jupiter:junit-jupiter-engine:5.5.2
Cannot resolve org.junit.platform:junit-platform-commons:1.5.2

Run Code Online (Sandbox Code Playgroud)

zaw*_*udo 5

尝试删除 .m2 文件夹,然后再次提取依赖项。我通常这样做:删除 .m/repo 中的所有内容,我转到 intellij 并在 pom.xml 中添加空格并删除它,这样它就可以让我提取在 pom.xml 中所做的更改

编辑:如果这没有帮助,你可以随时运行

mvn clean - clear dependencies so you get something like a clean slate

mvn install - initiates the pulling of dependencies again
Run Code Online (Sandbox Code Playgroud)