簡體   English   中英

我如何告訴Maven比起增量版本更喜歡SNAPSHOT版本?

[英]How can I tell maven to prefer SNAPSHOT versions over incremental versions?

因為我的增量內部版本號= CI內部版本號,所以我不想將增量內部版本號放入我的開發POM中。 它應僅具有主要和次要版本組件。

  • POM中的版本=例如1.1-SNAPSHOT
  • 發布版本=例如1.1.23

但是,同一框架內的另一個組件將要說“如果SNAPSHOT版本在本地存在,請使用該版本,否則請使用最新的增量版本”。

如何在我的POM中指定?

我嘗試了這個:

<dependencies>
    <dependency>
        <groupId>com.example.ajb.versionpoc</groupId>
        <artifactId>downstream</artifactId>
        <version>[1.1-SNAPSHOT],[1.1,2.0)</version>
    </dependency>
</dependencies>

但這是行不通的。 仍將版本解析為例如1.1.23。 我如何告訴Maven更喜歡SNAPSHOT版本?

我不太了解您要做什么,但這是一般性的協議:

  1. 僅在開發中使用快照。 切勿將它們放在范圍內。
  2. 您的范圍表達式必須包含兩個參數。 您有兩個范圍與三個范圍。
  3. 提供僅用於穩定發行的范圍。

基於@ DB5關於配置文件的建議,我認為您可以聲明一個包含快照依賴項的特定配置文件。 可以根據本地存儲庫中該庫的存在來完成此類配置文件的激活。

在您的pom的profiles部分中添加以下片段:

    <profile>
        <!--This profile will prefer the SNAPSHOT version if it exists locally-->
        <id>local</id>
        <activation>
            <file>
                <exists>${user.home}/.m2/repository/mygroup/myartifact/myversion-SNAPSHOT/myartifact-myversion-SNAPSHOT.jar</exists>
            </file>
        </activation>
        <dependencies>
            <dependency>
                <groupId>mygroup</groupId>
                <artifactId>myartifact</artifactId>
                <version>myversion-SNAPSHOT</version>
            </dependency>
        </dependencies>
    </profile>

    <profile>
        <!--This profile will prefer the released version if the SNAPSHOT does not exist locally-->
        <id>released</id>
        <activation>
            <file>
                <missing>${user.home}/.m2/repository/mygroup/myartifact/myversion-SNAPSHOT/myartifact-myversion-SNAPSHOT.jar</missing>
            </file>
        </activation>
        <dependencies>
            <dependency>
                <groupId>mygroup</groupId>
                <artifactId>myartifact</artifactId>
                <version>myversion</version>
            </dependency>
        </dependencies>
    </profile>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM