aqubi+shin1

Recent site activity

maven2

オプション

  1. pluginのupdateを強制的に確認しつつ実行
    1. 「-U」オプション「-cpu」「--check-plugin-updates」の間違い。
  2. offlineモード
    1. 「-o」
  3. SNAPHOTのupdateを強制的に確認しつつ実行
    1. 「-U」「--update-snapshots」
  4. ヒープサイズの指定
    1. 環境変数「MAVEN_OPTS」に「-Xmx128m」とか。
  5. サブプロジェクトを再帰的に処理しない。
    1. 「-N」「--non-recursive」

各種プラグインの使い方(ヘルプ)を表示する

apache標準のhelpプラグインを使うことで、各プラグインのヘルプ(ゴールの一覧や、使用できるパラメータの説明など)を表示させることができる。
  • mvn help:describe -Dplugin=${プラグインのgroupId}:${プラグインのartifactId}:${プラグインのバージョン}
    • プラグインのバージョンは省略可能
    • apache標準のプラグイン(groupId=org.apache.maven.plugins)のものは、groupIdは省略でき、artifactIdも省略形が使用できる。
    • "full"パラメータをtrueに設定すると、詳細なヘルプが表示される。
      • -Dfull=true
    • "output"パラメータでファイル名を設定するとファイルに出力できる。
      • -Doutput=target/help.txt
たとえば、以下のようなカンジ。
  • helpプラグイン自体のヘルプを詳細に表示する。groupIdは省略して、artifactIdは省略形を使用した場合。
    • mvn help:describe -Dplugin=help -Dfull=true
  • codehausのwagonプラグインのヘルプを詳細に表示する。groupIdもartifactIdも指定した場合。
    • mvn help:describe -Dplugin=org.codehaus.mojo:wagon-maven-plugin -Dfull=true

artifactの検索

Snapshotについて

version番号に"+-SNAPSHOT"にマッチする文字列を指定する事で、通常のartifactとは違う配布方式をとる事ができる。

deployする側

  1. //distributionManagement/snapshotRepositoryで設定したServerに配布される。
  2. //distributionManagement/snapshotRepository/uniqueVersionに"true"を設定すると、配 布する時のjar名が"artifactId-+-SNAPSHOT.jar"ではなく、"artifactId-+日付.時刻.jar"となる。
    <distributionManagement>
    <snapshotRepository>
    <id>ftp-hoge</id>
    <url>ftp://hoge/fuga</url>
    </snapshotRepository>
    </distributionMangement>

使用する側

  1. repositories/repository/snapshots/updatePolicy要素に"always"を設定する事で「常に最新かどうかのチェックを行う」という動作をしてくれる。
    <repositories>
    <repository>
    <id>shin1</id>
    <url>http://hoge.fuga.com/shin1</url>
    <snapshots>
    <updatePolicy>always</updatePolicy>
    </snapshots>
    </repository>
    </repositories>

Repository

良く使うリポジトリ。
  • Maven Snapshots
    <repository>
      <id>Maven Snapshots</id>
      <url>http://snapshots.maven.codehaus.org/maven2/</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>false</enabled>
      </releases>
    </repository>
  • Codehaus Snapshots
    <pluginRepository>
      <id>Codehaus Snapshots</id>
      <url>http://snapshots.repository.codehaus.org/</url>
    </pluginRepository>
  • eclipse関連
    <repository>
      <id>Eclipse</id>
      <url>http://repo2.maven.org/eclipse/</url>
    </repository>
  • java.net
    <repository>
      <id>maven2-repository.dev.java.net</id>
      <name>Java.net Repository for Maven</name>
      <url>http://download.java.net/maven/2/</url>
      <layout>default</layout>
    </repository>
    <repository>
      <id>java.net</id>
      <url>http://download.java.net/maven/1</url>
      <layout>legacy</layout>
    </repository>
  • coderepos
    <repository>
      <id>coderepos.org</id>
      <name>CodeRepos svn repository</name>
      <url>http://svn.coderepos.org/share/lang/java/misc/maven2repo</url>
    </repository>
  • seasar
    <repositories>
      <repository>
        <id>maven.seasar.org</id>
        <name>The Seasar Foundation Maven2 Repository</name>
        <url>http://maven.seasar.org/maven2</url>
      </repository>
    </repositories>
  • ローカルフォルダ
    <repository>
      <id>local</id>
      <url>file:${basedir}/lib</url>
    </repository>
  • wicket stuff
    <repository>
      <id>wicket-stuff.org</id>
      <url>http://wicketstuff.org/maven/repository/</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>

