// 下階層用テンプレート #topicpath ---- //ここにコンテンツを記述します。 #contents **プラグイン用Eclipseプロジェクトを作る [#z8b8ef14] mvn archetype:create -DgroupId=nu.mine.kino.plugins \ -DartifactId=maven-hoge-plugin \ -DarchetypeArtifactId=maven-archetype-mojo cd maven-hoge-plugin/ mvn eclipse:eclilpse pom.xmlは以下の物が生成されました。 <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>nu.mine.kino.plugins</groupId> <artifactId>maven-hoge-plugin</artifactId> <packaging>maven-plugin</packaging> <version>1.0-SNAPSHOT</version> <name>maven-hoge-plugin Maven Mojo</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project> **プラグインのソースを書く。 [#d446f76c] package nu.mine.kino.plugins; /** * Goal which touches a timestamp file. * * @goal touch <-Annotation * * @phase process-sources */ public class MyMojo extends AbstractMojo { /** * @parameter expression="${project.build.directory}" * @required */ private File outputDirectory; public void execute() throws MojoExecutionException { File f = outputDirectory; if (!f.exists()) { f.mkdirs(); } File touch = new File(f, "touch.txt"); FileWriter w = null; try { w = new FileWriter(touch); w.write("touch.txt"); } catch (IOException e) { throw new MojoExecutionException("Error creating file " + touch, e); } finally { if (w != null) { try { w.close(); } catch (IOException e) { // ignore } } } } } **Mavenコマンドでローカルリポジトリにプラグインをインストールする [#s9e102f1] maven clean install これで先のソースがローカルリポジトリにインストールされました。 **Mavenプロジェクトからインストールしたプラグインを呼び出す。 [#ud172144] さて、ローカルリポジトリにプラグインがインストールされたので、別のmavenプロジェクトからプラグインを呼び出してみようと思います。 pom.xmlには以下のように追加します。 <build> ...... <plugin> <groupId>nu.mine.kino.plugins</groupId> <artifactId>maven-hoge-plugin</artifactId> <version>1.0-SNAPSHOT</version> </plugin> </plugins> </build> 以下のコマンドで先のモジュールを呼び出します。 mvn nu.mine.kino.plugins:maven-hoge-plugin:1.0-SNAPSHOT:touch 引数の意味。 mvn [groupId]:[artifactId]:[version]:[ゴール名] なんだろ、ローカルにインストールされているだけなので、グループIDとかを指定しなくてはいけないのかな。 **アノテーション [#oaaf2b02] **アノテーションやpomから生成されるファイル [#w283cabb] 上のアノテーションの記述やpom.xmlの情報から、プラグインファイルの設定情報plugin.xmlが出力されます。これは実際はjar内の maven-hoge-plugin-1.0-SNAPSHOT.jar#META-INF/maven/plugin.xml に格納されています。内容は以下の通り。 <plugin> <description></description> <groupId>nu.mine.kino.plugins</groupId> <artifactId>maven-hoge-plugin</artifactId> <version>1.0-SNAPSHOT</version> <goalPrefix>hoge</goalPrefix> <isolatedRealm>false</isolatedRealm> <inheritedByDefault>true</inheritedByDefault> <mojos> <mojo> <goal>touch</goal> <description>Goal which touches a timestamp file.</description> <requiresDirectInvocation>false</requiresDirectInvocation> <requiresProject>true</requiresProject> <requiresReports>false</requiresReports> <aggregator>false</aggregator> <requiresOnline>false</requiresOnline> <inheritedByDefault>true</inheritedByDefault> <phase>process-sources</phase> <implementation>nu.mine.kino.plugins.MyMojo</implementation> <language>java</language> <instantiationStrategy>per-lookup</instantiationStrategy> <executionStrategy>once-per-session</executionStrategy> <parameters> <parameter> <name>outputDirectory</name> <type>java.io.File</type> <required>true</required> <editable>true</editable> <description>Location of the file.</description> </parameter> </parameters> <configuration> <outputDirectory implementation="java.io.File">${project.build.directory}</outputDirectory> </configuration> </mojo> </mojos> <dependencies/> </plugin> -[[Mojoって何?>http://blog.goo.ne.jp/ikkoan/e/faee35340ce18875ead57930d40698e0]] **所感 [#yf38b602] 、、、、、、これ、デバッグどうやるんだ?? **組み込みプロパティの一覧 [#r1207831] -[[ParameterExpression>http://wiki.fdiary.net/maven2/?ParameterExpression]] に一覧があります。感謝! **関連リンク [#t80863c1] -[[Your First Plugin>http://maven.apache.org/guides/plugin/guide-java-plugin-development.html]] -[[Maven2のTipsを集めるWiki>http://wiki.fdiary.net/maven2/?CookBook#l5]] -[[[Maven] Maven2 Plugin の作り方 >http://www.in-vitro.jp/blog/index.cgi/Maven/20051024_01.html]] ---- この記事は #vote(おもしろかった[6],そうでもない[1]) - リポジトリ内の maven-metadata-local.xml に<prefix>hoge</prefix>って書いてあるな。。どこから取ってきたんだろう。。。。 -- [[きの]] &new{2007-06-28 (木) 11:54:40}; - http://maven.apache.org/guides/plugin/guide-java-plugin-development.html に he "maven-$name-plugin" and "$name-maven-plugin" artifactId patterns are treated in a special way. て書いてあった。スペシャルに扱われて抜き出されるんだな。。 -- [[きの]] &new{2007-06-28 (木) 11:56:39}; #comment #topicpath SIZE(10){現在のアクセス:&counter;}