如何让 maven 获取发布父 pom 而不是最新的?

How to make maven to obtain release parent pom instead of latest?

使用版本范围声明项目的主 POM 解析为最新版本(包含 SNAPSHOT)。有什么办法让它下定决心释放?

项目中的父 POM 声明:

<parent>
  <groupId>my.company</groupId>
  <artifactId>my-company-pom</artifactId>
  <version>(,2.0.0]</version>
</parent>

父 POM 元数据文件

<metadata>
  <groupId>my.company</groupId>
  <artifactId>my-company-pom</artifactId>
  <version>1.0.1</version>
  <versioning>
    <latest>1.3.0-SNAPSHOT</latest>
    <release>1.2.0</release>
    <versions>
      <version>1.0.0</version>
      <version>1.0.1-SNAPSHOT</version>
      <version>1.0.1</version>
      <version>1.1.0</version>
      <version>1.2.0</version>
      <version>1.3.0-SNAPSHOT</version>
    </versions>
    <lastUpdated>xxxxxxxxxxxx</lastUpdated>
  </versioning>
</metadata>

为什么 Maven 将父 POM 版本解析为 1.3.0-SNAPSHOT 而不是 1.2.0?

因为你设置的1.3.0-SNAPSHOT是最新的,在这一行(父pom元数据XML文件的第6行)

<latest>1.3.0-SNAPSHOT</latest>

您可以在自定义存储库定义中排除快照版本来解决此问题。

<repositories>
 <repository>
  <id>codehaus</id>
   <name>codehaus</name>
   <releases>
    <enabled>true</enabled>
   </releases>
   <snapshots>
    <enabled>false</enabled>
   </snapshots>
   <url>http://snapshots.maven.codehaus.org/maven2</url>
   <layout>default</layout>
  </repository>
</repositories>

Maven 只是不"see" 快照。当然,您必须根据您的存储库调整设置(URL 等)。

如您所见here,对我来说,这是 maven 中一个非常古老、众所周知且有争议的错误,您最好的选择是根本不使用您的情况的版本范围,因为没有真正有效的解决方法。