Profile

色々な環境やフェーズ(Maven的なフェーズというよりプロジェクトの工程的なフェーズだったりするかもしれない)ごとに各種プラグイン等の設定を切り替える事ができる。めっちゃくちゃ強力。
  • 環境やフェーズに応じてリソースファイルを切り替えたい(build/resources/resource/directory)。
  • 環境やフェーズに応じてデプロイ先を切り替えたい(distributionManagement)。
  • 環境やフェーズに応じてpropertyの値を変更したい(properties)。
  • 環境やフェーズに応じてpluginの設定を変更したい(build/plugins/plugin)
    • surefire-pluginの設定でtest対象を変更したいとか。
    • cargo-pluginの設定でintegration-testをするapserverの設定を変えたいとか。
とにかく強力にカスタマイズできる。手動で切り替えるには以下のように Pオプションで指定する。
  • $ mvn -P {profile-id} ...
さらに、osや環境変数の値を判断して自動的に切り替えたりする事もできる。

特にCIサーバに乗せる事を考えた場合にめっちゃ便利。相当広い範囲で設定できるので、詳細は本家のリファレンスである以下も参照する事。

例えば「開発中」「integration-test用」「製品としてのパッケージング用」のみっつの設定を用意するなら。
  • <profiles>
      <profile>
        <id>development</id>
        <activation>
          <activeByDefault>true</activeByDefault>
        </activation>
        <build>
          <resources>
            <resource>
              <directory>src/main/resources</directory>
            </resource>
          </resources>
          <plugins>
            <plugin>
              <artifactId>maven-surefire-plugin</artifactId>
              <configuration>
                <excludes>
                  <exclude>**/*ItTest.java</exclude>
                </excludes>
              </configuration>
            </plugin>
          </plugins>
        </build>
      </profile>
      <profile>
        <id>integration-test</id>
        <build>
          <resources>
            <resource>
              <directory>src/it/resources</directory>
            </resource>
          </resources>
          <plugins>
            <plugin>
              <artifactId>maven-surefire-plugin</artifactId>
              <configuration>
                <includes>
                  <include>**/*ItTest.java</include>
                </includes>
              </configuration>
            </plugin>
          </plugins>
        </build>
      </profile>
      <profile>
        <id>production</id>
        <build>
          <resources>
            <resource>
              <directory>src/production/resources</directory>
            </resource>
          </resources>
        </build>
        <properties>
          <maven.test.skip>true</maven.test.skip>
        </properties>
      </profile>
    </profiles>
以下のような動作をする。
  • $ mvn package
    • src/main/resourceかsrc/test/resources配下のリソースが適用される。
    • testが実行されるが、*ItTestというtestは実行されない。
  • $ mvn -P integration-test package
    • src/it/resources配下のリソースが適用される。
    • testが実行されるが、*ItTestというtestが実行される。
  • $ mvn -P production
    • src/production/resources配下のリソースが適用される。
    • testが実行されない。

各plugin

test

  1. testをskipする。「-Dmaven.test.skip=true」
  2. test対象を指定する。「-Dtest=hoge」ワイルドカードも使える。
  3. testの失敗を無視して続行する。「-Dmaven.test.failure.ignore=true」

projecthelp,help

  1. pom.xml内で省略されている、default設定を出力
    1. mvn projecthelp:effective-pom
  2. 読み込んだsetting.xmlを出力
    1. mvn help:effective-settings -Doutput=effective-settings.xml

