缺少依赖版本-缺少io.vertx:vertx-stack-depchain:jar的'dependencies.dependency.version'

时间:2020-08-17 21:22:44

标签: java xml maven pom.xml vert.x

尝试为父pom中的不同模块指定我的vertx版本。 我的父pom文件是:

<groupId>com.abc.xyc</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Parent POM</name>

<modules>
    ...
    <module>Server</module>
    ...
</modules>

<properties>
    ...
    <vertx.version>3.8.2</vertx.version>
    <vertx.verticle>com.abc.xyc.as4.MainVerticle</vertx.verticle>
    <vertx-maven-plugin.version>1.0.22</vertx-maven-plugin.version>
    <lmax.version>3.4.2</lmax.version>
    ...
</properties>

<dependencyManagement>
    <dependencies>
        ...
        <dependency>
            <groupId>io.vertx</groupId>
            <artifactId>vertx-stack-depchain</artifactId>
            <version>${vertx.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>io.vertx</groupId>
            <artifactId>vertx-core</artifactId>
            <version>${vertx.version}</version>
        </dependency>
        ...
    </dependencies>
</dependencyManagement>

<build>
        <pluginManagement>
            ...
            <plugins>
                <plugin>
                    <groupId>io.reactiverse</groupId>
                    <artifactId>vertx-maven-plugin</artifactId>
                    <version>${vertx-maven-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>vmp</id>
                            <goals>
                                <goal>initialize</goal>
                                <goal>package</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <redeploy>true</redeploy>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManageme>
</build>

这是我的孩子pom文件

<artifactId>Server</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
    <groupId>com.abc.xyc</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>

<dependencies>
    ...
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-stack-depchain</artifactId>
    </dependency>
    ... 
</dependencies>

我得到的错误是:缺少io.vertx:vertx-stack-depchain:jar的'dependencies.dependency.version'。当我在子pom中指定版本时,它可以正常工作。我的问题是为什么它不从我的父pom获取版本?

1 个答案:

答案 0 :(得分:1)

这是因为它没有“管理”自己的版本,而是通过<dependencyManagement>管理其他依赖项。

通常,不需要导入vertx-stack-depchain作为依赖对象,它应该是parent或像您在<scope>import</scope>进行依赖管理时所做的那样,然后您可以您的孩子poms中的内容如下:

<dependency>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-core</artifactId>
</dependency>

如果仍然有很好的理由导入dep-chain本身,则需要指定版本。