May 14, 2007

[Maven] Maven2 で POM の inheritance & aggregation を整理してみる(3)

inheritance & aggregation の実験

inheritance & aggregation 用のサンプルプロジェクトは下記の様な構成。 基本的には前回 2 つと全く同じ。 \both\pom.xml は packageing=pom で aggregation を使用できるようにしてある。 \both\child\pom.xml は継承を表す parent タグを使用して \both\pom.xml を継承してある。

\both
  ├pom.xml
  └child
    ├pom.xml
    └src
      └java
        └com
         └example
           └HelloWorld.java

\both\pom.xml

artifactId、name 以外は aggregation のサンプルと全く同一。

<?xml version="1.0" encoding="UTF-8" ?>

<project>
  <modelVersion>4.0.0</modelVersion>
  <name>pom both sample</name>
  <groupId>com.example</groupId>
  <artifactId>pom-both-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>

\both\child\pom.xml

artifactId、name 以外は inheritance のサンプルと全く同一。

<?xml version="1.0" encoding="UTF-8" ?>

<project>
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.example</groupId>
    <artifactId>pom-both-sample</artifactId>
    <version>1.0.0</version>
  </parent>

  <artifactId>pom-both-sample-child</artifactId>
  <name>pom both sample - child</name>
  <packaging>jar</packaging>

</project>

\both で Maven2 による compile を実行した結果

aggregation を使用しているので、\both\pom.xml を使用してコンパイルを実行すると \both\child\pom.xml も同時に処理されている。 また、inheritance も使用しているので、\both\pom.xml の設定項目が \both\child\pom.xml に継承されている。


both>mvn compile
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO]   pom both sample
[INFO]   pom both sample - child
[INFO] -------------------------------------------------------------------------
---
[INFO] Building pom both sample
[INFO]    task-segment: [compile]
[INFO] -------------------------------------------------------------------------
---
[INFO] [largo-support-pom:dumpPom {execution: default}]
***** POM INFORMATION *************************************
  id : com.example:pom-both-sample:pom:1.0.0
  groupId : com.example
  atrifactId : pom-both-sample
  version : 1.0.0
  name : pom both sample
***********************************************************
Parent : null
File : D:\both\pom.xml
Basedir : D:\both
Repositories : [org.apache.maven.model.Repository@13059051[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@3945515[name=M
aven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout=
default,releases=null,snapshots=org.apache.maven.model.RepositoryPolicy@8530b8],
]
Modules : [child,]
BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],]
ReportPlugins : [org.apache.maven.model.ReportPlugin@1deeb40,]
Developers : [org.apache.maven.model.Developer@30633470[name=me,email=null,id=me
,organization=null,organizationUrl=null,roles=[]],]
Organization : org.apache.maven.model.Organization@25109548[name=example.com,url
=http://www.example.com/]

[INFO] -------------------------------------------------------------------------
---
[INFO] Building pom both 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:\both\child\target\classes
[INFO] [largo-support-pom:dumpPom {execution: default}]
***** POM INFORMATION *************************************
  id : com.example:pom-both-sample-child:jar:1.0.0
  groupId : com.example
  atrifactId : pom-both-sample-child
  version : 1.0.0
  name : pom both sample - child
***********************************************************
Parent : org.apache.maven.project.MavenProject@f328409
File : D:\both\child\pom.xml
Basedir : D:\both\child
Repositories : [org.apache.maven.model.Repository@29857804[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@13594894[name=
Maven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout
=default,releases=null,snapshots=org.apache.maven.model.RepositoryPolicy@1077fc9
],]
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 : [org.apache.maven.model.ReportPlugin@a2220f,]
Developers : [org.apache.maven.model.Developer@1668655[name=me,email=null,id=me,
organization=null,organizationUrl=null,roles=[]],]
Organization : org.apache.maven.model.Organization@7388808[name=example.com,url=
http://www.example.com/]

***** POM INFORMATION *************************************
  id : com.example:pom-both-sample:pom:1.0.0
  groupId : com.example
  atrifactId : pom-both-sample
  version : 1.0.0
  name : pom both sample
***********************************************************
Parent : null
File : D:\both\pom.xml
Basedir : D:\both
Repositories : [org.apache.maven.model.Repository@13059051[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@3945515[name=M
aven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout=
default,releases=null,snapshots=org.apache.maven.model.RepositoryPolicy@8530b8],
]
Modules : [child,]
BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],]
ReportPlugins : [org.apache.maven.model.ReportPlugin@1deeb40,]
Developers : [org.apache.maven.model.Developer@30633470[name=me,email=null,id=me
,organization=null,organizationUrl=null,roles=[]],]
Organization : org.apache.maven.model.Organization@25109548[name=example.com,url
=http://www.example.com/]

[INFO]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] pom both sample ....................................... SUCCESS [0.969s]
[INFO] pom both sample - child ............................... SUCCESS [1.766s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Mon May 14 00:14:11 JST 2007
[INFO] Final Memory: 4M/13M
[INFO] ------------------------------------------------------------------------

both>

\both\child で Maven2 による compile を実行した結果

\both\child\pom.xml を使用してコンパイルを実行してみる。 \both\pom.xml を継承しているので、\both\child\pom.xml がきちんと \both\pom.xml の内容を引き継いでいることが分かる。


both\child>mvn compile
[INFO] Scanning for projects...
[INFO] -------------------------------------------------------------------------
---
[INFO] Building pom both 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:\both\child\target\classes
[INFO] [largo-support-pom:dumpPom {execution: default}]
***** POM INFORMATION *************************************
  id : com.example:pom-both-sample-child:jar:1.0.0
  groupId : com.example
  atrifactId : pom-both-sample-child
  version : 1.0.0
  name : pom both sample - child
***********************************************************
Parent : org.apache.maven.project.MavenProject@f328409
File : D:\both\child\pom.xml
Basedir : D:\both\child
Repositories : [org.apache.maven.model.Repository@33459432[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@13948523[name=
Maven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout
=default,releases=null,snapshots=org.apache.maven.model.RepositoryPolicy@149105b
],]
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 : [org.apache.maven.model.ReportPlugin@196f4b5,]
Developers : [org.apache.maven.model.Developer@33445663[name=me,email=null,id=me
,organization=null,organizationUrl=null,roles=[]],]
Organization : org.apache.maven.model.Organization@6326112[name=example.com,url=
http://www.example.com/]

***** POM INFORMATION *************************************
  id : com.example:pom-both-sample:pom:1.0.0
  groupId : com.example
  atrifactId : pom-both-sample
  version : 1.0.0
  name : pom both sample
***********************************************************
Parent : null
File : D:\both\pom.xml
Basedir : D:\both
Repositories : [org.apache.maven.model.Repository@13301441[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@17708501[name=
Maven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout
=default,releases=null,snapshots=org.apache.maven.model.RepositoryPolicy@1f03691
],]
Modules : [child,]
BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],]
ReportPlugins : [org.apache.maven.model.ReportPlugin@1b03c1a,]
Developers : [org.apache.maven.model.Developer@5313146[name=me,email=null,id=me,
organization=null,organizationUrl=null,roles=[]],]
Organization : org.apache.maven.model.Organization@6888942[name=example.com,url=
http://www.example.com/]

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Mon May 14 00:22:39 JST 2007
[INFO] Final Memory: 4M/8M
[INFO] ------------------------------------------------------------------------

both\child>

Posted in Maven | このエントリーをはてなブックマークに追加 | この記事をクリップ! livedoor クリップ |