archetype

  1. artifactの作成
    1. mvn archetype:create -DgroupId=${groupId} -DartifactId=${artifactId}
    2. [TODO]最近、どのマシンだかで使った場合に対話形式でGroupIdとかを設定できたんだが…?
      mvn archetype:generate
      だとarchetypeArtifctId他いくつかの属性値を対話形式で設定できる。
    3. 「archetypeArtifactId」属性でarchetypeの種類を指定できる。maven-archetype-webappなら webappとか。maven標準でないarchetypeArtifactを使う場合は「archeTypeGroupId」の指定も必要。

source

  1. 生成物を全部削除して、ソースとjarをinstall
    1. mvn clean source:jar install
  2. test-jarゴールを指定すると、テストソースがパッケージングされる。

compiler

  1. java5の使用とソースのエンコードをutf-8に設定する。
    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.5</source>
            <target>1.5</target>
            <encoding>UTF-8</encoding>
        </configuration>
    </plugin>

clean

  1. cleanする時の削除対象のフォルダに、target以外も対象としたい時とか。
    <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <configuration>
            <filesets>
                <fileset>
                    <directory>${basedir}/lib</directory>
                </fileset>
            </filesets>
            <failOnError>false</failOnError>
        </configuration>
    </plugin>

package

  • test-jarゴールを指定すると、テスト用のclassがパッケージングされる。
    ただし、testフェーズをskipする場合はtest-jarが作成されない。testを実行せずにtest-jarを作成したい場合は、以下のようにして「存在しないテストケースをtestパラメタで指定する」「test対象が存在しない場合にエラーを発生させない」という状態で実行する。
    • -Dtest=DETARAMEPATTERN -DfailIfNoTests=false

dependency

  1. 依存jarをlibとlib/sourcesに出力する。eclipseのpdeと併用する時に便利。
    <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <id>jar</id>
                <phase>process-resources</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                    <outputDirectory>${basedir}/lib</outputDirectory>
                    <excludeGroupIds>org.eclipse,org.eclipse.ui</excludeGroupIds>
                    <includeScope>compile</includeScope>
                    <excludeScope>test</excludeScope>
                    <overWriteReleases>false</overWriteReleases>
                    <overWriteSnapshots>true</overWriteSnapshots>
                    <overWriteIfNewer>true</overWriteIfNewer>
                </configuration>
            </execution>
            <execution>
                <id>source-jar</id>
                <phase>process-resources</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                    <outputDirectory>${basedir}/lib/sources</outputDirectory>
                    <excludeGroupIds></excludeGroupIds>
                    <includeScope>compile</includeScope>
                    <excludeScope>test</excludeScope>
                    <overWriteReleases>false</overWriteReleases>
                    <overWriteSnapshots>true</overWriteSnapshots>
                    <overWriteIfNewer>true</overWriteIfNewer>
                    <classifier>sources</classifier>
                    <failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
                </configuration>
            </execution>
        </executions>
    </plugin>

unpack

依存しているjarを解凍できる。以下のようなときには使える。
  1. 依存先artifactのjarも含めてcoberturaでカバレッジを取得したいとき。coberturaはclassファイルをカバレッジ対象とするので、${project.build.directory}へ依存先jarを解凍しておくとそれらのclassもカバレッジ対象となる。
  2. test-jarに含まれているリソース類を共有したいとか。
...他にもいろいろ使い道はあるが、どれもartifactの構成が悪かったりする事が原因だったりするかも。そういった時の一時しのぎ的に使うときには便利。
  • <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <executions>
        <execution>
          <id>unpack</id>
          <-- 使用用途によって実行フェーズをシビアに選択する必要がある事が多い -->
          <phase>process-resources</phase>
          <goals>
            <goal>unpack</goal>
          </goals>
          <configuration>
            <artifactItems>
              <artifactItem>
                <groupId>com.shin1ogawa</groupId>
                <artifactId>com.shin1ogawa.hoge</artifactId>
                <version>1.0.0-SNAPSHOT</version>
                <type>jar</type>
                <overWrite>false</overWrite>
                <outputDirectory>${project.build.directory}</outputDirectory>
              </artifactItem>
            </artifactItems>
            <excludes>*.txt, *.properties</excludes>
          </configuration>
        </execution>
      </executions>
    </plugin>

assembly

