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

huangapple go评论93阅读模式
英文:

Maven unable to resolve dependencies for Spring Boot and JUnit

问题

以下是翻译好的部分:

我正在尝试实际操作学习Spring Boot,并通过我的IntelliJ IDE使用Spring Starter导入基本Spring Boot应用程序的样板代码,但Maven无法解析所有依赖项,我的项目缺少重要的依赖项。我无法弄清楚这个问题的原因。

起初,我认为问题是使用JDK8来构建较新版本的Spring Framework,然后我安装了JDK11,但问题仍然存在,据我理解,POM.xml中列出了所有依赖项。

这里是IDE的截图以了解情况:

screenshot

<?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>

这里是无法解析的所有依赖项:

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

英文:

I'm trying to learn Spring Boot hands-on and importing the boilerplate for basic spring boot application through Spring Starter using my IntelliJ IDE, but Maven is unable to resolve all dependencies and my project is missing out on important dependencies. I can't figure out the reason for this.

First I thought the problem was using JDK8 for newer versions of the SpringFramework, then I installed JDK11 but the same problem persists and as far as I can understand POM.xml has all the dependencies listed in it.

Screenshot of IDE to get an idea

    &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
    &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;parent&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
        &lt;version&gt;2.2.6.RELEASE&lt;/version&gt;
        &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
    &lt;/parent&gt;
    &lt;groupId&gt;com.selfspring&lt;/groupId&gt;
    &lt;artifactId&gt;conference-demo&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;name&gt;conference-demo&lt;/name&gt;
    &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;

    &lt;properties&gt;
        &lt;java.version&gt;11&lt;/java.version&gt;
    &lt;/properties&gt;

    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
            &lt;scope&gt;test&lt;/scope&gt;
            &lt;exclusions&gt;
                &lt;exclusion&gt;
                    &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
                    &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
                &lt;/exclusion&gt;
            &lt;/exclusions&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;

    &lt;build&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/build&gt;

    &lt;/project&gt;```

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


</details>


# 答案1
**得分**: 5

尝试删除你的 .m2 文件夹,然后再次拉取依赖。我通常是这样做的:
从 .m/repo 中删除所有内容,然后我进入 IntelliJ,在 pom.xml 中加入空格并删除它,这样它会提示我拉取在 pom.xml 中进行的更改。

编辑:
如果这没有帮助,你始终可以运行以下命令:

    mvn clean - 清除依赖,使你获得类似于全新状态的干净环境

    mvn install - 初始化重新拉取依赖

<details>
<summary>英文:</summary>

Try nuking your .m2 folder, and then pull dependencies again. I usually do it like this:
delete everything from .m/repo, I go to intellij and add space in pom.xml and delete it so it offers me to pull changes that were made in pom.xml

EDIT:
If that does not help, you can always run

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

    mvn install - initiates the pulling of dependencies again

</details>



huangapple
  • 本文由 发表于 2020年4月8日 18:48:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/61098893.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定