使用 Maven 动态版本控制发布库

Using Maven dynamic versioning to release a library

从 Maven 3.5.0 开始,可以在 <version> 标签中使用一些变量: https://maven.apache.org/maven-ci-friendly.html

假设我有 <version>${revision}</version>,在一个库项目中(它生成一个 jar 用于其他项目,它不仅仅是一个网络应用程序或批处理应用程序)。

当我构建并发布我的库 v1.0.0 (mvn deploy -Drevision=1.0.0-release) 时,工件被命名为 "my-library-1.0.0-release.jar",但 jar 中的 pom.xml 元数据仍在 <version>${revision}</version>, 是否有一些用例会导致我的库无法使用?

编辑:同样的问题,如果我的库发布在 SNAPSHOT 存储库中并从那里用作对其他项目的依赖。

将您的库用作依赖项并发布到共享工件存储库(例如 Maven Central)会出现问题,因为您的 pom.xml 与工件版本不匹配。也许某些工件存储库可以工作(例如,具有自定义配置的本地 Artifactory 代理),但它会带来问题。

这个是在Maven CI Friendly Versions you linked to, under "Install/Deploy" chapter which suggests to use flatten-maven-plugin中提到的:

If you like to install or deploy artifacts by using the above setup you have to use the flatten-maven-plugin otherwise you will install/deploy artifacts in your repository which will not be consumable by Maven anymore.

有同样的问题。使用此 Maven 扩展解决(在 extension.xml 文件中):

<extensions>
    <!-- this extension ensures ${revision} gets replaced with the proper value in the output pom files-->
    <extension>
      <groupId>fr.jcgay.maven.extension</groupId>
      <artifactId>unique-revision-maven-filtering</artifactId>
      <version>1.2</version>
    </extension>
</extensions>