http://maven.apache.org/plugins/maven-assembly-plugin/
  1. ソースをパッケージ(pom.xmlも含む)
    1. mvn assembly:assembly -DdescriptorId=src
  2. 依存jarも含めてパッケージ
    1. mvn assembly:assembly -DdescriptorId=jar-with-dependencies

eclipse 

http://maven.apache.org/plugins/maven-eclipse-plugin/
  1. EclipseのProjectを生成する。 http://maven.apache.org/plugins/maven-eclipse-plugin/eclipse-mojo.html
    1. mvn eclipse:eclipse
      1. -DdownloadSources=true ならソースのjarの参照も付加。
      2. -DdownloadJavadocs=true ならソースのjavadocの参照も付加。
  2. EclipseのworkspaceにM2_REPOを設定する。
    1. maven eclipse:add-maven-repo -Declipse.workspace=XXXXX
Eclipseのプロジェクトの設定をそこそこ制御できる。
  • builderやnatureをpom.xmlでconfiguration/buildcommands, configuration/projectnatures, configuration/classpathContainers要素で指定する事ができる。
  • .settings配下に配置する、リソースのエンコードの設定やフォーマッタの設定、jdtへの設定もconfiguration/additionlConfig/file要素で指定する事ができる。が、これらはでかくなりがちなので別ファイルにしておいたほうがいいのかも。
  • wtpのバージョンもconfiguration/wtpversion要素で指定できる。
例えばcheckstyle plug-inとfindbus-pluginは必ず使うはずなので、以下のように指定しておく。
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-eclipse-plugin</artifactId>
  <configuration>
    <buildcommands>
      <java.lang.String>org.eclipse.jdt.core.javabuilder</java.lang.String>
      <java.lang.String>org.eclipse.wst.common.project.facet.core.builder</java.lang.String>
      <java.lang.String>org.eclipse.wst.validation.validationbuilder</java.lang.String>
    </buildcommands>
    <classpathContainers>
      <buildcommand>org.eclipse.jdt.launching.JRE_CONTAINER</buildcommand>
    </classpathContainers>
    <projectnatures>
      <projectnature>org.eclipse.wst.common.project.facet.core.nature</projectnature>
      <projectnature>org.eclipse.jdt.core.javanature</projectnature>
      <projectnature>org.eclipse.wst.common.modulecore.ModuleCoreNature</projectnature>
      <projectnature>org.eclipse.jem.workbench.JavaEMFNature</projectnature>
    </projectnatures>
    <additionalConfig>
      <file>
        <name>.settings/org.eclipse.core.resources.prefs</name>
        <content>
        <![CDATA[
eclipse.preferences.version=1
encoding/<project>=UTF-8
        ]]>
        </content>
      </file>
      <file>
        <name>.settings/org.eclipse.core.resources.prefs</name>
        <content>
        <![CDATA[
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
...
        ]]>
        </content>
      </file>
    </additionalConfig>
    <wtpversion>2.0</wtpversion>
  </configuration>
</plugin>

install

http://maven.apache.org/plugins/maven-install-plugin/
  1. リポジトリに無いjarを手動で登録する(jtaの例)。
    1. mvn install:install-file -DgroupId=javax.transaction -DartifactId=jta -Dversion=1.0.1B -Dpackaging=jar -Dfile=jta-1.0.1b.jar

jar

証明書を用意しておき、signゴールでsignもできる。
<plugin>
  <artifactId>maven-jar-plugin</artifactId>
  <version>2.2</version>
  <configuration>
    <archive>
      <index>true</index>
      <compress>true</compress>
    </archive>
    <alias>jws</alias>
    <keystore>${basedir}/keystore</keystore>
    <storepass>storepassword</storepass>
    <keypass>keypassword</keypass>
  </configuration>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>jar</goal>
        <goal>sign</goal>
      </goals>
      <configuration>
        <jarPath>${project.build.directory}/${project.build.finalName}.${project.packaging}</jarPath>
        <signedjar>${project.build.directory}/signed/${project.build.finalName}.${project.packaging}</signedjar>
      </configuration>
    </execution>
  </executions>
</plugin>

cargo

