首页 > 解决方案 > Maven 版本范围:发布与快照版本

问题描述

使用 Apache Maven 3.3.9,我们使用 maven 范围来解析一些依赖项版本,因为我的应用程序中有很多 maven 模块,保持特定的依赖项版本并更改为每个版本有点痛苦。

为了说明当前应用程序的结构

pom.xml(父)

<groupId>com.myapp</groupId>
<artifactId>myapp</artifactId>
<version>0.0.5-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parentpom</name>
<modules>
    <module>../myapp-service</module>
</modules>
<dependencies>
    <dependency>
        <groupId>com.someotherapp</groupId>
        <artifactId>someotherappA</artifactId>
        <version>[1.1.0, 1.2.0)</version>
    </dependency>

    <dependency>
        <groupId>com.someotherapp</groupId>
        <artifactId>someotherappB</artifactId>
        <version>[1.1.0, 1.2.0)</version>
    </dependency>
</dependencies>

pom.xml(子模块)

 <parent>
        <groupId>com.myapp</groupId>
        <artifactId>myapp</artifactId>
        <version>[0.0.1,2.0.0)</version>
        <relativePath>../myapp/pom.xml</relativePath>
    </parent>

    <groupId>com.myapp.service</groupId>
    <artifactId>myapp-service</artifactId>
    <version>1.0.9-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>myapp-service</name>
    <dependencies>
        <dependency>
            <groupId>com.someotherapp</groupId>
            <artifactId>ssomeotherappA</artifactId>
        </dependency>
    
        <dependency>
            <groupId>com.someotherapp</groupId>
            <artifactId>someotherappB</artifactId>
        </dependency>
    </dependencies>

期望:我希望子模块应该选择最后发布的依赖版本(无快照),如 someotherappA-1.2.0 而不是最新版本“someotherappA-1.2.1-SNAPSHOT”

问题:如果工件中可用的依赖版本像“someotherappA-1.2.1-SNAPSHOT”(最新快照)和“someotherappA-1.2.0”(稳定版本),那么maven工件“myapp-service”选择SNAPSHOT依赖而不是发布版本,即使很难,我也在指定-DallowSnapshots=false这意味着 maven 版本范围中不允许使用快照版本。

这是我用来构建子模块的内容

mvn versions:resolve-ranges -f "myapp-service/pom.xml" -DgenerateBackupPoms=true -DallowSnapshots=false -DprocessDependencyManagement=false -DprocessParent=true

mvn clean install

我在这里发现了类似的问题,如何停止使用快照的 maven 版本范围,并且似乎 maven https://issues.apache.org/jira/browse/MNG-3092中有一个未解决的错误。但是,如果有人绕过这个类似的问题,我正在寻找可能的解决方法或解决方案。

标签: mavenmaven-release-plugin

解决方案


推荐阅读