下面是如何完成它的一個例子:
- 使用Maven
${maven.build.timestamp}
財產目錄名後綴有時間戳
- 動態目錄名稱重新定義
maven.build.timestamp.format
,如果需要的話,除去:
默認字符,這可能會導致某些操作系統中的問題。例如,對值yyyy-MM-dd_HH-mm-ss
(_
替換:
)
- 配置
maven-clean-plugin
以在執行此構建活動之前清理latest
文件夾。官方文檔已經提供了一個例子how to delete additional files
- 配置
maven-resources-plugin
通過兩個不同的插件執行將您的項目資源複製到latest
和新的構建存儲文件夾。官方的文檔已經在how to copy resources
- 配置
maven-jar-plugin
提供了一個例子來打包項目工件的兩個目錄(最新版本),我會用兩種不同的行家classifier
(時間戳和latest
是完美的候選人)建議。 how to attach additional jars
maven-dependency-plugin
配置maven-dependency-plugin
通過兩個插件執行將項目依賴項複製到兩個文件夾。官方的文檔已經爲了提供how to copy project dependencies
- 將這個整體構建配置一個例子,一個Maven profile不把它作爲默認行爲還可以調用它的需求
這裏是一個全面實施以上,已經放置在一個配置文件:
mvn clean package -P build-store
:
<profile>
<id>build-store</id>
<properties>
<maven.build.timestamp.format>yyyy-MM-dd_HH-mm-ss</maven.build.timestamp.format>
<build.store.directory>c:\build_${maven.build.timestamp}</build.store.directory>
<build.store.directory.latest>c:\latest</build.store.directory.latest>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<filesets>
<fileset>
<directory>${build.store.directory.latest}</directory>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-dependencies-to-build-store</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<outputDirectory>${build.store.directory}</outputDirectory>
<classifier>${maven.build.timestamp}</classifier>
</configuration>
</execution>
<execution>
<id>copy-dependencies-to-latest</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<outputDirectory>${build.store.directory.latest}</outputDirectory>
<classifier>latest</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies-to-build-store</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${build.store.directory}/libs</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
<execution>
<id>copy-dependencies-to-latest</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${build.store.directory.latest}/libs</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy-resources-build-store</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${build.store.directory}/conf</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-resources-latest</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${build.store.directory.latest}/conf</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
經由調用構建
然後將清理latest
文件夾內容,根據構建時間戳創建一個新文件夾,將所需文件移至該文件夾並移至latest
文件夾。
您可以定義編輯build.store.directory
和build.store.directory.latest
屬性的目標文件夾。
根據進一步的要求,可以輕鬆地將其他改進和配置添加到此配置文件。
你爲什麼喜歡做這樣的事情?爲什麼要將jar複製到libs文件夾?你有什麼樣的項目? – khmarbaise