WebAppコンテナを起動したり、warをデプロイすることができるプラグイン。
  • pre-integration-testフェーズ
    • tomcatをダウンロードし、tomcatを起動(startゴール)
    • warをデプロイ(deployer-deployゴール)
  • post-integration-testフェーズ
    • tomcatを停止(stopゴール)
上記を行う例が以下。src/main/webapp直下にindex.htmlなどを配置しておくか、pingURLをアクセス可能なURLに変更しておくかしないと、デプロイ完了の確認に失敗していまうので注意。
<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.cargo</groupId>
      <artifactId>cargo-maven2-plugin</artifactId>
      <version>1.0-SNAPSHOT</version>
      <configuration>
        <container>
          <containerId>tomcat5x</containerId>
          <zipUrlInstaller>
            <url>http://archive.apache.org/dist/tomcat/tomcat-5/v5.5.27/bin/apache-tomcat-5.5.27.zip</url>
          </zipUrlInstaller>
          <output>${project.build.directory}/tomcat5x.log</output>
          <log>${project.build.directory}/cargo.log</log>
          <timeout>60000</timeout>
        </container>
        <configuration>
          <home>${project.build.directory}/tomcat55</home>
          <properties>
            <cargo.servlet.port>8080</cargo.servlet.port>
            <cargo.logging>high</cargo.logging>
          </properties>
        </configuration>
        <deployer>
          <deployables>
            <deployable>
              <groupId>com.shin1ogawa</groupId>
              <artifactId>webappSample</artifactId>
              <type>war</type>
              <properties>
                <context>webappSample</context>
              </properties>
              <pingURL>http://localhost:8080/webappSample/</pingURL>
            </deployable>
          </deployables>
        </deployer>
      </configuration>
      <executions>
        <execution>
          <id>start-container</id>
          <phase>pre-integration-test</phase>
          <goals>
            <goal>start</goal>
            <goal>deployer-deploy</goal>
          </goals>
          <configuration>
            <wait>false</wait>
          </configuration>
        </execution>
        <execution>
          <id>stop-container</id>
          <phase>post-integrastion-test</phase>
          <goals>
            <goal>stop</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
<pluginRepositories>
  <pluginRepository>
    <id>cargo m2 release repository</id>
    <url>http://cargo.codehaus.org/dist2</url>
    <releases>
      <enabled>true</enabled>
    </releases>
  </pluginRepository>
</pluginRepositories>
さらに詳しい情報が必要なら、以下の本家のリファレンスを参照すること。

jetty

jetty本体を含んだプラグイン。wicket-archetype-quickstartを実行したときなんかはこのプラグインが最初から設定されている。
<build>
  <plugins>
    <plugin>
      <groupId>org.mortbay.jetty</groupId>
      <artifactId>maven-jetty-plugin</artifactId>
      <version>6.1.10</version>
      <configuration>
        <contextPath>webappSample</contextPath>
        <scanIntervalSeconds>10</scanIntervalSeconds>
        <stopKey>foo</stopKey>
        <stopPort>9999</stopPort>
        <connectors>
          <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
            <port>8080</port>
            <maxIdleTime>60000</maxIdleTime>
          </connector>
        </connectors>
      </configuration>
      <executions>
        <execution>
          <id>start-container</id>
          <phase>pre-integration-test</phase>
          <goals>
            <goal>run</goal>
          </goals>
          <configuration>
            <scanIntervalSeconds>0</scanIntervalSeconds>
            <daemon>true</daemon>
          </configuration>
        </execution>
        <execution>
          <id>stop-container</id>
          <phase>post-integration-test</phase>
          <goals>
            <goal>stop</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
さらに詳しい情報が必要なら、以下の本家のリファレンスを参照すること。
http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin

その他plugin

ソースフォルダを複数指定したい時。

