月曜日 8 21, 2006
月曜日 8 21, 2006
プロジェクト管理ツールMavenがバージョン2.0になってからは、バージョン1.0に較べてお世辞にも使いやすくなったとは言えません。例えば、プロジェクト・テンプレートを作成するのにMaven 1.0では、以下のように簡単なコマンドラインで済みました。
$ maven genapp
__ __
| \/ |__ _Apache__ ___
| |\/| / _` \ V / -_) ' \ ~ intelligent projects ~
|_| |_\__,_|\_/\___|_||_| v. 1.0
Enter a project template to use: [default]
Please specify an id for your application: [app]
Please specify a name for your application: [Example Application]
Please specify the package for your application: [example.app]
:
Maven 1.0ではパラメータで指定されなかったメタ情報については、インタラクティブに問い合わせてくれるため、実行するコマンドラインをシンプルにすることができました。
Maven 2.0では1.0のときのようなインタラクティブ・モードがないため、以下のように必須のパラメータについては全てコマンドラインに指定してあげなければなりません。
$ mvn archetype:create -DartifactId=app -DgroupId=example.app
[INFO] Scanning for projects...
:
Mavenのサイトの"Mini Guide: Guide to Maven 2.x auto completion using BASH"では、bash completionのためのスクリプトを紹介していますが、これはサンプル・スクリプトというレベルのもので一部のプラグイン名しか補間してくれませんし、パラメータについては全く補間してくれません。そこで、実用的なレベルで使用可能なスクリプトを作ってみましたので、ご紹介します。
設定方法は以下の通りです:
[ -f /etc/bash_completion ] && . /etc/bash_completion初期化用ファイルbash_completionのパスは、1.で導入したパッケージによって異なりますので注意して下さい。bashを再起動して、javaコマンドでのクラス名やcvsコマンドで引数の補間機能が働いていることを確認して下さい。
$ unzip m2.zip $ sudo cp m2 /etc/bash_completion.d/このコピー先のディレクトリも1.で導入したパッケージによって異なりますので注意して下さい。
デフォルトでは、Mavenのサイトにリストされている全てのプラグインのゴールと一般的によく使用されるフェーズ名の候補を列挙します。実際の利用シーンでは、プラグインのゴールを直接指定することはあまりなく、compile、test、packageなどのフェーズ名を指定することが多いかと思いますが、現状は全てのゴールとフェーズがリストされます。
$ mvn <TAB>
ant:ant package
antlr:generate plexus:app
archetype:create plexus:bundle-application
assembly:assembly plexus:bundle-runtime
assembly:directory plexus:descriptor
assembly:unpack plexus:runtime
castor:generate plexus:service
checkstyle:checkstyle plugin:addPluginArtifactMetadata
clean plugin:descriptor
clover:check plugin:report
clover:instrument plugin:updateRegistry
clover:log plugin:xdoc
clover:report project-info-reports:cim
compile project-info-reports:dependencies
compiler:compile project-info-reports:issue-tracking
compiler:testCompile project-info-reports:license
deploy project-info-reports:mailing-list
deploy:deploy project-info-reports:project-team
eclipse:add-maven-repo project-info-reports:scm
eclipse:clean projecthelp:active-profiles
eclipse:eclipse projecthelp:describe
ejb:ejb projecthelp:effective-pom
help:active-profiles projecthelp:effective-settings
help:describe rar:rar
help:effective-pom release:perform
help:effective-settings release:prepare
idea:idea resources:resources
install resources:testResources
install:install site
install:install-fire source:jar
jar:jar surefire:test
jar:test-jar taglist:taglist
javacc:javacc test
javacc:jjtree verifier:verify
javadoc:jar war:exploded
javadoc:javadoc war:inplace
jdepend war:war
また、ハイフン(-)までタイプして、タブを入力すると指定可能なオプションを列挙します。
$ mvn -<TAB>
--activate-profiles --reactor -e
--batch-mode --settings -f
--check-plugin-update --strict-checksums -fae
--debug --update-plugins -ff
--define --update-snapshots -fn
--fail-at-end --version -h
--fail-fast -B -npr
--fail-never -C -npu
--file -D -o
--help -N -r
--lax-checksums -P -s
--no-plugin-registry -U -up
--no-plugin-updates -X -v
--non-recursive -c
--offline -cpu
引数にプラグインのゴールが指定されている場合は、そのゴールで指定可能なパラメータを列挙します。
$ mvn archetype:create <TAB>-D<TAB> -DarchetypeArtifactId= -DarchetypeArtifactId=maven-archetype-archetype -DarchetypeArtifactId=maven-archetype-j2ee-simple -DarchetypeArtifactId=maven-archetype-mojo -DarchetypeArtifactId=maven-archetype-portlet -DarchetypeArtifactId=maven-archetype-profiles -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeArtifactId=maven-archetype-simple -DarchetypeArtifactId=maven-archetype-site -DarchetypeArtifactId=maven-archetype-site-simple -DarchetypeArtifactId=maven-archetype-webapp -DarchetypeGroupId= -DarchetypeVersion= -DartifactId= -DgroupId= -DlocalRepository= -DpackageName= -DpomRemoteRepositories= -Dproject= -DremoteRepositories= -Dversion=
パラメータの補間時には、help:describeの出力結果を~/.bash/ディレクトリにキャッシュして補間候補に使用するようにしています。初めてタイプしたゴールのパラメータ補間時には内部でmvn help:describeを実行するため少し時間が掛かりますが、2回目以降はすぐに反応してくれます。
Maven 2.0.4の環境でほぼ問題なく動作することを確認していますが、何か問題などありましたらお知らせ下さい。改善提案なども大歓迎です。