我想知道Maven是否有一些內置的插件可用於時間戳工件。我創建了一個程序集文件,並使用maven-assembly插件創建最終分發(jar,docs,scripts等)。我想將此分發文件命名爲domain_year_month_day.zip。如何將時間戳的日期部分附加到正在生成的最終壓縮文件的末尾。謝謝。如何在Maven中輸出工件時間戳?
10
A
回答
8
您可以使用maven-timestamp-plugin來設置屬性(例如timestamp
),並稍後在組件的最終名稱中使用它。顯示性能
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>set-custom-property</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
def timestamp = new Date().format('MM_dd_yy')
project.properties.setProperty('timestamp', timestamp)
</source>
</configuration>
</execution>
<execution><!-- for demonstration purpose -->
<id>show-custom-property</id>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
println project.properties['timestamp']
</source>
</configuration>
</execution>
</executions>
</plugin>
輸出示例:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>create-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<finalName>domain_${timestamp}</finalName>
<descriptors>
<descriptor>src/main/assembly/my-descriptor.xml</descriptor>
</descriptors>
<attach>true</attach>
</configuration>
</execution>
</executions>
</plugin>
作爲替代方案,你可以使用GMaven plugin把一些Groovy代碼在你的POM
$ mvn generate-resources [INFO] Scanning for projects... [INFO] ... [INFO] --- gmaven-plugin:1.3:execute (set-custom-property) @ Q4081274 --- [INFO] [INFO] --- gmaven-plugin:1.3:execute (show-custom-property) @ Q4081274 --- 11_02_10 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ ...
再次,使用此屬性稍後在您的程序集的構建名稱中。
0
如果您使用Hudson/Jenkins,則只需使用變量$ {BUILD_ID}即可獲取要編輯的任何屬性文件的時間戳。
信息到其他環境變量哈德森/詹金斯支持,下面我們來看一看: http://wiki.hudson-ci.org/display/HUDSON/Building+a+software+project
16
你不需要Maven的時間戳的插件與行家的新版本。自2.1版本以來,Maven提供了特殊的屬性maven.build.timestamp。
您設置的格式在像這樣的POM屬性:
<maven.build.timestamp.format>yyyy-MM-dd'T'HH.mm.ss</maven.build.timestamp.format>
然後用$ {} maven.build.timestamp無論你需要一個timestamp屬性。有關詳細信息,請參閱http://maven.apache.org/guides/introduction/introduction-to-the-pom.html。
4
由於${maven.build.timestamp}
似乎Buggy在Maven的,解決方法如下:
創建一個新的變量(我選擇了 「build.timestamp」,在這裏) - 和可選,指定格式:
的pom.xml
<project>
...
<properties>
...
<build.timestamp>${maven.build.timestamp}</build.timestamp>
<maven.build.timestamp.format>yyyyMMdd</maven.build.timestamp.format>
<!-- default is: yyyyMMdd-HHmm -->
</properties>
<build>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>some-assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
...
使用自定義從任何地方變量:
一些-assembly.xml
<?xml version="1.0"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>release-${build.timestamp}</id>
<baseDirectory>/</baseDirectory>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}/${project.artifactId}-${project.version}</directory>
</fileSet>
</fileSets>
</assembly>
相關問題
- 1. 如何在MSBuild中輸出時間戳
- 2. 在Powershell輸出中添加時間戳
- 3. 如何保存tshark輸出文件中的時間戳?
- 4. 如何在MySQL輸出文件上添加時間戳?
- 5. 格式時間戳輸出
- 6. 如何在linux上解釋上次輸出中的時間戳?
- 7. 輸出RFC 3339 Java中的時間戳
- 8. Maven 3和時間戳
- 9. Laravel PHP - 在工匠控制檯輸出上添加時間戳
- 10. MySQL事件.csv輸出文件,名稱中帶有時間戳
- 11. 如何跟蹤在Visual C++ 2010 /輸出時間戳,而調試
- 12. 如何找出Maven工件的最後修改時間?
- 13. 忽略Maven快照中的時間戳
- 14. 插入時間戳到file_put_contents輸出
- 15. Matlab:輸出netcdf時間戳變量
- 16. C++時間戳。更新輸出
- 17. 熊貓輸出時間戳to_excel微秒
- 18. Gson dateformat解析/輸出unix時間戳
- 19. Jboss標準輸出時間戳
- 20. 一個時間戳多格式輸出
- 21. 如何檢查在Maven中部署工件的時間?
- 22. 如何添加時間戳控制檯輸出文件中的RubyMine
- 23. 如何在SQL Server時間戳和時間戳之間
- 24. 時間戳哈希如何工作?
- 25. FFMPEG:在創建時間戳後的一段時間後輸出到新文件?
- 26. PostgreSQL和Hibernate:如何格式化時間戳輸出?
- 27. 如何從當前時間戳獲取shell輸出。 Linux,unix
- 28. 如何將時間戳添加到管道輸出?
- 29. 在Golang中輸出JSON格式化時間戳?
- 30. 在螞蟻中輸出幾個時間戳
這是偉大的。再次感謝您的回答和時間帕斯卡爾。 – John 2010-11-03 11:38:24
然後接受它我的朋友:D – 2010-11-17 14:19:44