May 13, 2007
Maven2 で POM の inheritance & aggregation を整理してみる(2)
aggregation の実験
aggregation 用のサンプルプロジェクトは下記の様な構成。 基本的には inheritance 用と全く同じ。 \aggregation\pom.xml は packageing=pom で aggregation を使用できるようにしてある。 \aggregation\child\pom.xml は inheritance の時とは異なり、継承を表す parent タグを外してある。
\aggregation ├pom.xml └child ├pom.xml └src └java └com └example └HelloWorld.java
\aggregation\pom.xml
<?xml version="1.0" encoding="UTF-8" ?>
<project>
<modelVersion>4.0.0</modelVersion>
<name>pom aggregation sample</name>
<groupId>com.example</groupId>
<artifactId>pom-aggregation-sample</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>jp.in-vitro.largo</groupId>
<artifactId>largo-support-pom</artifactId>
<version>2.0.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>dumpPom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<charset>Shift_JIS</charset>
</configuration>
</plugin>
</plugins>
</reporting>
<organization>
<name>example.com</name>
<url>http://www.example.com/</url>
</organization>
<developers>
<developer>
<id>me</id>
<name>me</name>
</developer>
</developers>
<issueManagement>
<system>Bugzilla</system>
<url>http://www.example.com/bugzilla</url>
</issueManagement>
<ciManagement>
<system>continuum</system>
<url>http://www.example.com/continuum</url>
</ciManagement>
<mailingLists>
<mailingList>
<name>Developer ML</name>
<subscribe>subscribe@example.com</subscribe>
<unsubscribe>unsubscribe@example.com</unsubscribe>
<post>developer@example.com</post>
</mailingList>
</mailingLists>
<scm>
<connection>scm:svn:http://www.example.com/svn/my-project</connection>
<developerConnection>scm:svn:https://127.0.0.1/svn/my-project</developerConnection>
<tag>HEAD</tag>
<url>http://www.example.com/websvn/my-project</url>
</scm>
<repositories>
<repository>
<id>repository.example.com</id>
<name>example.com repository</name>
<url>http://www.example.com/maven2</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>repository.example.com</id>
<name>example.com repository</name>
<url>scp://www.example.com/maven2</url>
</repository>
</distributionManagement>
<modules>
<module>child</module>
</modules>
</project>
\aggregation\child\pom.xml
今回は aggregation のみ使用することが目的なので、inheritance を表す parent タグは使用していない。 \aggregation\pom.xml との違いを明確にするために、わざとほとんどの設定を省略している。
<?xml version="1.0" encoding="UTF-8" ?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>pom-aggregation-sample-child</artifactId>
<version>1.0.0</version>
<name>pom aggregation sample - child</name>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>jp.in-vitro.largo</groupId>
<artifactId>largo-support-pom</artifactId>
<version>2.0.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>dumpPom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\aggregation で Maven2 による compile を実行した結果
aggregation を使用しているので、\aggregation\pom.xml を使用してコンパイルを実行すると \aggregation\child\pom.xml も同時に処理されている。 今回は inheritance を使用していないので、\aggregation\child\pom.xml では \aggregation\pom.xml の内容は引き継がれていない。 例えば、Developer や Organization といった項目に注目してみると、\aggregation\child\pom.xml では空になっていることが分かる。 また、\aggregation\pom.xml では、Modules に child が設定されていることが分かる。
aggregation>mvn compile
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO] pom aggregation sample - child
[INFO] pom aggregation sample
[INFO] -------------------------------------------------------------------------
---
[INFO] Building pom aggregation sample - child
[INFO] task-segment: [compile]
[INFO] -------------------------------------------------------------------------
---
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Compiling 1 source file to D:\aggregation\child\tar
get\classes
[INFO] [largo-support-pom:dumpPom {execution: default}]
***** POM INFORMATION *************************************
id : com.example:pom-aggregation-sample-child:jar:1.0.0
groupId : com.example
atrifactId : pom-aggregation-sample-child
version : 1.0.0
name : pom aggregation sample - child
***********************************************************
Parent : null
File : D:\aggregation\child\pom.xml
Basedir : D:\aggregation\child
Repositories : [org.apache.maven.model.Repository@29345020[name=Maven Repository
Switchboard,url=http://repo1.maven.org/maven2,id=central,layout=default,release
s=null,snapshots=org.apache.maven.model.RepositoryPolicy@11db6bb],]
BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],Plugin [org.apache.
maven.plugins:maven-resources-plugin],Plugin [org.apache.maven.plugins:maven-com
piler-plugin],]
ReportPlugins : []
Developers : []
Organization : null
[INFO] -------------------------------------------------------------------------
---
[INFO] Building pom aggregation sample
[INFO] task-segment: [compile]
[INFO] -------------------------------------------------------------------------
---
[INFO] [largo-support-pom:dumpPom {execution: default}]
***** POM INFORMATION *************************************
id : com.example:pom-aggregation-sample:pom:1.0.0
groupId : com.example
atrifactId : pom-aggregation-sample
version : 1.0.0
name : pom aggregation sample
***********************************************************
Parent : null
File : D:\aggregation\pom.xml
Basedir : D:\aggregation
Repositories : [org.apache.maven.model.Repository@30311876[name=example.com repo
sitory,url=http://www.example.com/maven2,id=repository.example.com,layout=defaul
t,releases=null,snapshots=null],org.apache.maven.model.Repository@28326938[name=
Maven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout
=default,releases=null,snapshots=org.apache.maven.model.RepositoryPolicy@139e351
],]
Modules : [child,]
BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],]
ReportPlugins : [org.apache.maven.model.ReportPlugin@51127a,]
Developers : [org.apache.maven.model.Developer@30167145[name=me,email=null,id=me
,organization=null,organizationUrl=null,roles=[]],]
Organization : org.apache.maven.model.Organization@13594894[name=example.com,url
=http://www.example.com/]
[INFO]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] pom aggregation sample - child ........................ SUCCESS [2.640s]
[INFO] pom aggregation sample ................................ SUCCESS [0.047s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Sun May 13 18:05:02 JST 2007
[INFO] Final Memory: 4M/9M
[INFO] ------------------------------------------------------------------------
aggregation>
\aggregation\child で Maven2 による compile を実行した結果
\aggregation\child\pom.xml を使用してコンパイルを実行してみる。 aggregation を使用していても、基本的には \aggregation\pom.xml との親子関係は無いので単体で問題なくコンパイルできる。
aggregation\child>mvn compile
[INFO] Scanning for projects...
[INFO] -------------------------------------------------------------------------
---
[INFO] Building pom aggregation sample - child
[INFO] task-segment: [compile]
[INFO] -------------------------------------------------------------------------
---
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Compiling 1 source file to D:\aggregation\child\target\classes
[INFO] [largo-support-pom:dumpPom {execution: default}]
***** POM INFORMATION *************************************
id : com.example:pom-aggregation-sample-child:jar:1.0.0
groupId : com.example
atrifactId : pom-aggregation-sample-child
version : 1.0.0
name : pom aggregation sample - child
***********************************************************
Parent : null
File : D:\aggregation\child\pom.xml
Basedir : D:\aggregation\child
Repositories : [org.apache.maven.model.Repository@33459432[name=Maven Repository
Switchboard,url=http://repo1.maven.org/maven2,id=central,layout=default,release
s=null,snapshots=org.apache.maven.model.RepositoryPolicy@d4d66b],]
Modules : []
BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],Plugin [org.apache.
maven.plugins:maven-resources-plugin],Plugin [org.apache.maven.plugins:maven-com
piler-plugin],]
ReportPlugins : []
Developers : []
Organization : null
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Sun May 13 18:12:51 JST 2007
[INFO] Final Memory: 4M/8M
[INFO] ------------------------------------------------------------------------
aggregation\child>
writeback message: Ready to post a comment.
