zoukankan      html  css  js  c++  java
  • 【dependencyManagement版本管理】dependencies.dependency.version is missing

    maven 的gav的v(版本问题)

    报错dependencies.dependency.version is missing

    出现的场景

    一个项目中有多个模块

    • 父模块中出现dependencies.dependency.version is missing

    • 子模块中出现dependencies.dependency.version is missing

    模块结构

    父模块结构(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>
        <groupId>com.wangguofa.cloud</groupId>
        <artifactId>cloud</artifactId>
        <version>0.0.1</version>
        <name>cloud</name>
        <packaging>pom</packaging>
    
        <modules>
            <module>cloud-common</module>
        </modules>
    
        <properties>
            <java.version>1.8</java.version>
            <mybatis-plus-boot-starter.version>3.3.0</mybatis-plus-boot-starter.version>
            <hutool-all.version>5.5.7</hutool-all.version>
            <spring-boot.version>2.3.7.RELEASE</spring-boot.version>
        </properties>
    
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter</artifactId>
                </dependency>
                <dependency>
                    <groupId>com.baomidou</groupId>
                    <artifactId>mybatis-plus-boot-starter</artifactId>
                    <version>${mybatis-plus-boot-starter.version}</version>
                </dependency>
                <dependency>
                    <groupId>cn.hutool</groupId>
                    <artifactId>hutool-all</artifactId>
                </dependency>
            </dependencies>
        </dependencyManagement>
        <!-- 父项目中引入部分依赖 -->
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-redis</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-aop</artifactId>
            </dependency>
        </dependencies>
    </project>
    

    点击Maven的生命周期test出现如下错误

    [ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-data-redis:jar is missing. @ line 48, column 21
    [ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-aop:jar is missing. @ line 52, column 21
    

    是因为少写了一个父类的引用,参考链接:https://blog.csdn.net/qq_32198005/article/details/77671803

    添加一个<parent>标签

    <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.3.7.RELEASE</version>
    </parent>
    

    子模块结构(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">
        <parent>
            <groupId>com.wangguofa.cloud</groupId>
            <artifactId>cloud</artifactId>
            <version>0.0.1</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.wangguofa.cloud</groupId>
        <artifactId>cloud-common</artifactId>
        <version>0.0.1</version>
        <name>cloud-common</name>
        <description>Demo project for Spring Boot</description>
    
        <properties>
            <java.version>1.8</java.version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <spring-boot.version>2.3.7.RELEASE</spring-boot.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>cn.hutool</groupId>
                <artifactId>hutool-all</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</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>
    </project>
    

    点击Maven的生命周期test出现如下错误

    'dependencies.dependency.version' for cn.hutool:hutool-all:jar is missing. @ line 24, column 21
    'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter:jar is missing. @ line 38, column 21
    

    子项目的版本,如果没有添加是根据父项目的,观察到dependencyManagement并没有写这两个的版本,需要在父项目中添加版本

    <dependency>
    	<groupId>org.springframework.boot</groupId>
    	<artifactId>spring-boot-starter</artifactId>
    	<version>${spring-boot.version}</version>
    </dependency>
    <dependency>
    	<groupId>cn.hutool</groupId>
    	<artifactId>hutool-all</artifactId>
    	<version>${hutool-all.version}</version>
    </dependency>
    
  • 相关阅读:
    三种省市级联下拉列表的写法
    三种省市级联下拉列表的写法
    SQL经典试题(mysql)
    60行代码俄罗斯方块
    ibatis xml中配置信息详解
    60行代码俄罗斯方块
    xinetd
    csh and tcsh
    xinetd restart
    bash sh
  • 原文地址:https://www.cnblogs.com/10134dz/p/14294535.html
Copyright © 2011-2022 走看看