简体   繁体   English

如何重命名最新快照版本以包含版本号

[英]How to rename latest snapshot version to include a version number

Question : How can I rename the snapshot version of file to include the version number? 问题 :如何重命名文件的快照版本以包含版本号?

I use <version>LATEST</version> to download the latest version, but how can I use it in the <destFileName> ? 我使用<version>LATEST</version>下载最新版本,但是如何在<destFileName>使用它?

${project.dependencies[0].version} gives me version LATEST . ${project.dependencies[0].version}给我版本LATEST

<artifactItem>
    <groupId>my.group</groupId>
    <artifactId>my.artifact</artifactId>
    <version>LATEST</version>
    <type>exe</type>
    <overWrite>true</overWrite
    <outputDirectory>target/downloads</outputDirectory>
    <destFileName>${project.dependencies[0].version}_My_File_Name.exe</destFileName>
</artifactItem>

I'm using Snapshot version and I want to change the file name to include only the version number. 我正在使用Snapshot版本,我想更改文件名以仅包含版本号。 (otherwise the file name is My_File_Name-version-20160630.212007-10 ). (否则文件名为My_File_Name-version-20160630.212007-10 )。

You need to set useBaseVersion to true in the configuration of the maven-dependency-plugin : 您需要在maven-dependency-plugin的配置中将useBaseVersion设置为true

<configuration>
    <artifactItems>
        <artifactItem>
            <groupId>my.group</groupId>
            <artifactId>my.artifact</artifactId>
            <version>LATEST</version>
            <type>exe</type>
            <overWrite>true</overWrite>
            <outputDirectory>target/downloads</outputDirectory>
        </artifactItem>
    </artifactItems>
    <useBaseVersion>true</useBaseVersion>
</configuration>

This parameter was introduced in version 2.7 of the plugin. 此参数是在插件的2.7版本中引入的。


A bit of explanation , using as example the artifact org.springframework.batch:spring-batch-admin-manager . 一些解释 ,使用工件org.springframework.batch:spring-batch-admin-manager When you are using "LATEST" as the version inside a dependency, Maven will fetch a file from the configured remote repositories called maven-metadata.xml . 当您使用"LATEST"作为依赖项中的版本时,Maven将从配置的名为maven-metadata.xml远程存储库中获取文件。 This file contains the information of all the versions that are deployed for the groupId:artifactId of the dependency. 此文件包含为依赖项的groupId:artifactId部署的所有版本的信息。

This is an example of such a file 这是这种文件的一个例子

<?xml version="1.0" encoding="UTF-8"?>
<metadata modelVersion="1.1.0">
  <groupId>org.springframework.batch</groupId>
  <artifactId>spring-batch-admin-manager</artifactId>
  <versioning>
    <latest>1.3.2.BUILD-SNAPSHOT</latest> <!-- This is the LATEST to use! -->
    <release></release>
    <versions>
      <version>1.3.1.BUILD-SNAPSHOT</version>
      <version>1.3.2.BUILD-SNAPSHOT</version>
    </versions>
    <lastUpdated>20150122163642</lastUpdated>
  </versioning>
</metadata>

Among others, it declares what is the latest version inside the <latest> element. 其中,它声明了<latest>元素中的最新版本。 In this case, the latest version would be 1.3.2.BUILD-SNAPSHOT . 在这种情况下,最新版本将是1.3.2.BUILD-SNAPSHOT

However, this is a SNAPSHOT version, which means that there can actually be multiple snapshot versions for the same 1.3.2.BUILD-SNAPSHOT . 但是,这是一个SNAPSHOT版本,这意味着实际上可以有相同的1.3.2.BUILD-SNAPSHOT多个快照版本。 They are differentiated in Maven 3 by adding a timestamp at the end of the filename. 它们在Maven 3中通过在文件名末尾添加时间戳来区分。 Therefore, you can have multiple 1.3.2-SNAPSHOT with different timestamps. 因此,您可以拥有多个具有不同时间戳的1.3.2-SNAPSHOT

Now that Maven knows that 1.3.2.BUILD-SNAPSHOT is the one to be considered, it looks for another maven-metadata.xml that is specific to 1.3.2.BUILD-SNAPSHOT , which is: 既然Maven知道1.3.2.BUILD-SNAPSHOT是要考虑的那个,它会查找另一个特定于1.3.2.BUILD-SNAPSHOT maven-metadata.xml ,它是:

<?xml version="1.0" encoding="UTF-8"?>
<metadata modelVersion="1.1.0">
  <groupId>org.springframework.batch</groupId>
  <artifactId>spring-batch-admin-manager</artifactId>
  <version>1.3.2.BUILD-SNAPSHOT</version>
  <versioning>
    <snapshot>
      <timestamp>20150115.230511</timestamp>  <!-- This is the timestamp to use! -->
      <buildNumber>1</buildNumber>
    </snapshot>
    <lastUpdated>20150122163642</lastUpdated>
    <snapshotVersions>
      <snapshotVersion>
        <extension>jar</extension>
        <value>1.3.2.BUILD-20150115.230511-1</value>
        <updated>20150115230511</updated>
      </snapshotVersion>
      <!-- omitted for brevity -->
  </versioning>
</metadata>

This file notably declares the latest timestamp of the deployed snapshot version, inside the <timestamp> element. 此文件特别声明了<timestamp>元素内部署的快照版本的最新时间戳。 Maven will use and download this timestamped artifact. Maven将使用并下载这个带时间戳的工件。

So finally: 最后:

  • The base version will correspond to the SNAPSHOT version of the artifact, 1.3.2.BUILD-SNAPSHOT - in this example; 基本版本将对应于工件的SNAPSHOT版本, 1.3.2.BUILD-SNAPSHOT - 在此示例中;
  • The version will correspond to the timestamped version of the latest snapshot, 1.3.2.BUILD-20150115.230511-1 in this example. 该版本将对应于此示例中最新快照的时间戳版本1.3.2.BUILD-20150115.230511-1

As such, useBaseVersion will allow to output a file without the timestamp. 因此, useBaseVersion将允许输出没有时间戳的文件。 When dealing with a release version instead of a snapshot version, both will be the same. 在处理发布版本而不是快照版本时,两者都是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM