问题:如何重命名文件的快照版本以包含版本号?
我使用<version>LATEST</version>
下载最新版本,但如何在 <destFileName>
中使用它?
${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>
我正在使用快照版本,我想更改文件名以仅包含版本号。 (否则文件名为 My_File_Name-version-20160630.212007-10
)。
最佳答案
您需要设置 useBaseVersion
至true
在maven-dependency-plugin
的配置中:
<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>
该参数是在插件 2.7 版本中引入的。
<小时/> A bit of explanation ,以 Artifact org.springframework.batch:spring-batch-admin-manager
为例。当您使用"LATEST"
时作为依赖项内的版本,Maven 将从配置的远程存储库中获取名为 maven-metadata.xml
的文件。 。该文件包含为groupId:artifactId
部署的所有版本的信息。的依赖关系。
这是此类文件的示例
<?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>
其中,它声明 <latest>
内的最新版本是什么。元素。在这种情况下,最新版本将为 1.3.2.BUILD-SNAPSHOT
。
但是,这是一个 SNAPSHOT 版本,这意味着同一个 1.3.2.BUILD-SNAPSHOT
实际上可以有多个快照版本。 。它们在 Maven 3 by adding a timestamp 中有所区别在文件名的末尾。因此,您可以有多个 1.3.2-SNAPSHOT
具有不同的时间戳。
现在 Maven 知道 1.3.2.BUILD-SNAPSHOT
是要考虑的一个,它会寻找另一个 maven-metadata.xml
特定于1.3.2.BUILD-SNAPSHOT
,即:
<?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>
此文件特别声明了已部署快照版本的最新时间戳,位于<timestamp>
内。元素。 Maven 将使用并下载这个带有时间戳的 Artifact 。
最后:
- 基础版本将对应于 Artifact 的快照版本
1.3.2.BUILD-SNAPSHOT
- 在此示例中; - 该版本将对应于最新快照的时间戳版本
1.3.2.BUILD-20150115.230511-1
在这个例子中。
因此,useBaseVersion
将允许输出没有时间戳的文件。当处理发布版本而不是快照版本时,两者将是相同的。
关于maven - 如何重命名最新快照版本以包含版本号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37947687/