Oct 07, 2008
Maven2 の release プラグインにチャレンジ
Maven2 では maven-release-plugin を使用することで簡単にリリース作業を行うことができる。
maven-release-plugin を使うことで、
- SCM のタグ付け
- pom.xml の <version> 更新
- Maven リポジトリへのプロジェクト登録
- Web サーバへのドキュメント登録
を簡単に行うことができる。
- Maven Release Plugin
- http://maven.apache.org/plugins/maven-release-plugin/
- Technical Project Descriptor
- http://maven.apache.org/ref/current/maven-model/maven.html
- Technical Settings Descriptor
- http://maven.apache.org/ref/current/maven-settings/settings.html
環境
サーバ環境
サーバは "dev.example.com" と表記し、以下の環境であることを前提とする。
- http://dev.example.com/project/maven で WebDAV が利用可能。
- http://dev.example.com/project/maven-snapshot で WebDAV が利用可能。
- http://dev.example.com/project/dist で WebDAV が利用可能。
- http://dev.example.com/project/svn で Subversion にアクセス可能。
クライアント環境
クライアントの環境はこんな感じ。Maven2 と svn コマンドが動作するだけで良いはず。
$ mvn --version Maven version: 2.0.9 Java version: 1.5.0_13 OS name: "mac os x" version: "10.4.11" arch: "i386" Family: "unix" $ svn --version svn, version 1.5.1 (r32289) compiled Aug 6 2008, 13:59:27 Copyright (C) 2000-2008 CollabNet. Subversion is open source software, see http://subversion.tigris.org/ This product includes software developed by CollabNet (http://www.Collab.Net/). The following repository access (RA) modules are available: * ra_neon : Module for accessing a repository via WebDAV protocol using Neon. - handles 'http' scheme - handles 'https' scheme * ra_svn : Module for accessing a repository using the svn network protocol. - with Cyrus SASL authentication - handles 'svn' scheme * ra_local : Module for accessing a repository on local disk. - handles 'file' scheme * ra_serf : Module for accessing a repository via WebDAV protocol using serf. - handles 'http' scheme - handles 'https' scheme $
設定
pom.xml
$PROJECT_HOME/pom.xml に release 用の設定を行う。
- scm の設定
- distributionManagement の設定
- maven-release-plugin の組み込み
- (Web DAV を利用する場合は) wagon-webdav の組み込み
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>jp.in-vitro.dummy</groupId>
<artifactId>dummy</artifactId>
<version>1.0.1-SNAPSHOT</version>
<name>Dummy</name>
<description>Dummy Project</description>
<packaging>jar</packaging>
<scm>
<url>http://dev.example.com/project/svn/Dummy/tags/dummy-1.0.0</url>
<connection>scm:svn:http://dev.example.com/project/svn/Dummy/tags/dummy-1.0.0</connection>
<developerConnection>scm:svn:http://dev.example.com/project/svn/Dummy/tags/dummy-1.0.0</developerConnection>
</scm>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<username>${scm.username}</username>
<password>${scm.password}</password>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav</artifactId>
</extension>
</extensions>
</build>
<distributionManagement>
<repository>
<id>project.repository.release</id>
<name>Project Repository</name>
<url>dav:http://dev.example.com/project/maven</url>
</repository>
<snapshotRepository>
<id>project.repository.snapshots</id>
<uniqueVersion>false</uniqueVersion>
<name>Project Snapshots Repository</name>
<url>dav:http://dev.example.com/project/maven-snapshot</url>
</snapshotRepository>
<site>
<id>project.website</id>
<url>dav:http://dev.example.com/project/dist/${pom.version}</url>
</site>
</distributionManagement>
</project>
settings.xml の設定
$USER_HOME/.m2/settings.xml に SCM や Web DAV のアカウント情報を記述する。
<?xml version="1.0" encoding="UTF-8" ?>
<settings xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>project.repository.release</id>
<username>me</username>
<password>password</password>
</server>
<server>
<id>project.repository.snapshots</id>
<username>me</username>
<password>password</password>
</server>
<server>
<id>project.website</id>
<username>me</username>
<password>password</password>
</server>
</servers>
<profiles>
<profile>
<id>project</id>
<properties>
<scm.username>me</scm.username>
<scm.password>password</scm.password>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>project</activeProfile>
</activeProfiles>
</settings>
maven-release-plugin の実行
release:prepare
まずはリリースの準備として release:prepare を実行する。 release:prepare では、"リリースするバージョン"、"SCM に付けるタグ", "次のバージョン" を質問されるので、それぞれ入力する。
$ mvn release:prepare [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'release'. WAGON_VERSION: 1.0-beta-2 [INFO] ------------------------------------------------------------------------ [INFO] Building Dummy [INFO] task-segment: [release:prepare] (aggregator-style) [INFO] ------------------------------------------------------------------------ [INFO] [release:prepare] [INFO] Verifying that there are no local modifications... [INFO] Executing: svn --username me --password ***** --non-interactive status [INFO] Working directory: /Users/me/Documents/Private/000-workspace/Dummy [INFO] Checking dependencies and plugins for snapshots ... What is the release version for "Dummy"? (jp.in-vitro.dummy:dummy) 1.0.1: : What is SCM release tag or label for "Dummy"? (jp.in-vitro.dummy:dummy) dummy-1.0.1: : What is the new development version for "Dummy"? (jp.in-vitro.dummy:dummy) 1.0.2-SNAPSHOT: : [INFO] Transforming 'Dummy'... [INFO] Not generating release POMs [INFO] Executing goals 'clean verify'... (略) [INFO] Release preparation complete. [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 17 seconds [INFO] Finished at: Fri Oct 03 18:20:48 JST 2008 [INFO] Final Memory: 6M/12M [INFO] ------------------------------------------------------------------------ $
release:perform
release:prepare が正常終了したら、release:perform を実行する。 release:perform を実行すると、SCM へのタグ付けやリポジトリへの登録、バージョンの更新などのリリース処理が行われる。
$ mvn release:perform
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'release'.
WAGON_VERSION: 1.0-beta-2
[INFO] ------------------------------------------------------------------------
[INFO] Building Dummy
[INFO] task-segment: [release:perform] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [release:perform]
[INFO] Checking out the project to perform the release ...
[INFO] Executing: svn --username me --password ***** --non-interactive checkout http://dev.example.com/project/svn/Dummy/tags/dummy-1.0.1 checkout
[INFO] Working directory: /Users/me/Documents/Private/000-workspace/Dummy/target
[INFO] Executing goals 'deploy site-deploy'...
[INFO] Executing: mvn deploy site-deploy --no-plugin-updates -P project -DperformRelease=true -f pom.xml
[INFO] Scanning for projects...
WAGON_VERSION: 1.0-beta-2
[INFO] ------------------------------------------------------------------------
[INFO] Building Dummy
[INFO] task-segment: [deploy, site-deploy]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
(略)
Transfer finished. 1687 bytes copied in 0.025 seconds
http://dev.example.com/project/dist/1.0.1 - Session: Disconnecting
http://dev.example.com/project/dist/1.0.1 - Session: Disconnected
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 2 seconds
[INFO] Finished at: Fri Oct 03 18:22:01 JST 2008
[INFO] Final Memory: 39M/63M
[INFO] ------------------------------------------------------------------------
[INFO] Cleaning up after release...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 8 seconds
[INFO] Finished at: Fri Oct 03 18:22:02 JST 2008
[INFO] Final Memory: 6M/12M
[INFO] ------------------------------------------------------------------------
$
TrackBack ping me at
http://www.in-vitro.jp/blog/index.cgi/Maven/20081007_01.trackback
writeback message: Ready to post a comment.
