pom.xml 每次添加新依赖时都会出错

Posted

技术标签:

【中文标题】pom.xml 每次添加新依赖时都会出错【英文标题】:pom.xml gives error every time on adding new dependency 【发布时间】:2020-01-20 02:21:24 【问题描述】:

我有一个 pom.xml 文件错误,其中包含依赖项/插件。每次我添加新的依赖项时,它都会给出与版本相关的错误。目前它给出了与 Eureka 服务器相关的错误。

在 pom.xml 中为 Eureka 命名服务器添加依赖项后的错误消息

项目构建错误:org.springframework.cloud:spring-cloud-starter-eureka:jar 的“dependencies.dependency.version”缺失。

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.1.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.in28minutes.microservices</groupId>
    <artifactId>currency-conversion-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>currency-conversion-service</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.SR3</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-netflix-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
        <dependency> <--- ERROR HERE
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>

        </dependency>
         <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>$spring-cloud.version</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

【问题讨论】:

spring-cloud-starter-eureka is not resolving when i use Finchley.M5 和/或 ***.com/questions/51921033/… 的可能重复 【参考方案1】:

该依赖已被弃用,因此它不包含在导入的依赖管理中,另请参阅https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka 处的备注:

Spring Cloud Starter Eureka(已弃用,请使用 spring-cloud-starter-netflix-eureka-client

所以只需使用:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

【讨论】:

以上是关于pom.xml 每次添加新依赖时都会出错的主要内容,如果未能解决你的问题,请参考以下文章

SBT 对非 SBT 库的依赖

如何将照片(以及标签和按钮)放入滚动视图中,每次在情节提要中添加新照片时都会延长它

我的查询有啥问题?为啥每次单击列按钮时都会出错? [关闭]

maven-不在 pom.xml 文件中下载新添加的依赖项

如何在 pom.xml 中添加\安装到新创建\第三方 jar 的 maven 依赖项

每次提交时都会删除Composer包