質問

Mavenには、タイムスタンプアーティファクトに使用できる組み込みプラグインがあるかどうかを確認しようとしています。アセンブリファイルを作成し、Maven-Assemblyプラグインを使用して最終的な分布(JAR、ドキュメント、スクリプトなど)を作成しています。この配布ファイルをdomain_year_month_day.zipに名前を付けたいと思います。作成されている最終的なzipファイルの最後にタイムスタンプの日部分を追加するにはどうすればよいですか。ありがとう。

役に立ちましたか?

解決

使用できます Maven-Timestamp-Plugin プロパティを設定する(例: timestamp)そして、後で組み立ての最終名で使用します。

<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>

別の方法として、あなたはあなたのpomにいくつかのグルーヴィーなコードをあなたのPOMに置くことができます Gmavenプラグイン:

<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>

プロパティを示すサンプル出力:

$ 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] ------------------------------------------------------------------------
...

繰り返しますが、このプロパティを後で組み立てのビルド名で使用してください。

他のヒント

Mavenの新しいバージョンを備えたMaven-Timestamp-Pluginは必要ありません。 2.1'ish以来、Mavenは特別なプロパティmaven.build.timestampを提供しています。

POMプロパティの形式を次のようなもので設定します。

<maven.build.timestamp.format>yyyy-MM-dd'T'HH.mm.ss</maven.build.timestamp.format>

次に、タイムスタンププロパティが必要な場所で$ {maven.build.timestamp}を使用します。見る http://maven.apache.org/guides/introduction/introduction-to-pom.html 詳細については。

として ${maven.build.timestamp} 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>

...

どこからでもカスタム変数を使用します。

some-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>

Hudson/Jenkinsを使用する場合は、編集する任意のプロパティファイルにタイムスタンプのようなものを取得するために、変数$ {build_id}を使用することができます。

他の環境変数への情報Hudson/Jenkinsがサポートしています。こちらをご覧ください。http://wiki.hudson-ci.org/display/hudson/building+a+software+project

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top