build-helperプラグインを使用する。
  1. /build配下に以下の様な記述を行う。
    <sourceDirectory>src/src1</sourceDirectory>
    ...
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>build-helper-maven-plugin</artifactId>
      <executions>
        <execution>
          <id>add-source</id>
          <phase>generate-sources</phase>
          <goals>
            <goal>add-source</goal>
          </goals>
          <configuration>
            <sources>
              <source>src/src2</source>
              <source>src/src3</source>
            </sources>
          </configuration>
        </execution>
      </executions>
    </plugin>
  2. testソースフォルダを追加したい場合は、上記の「add-source」が「add-test-source」となる。

特定のファイルを別マシンへscpなどしたい時

wagonプラグインを使用する。
  1. deployプラグインで別マシンへinstallする時と同じように、settings.xmlのservers要素の配下に転送先のserverの設定が必要。
    <server>
      <id>remotehost</id>
      <username>shin1ogawa</username>
      <password>password</password>
    </server>
  2. pom.xmlはbuild/plugins配下に以下のように設定。この例ではpackageフェーズが実行されたタイミングで起動している。
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>wagon-maven-plugin</artifactId>
      <version>1.0-beta-1</version>
      <executions>
        <execution>
          <id>upload-jar</id>
          <phase>package</phase>
          <goals>
            <goal>upload</goal>
          </goals>
          <configuration>
            <serverId>remotehost</serverId>
            <url>scp://192.168.1.109/</url>
            <fromDir>target</fromDir>
            <includes>**/*.jar</includes>
            <excludes>*-sources.jar</excludes>
            <toDir>/home/shin1ogawa/tmp</toDir>
          </configuration>
        </execution>
      </executions>
    </plugin>

Reportについて

テンプレート

  • surefire-report
  • cobertura
  • findbugs
  • jxr
  • pmd
  • jdepend
これらを使用する。
<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>com.shin1o</groupId>
  <artifactId>com.shin1o.reportsample</artifactId>
  <packaging>jar</packaging>
  <version>1.0.0-SNAPSHOT</version>
  <name>com.shin1o.reportsample</name>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.4</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <!-- http://maven.apache.org/plugins/maven-compiler-plugin/ -->
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <encoding>UTF-8</encoding>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
      <!-- surefire: http://maven.apache.org/plugins/maven-surefire-plugin/ -->
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <systemProperties>
            <property>
              <name>net.sourceforge.cobertura.datafile</name>
              <value>${basedir}/target/cobertura/cobertura.ser</value>
            </property>
          </systemProperties>
          <!-- スラッシュ区切り、javaを指定。
          <excludes>
            <exclude>com/shin1o/exclude/**/*.java</exclude>
          </excludes>
          -->
        </configuration>
      </plugin>
      <!-- surefire-report: http://maven.apache.org/plugins/maven-surefire-report-plugin/ -->
      <!-- testフェーズでもsurefire-reportが必要なら有効にする。
      <plugin>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <executions>
          <execution>
            <phase>test</phase>
            <goals>
              <goal>report-only</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      -->
    </plugins>
  </build>

  <reporting>
    <plugins>
      <!-- jxr: http://maven.apache.org/plugins/maven-jxr-plugin/ -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jxr-plugin</artifactId>
        <configuration>
          <inputEncoding>UTF-8</inputEncoding>
          <outputEncoding>UTF-8</outputEncoding>
        </configuration>
      </plugin>
      <!-- cobertura: http://mojo.codehaus.org/cobertura-maven-plugin/ -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <configuration>
          <formats>
            <format>xml</format>
            <format>html</format>
          </formats>
          <instrumentation>
            <!-- ignoreはパッケージ名で指定。
            <ignores>
              <ignore>com.shin1o.exclude.*</ignore>
            </ignores>
            -->
            <!-- includes/excludesはスラッシュ区切り,classを指定
            <includes>
              <include>com/shin1o/include/**/*.class</include>
            </includes>
            <excludes>
              <exclude>**/*Test*.class</exclude>
            </excludes>
            -->
          </instrumentation>
        </configuration>
      </plugin>
      <!-- surefire-report: http://maven.apache.org/plugins/maven-surefire-report-plugin/ -->
      <plugin>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <reportSets>
          <reportSet>
            <reports>
              <report>report-only</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>
      <!-- site: http://maven.apache.org/plugins/maven-site-plugin/ -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <configuration>
          <inputEncoding>UTF-8</inputEncoding>
          <outputEncoding>UTF-8</outputEncoding>
        </configuration>
      </plugin>
      <!-- javadoc: http://maven.apache.org/plugins/maven-javadoc-plugin/ -->
      <plugin>
        <artifactId>maven-javadoc-plugin</artifactId>
        <configuration>
          <author>true</author>
          <source>1.5</source>
          <showPackage>false</showPackage>
          <showPrivate>true</showPrivate>
          <encoding>UTF-8</encoding>
          <charset>UTF-8</charset>
          <docencoding>UTF-8</docencoding>
          <links>
            <link>http://java.sun.com/j2se/1.5.0/ja/docs/ja/api/</link>
          </links>
        </configuration>
      </plugin>
      <!-- project-info: http://maven.apache.org/plugins/maven-project-info-reports-plugin/ -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
      </plugin>
      <!-- jdepend: http://mojo.codehaus.org/jdepend-maven-plugin/ -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jdepend-maven-plugin</artifactId>
      </plugin>
      <!-- pmd/cpd: http://maven.apache.org/plugins/maven-pmd-plugin/ -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <configuration>
          <linkXref>true</linkXref>
          <sourceEncoding>UTF-8</sourceEncoding>
          <minimumTokens>100</minimumTokens>
          <targetJdk>1.5</targetJdk>
        </configuration>
      </plugin>
      <!-- findbugs http://mojo.codehaus.org/findbugs-maven-plugin/ -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>findbugs-maven-plugin</artifactId>
        <configuration>
          <xmlOutput>true</xmlOutput>
          <effort>Max</effort>
        </configuration>
      </plugin>
      <!-- dashboard: http://maven.apache.org/plugins/dashboard-maven-plugin/ -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>dashboard-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </reporting>

  <repositories>
    <repository>
      <id>Maven Snapshots</id>
      <url>http://snapshots.maven.codehaus.org/maven2/</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>false</enabled>
      </releases>
    </repository>
  </repositories>

  <pluginRepositories>
    <pluginRepository>
      <id>Codehaus Snapshots</id>
      <url>http://snapshots.repository.codehaus.org/</url>
    </pluginRepository>
  </pluginRepositories>
</project>

依存性の定義について

maven公式|http://maven.apache.org/pom.html#Dependencies

optional

他から依存されたときに、無駄に依存を強制しないようにするため。例えば、自分は必ずhoge.jarが必要だが、自分に依存するartifactは必ずしも必要ないかもしれない、といった場合にoptional=trueを設定しておくと、行儀が良いかもしれない。

dependency/exclusions/exclusion

依存先の依存を引っ張ってこないようにする時は、ここで無視したいgroupIdとartifactIdを指定する。

親子関係の注意点

  1. parentproject\trunk
    1. pom.xml
    2. subproject1
      1. pom.xml(parentprojectをparentとして指定)
    3. subproject2
    4. ...

こんな構成のとき、subproject1のみinstallしても、親のpom.xmlがリポジトリに無いときに別projetからsubproject1を解決できない。当たり前といえば当たり前だが、手を抜こうとして最初はまった。 

dependencyのテンプレート

大概追加している依存artifactのテンプレ。

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.5</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest-library</artifactId>
    <version>1.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.easymock</groupId>
    <artifactId>easymockclassextension</artifactId>
    <version>2.4</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>aopalliance</groupId>
    <artifactId>aopalliance</artifactId>
    <version>1.0</version>
</dependency>
<dependency>
    <groupId>commons-lang</groupId>
    <artifactId>commons-lang</artifactId>
    <version>2.4</version>
</dependency>
<dependency>
    <groupId>commons-collections</groupId>
    <artifactId>commons-collections</artifactId>
    <version>3.2.1</version>
</dependency>
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>1.4</version>
</dependency>
<dependency>
    <groupId>commons-beanutils</groupId>
    <artifactId>commons-beanutils</artifactId>
    <version>1.8.0</version>
    <exclusions>
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.5.6</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jcl-over-slf4j</artifactId>
    <version>1.5.6</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>0.9.15</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>0.9.15</version>
</dependency>