Maven - 實例-6-聚合與繼承

建立項目

xxx - 繼承自testDep.PPP

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>testDep.XXX</groupId>
    <artifactId>xxx</artifactId>
    <packaging>jar</packaging>

    <name>xxx</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <parent>
        <groupId>testDep.PPP</groupId>
        <artifactId>ppp</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
    </dependencies>
</project>

yyy - 繼承自testDep.PPP

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>testDep.YYY</groupId>
    <artifactId>yyy</artifactId>
    <packaging>jar</packaging>

    <name>yyy</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <parent>
        <groupId>testDep.PPP</groupId>
        <artifactId>ppp</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
    </dependencies>
</project>

zzz - 在zzz中聚合xxx和yyy

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>testDep.ZZZ</groupId>
  <artifactId>zzz</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>

  <name>zzz</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <modules>
    <module>../xxx</module>
    <module>../yyy</module>    
  </modules>  
</project>

ppp - 父項目

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>testDep.PPP</groupId>
    <artifactId>ppp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>ppp</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit.version>3.8.1</junit.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit.version}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

驗證

ppp執行clean install

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building ppp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ ppp ---
[INFO] Deleting D:\Anliven-Running\Zen\EclipseProjects\ppp\target
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ ppp ---
[INFO] Installing D:\Anliven-Running\Zen\EclipseProjects\ppp\pom.xml to D:\DownLoadFiles\apache-maven-repo\testDep\PPP\ppp\0.0.1-SNAPSHOT\ppp-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.578 s
[INFO] Finished at: 2017-10-24T16:43:09+08:00
[INFO] Final Memory: 9M/309M
[INFO] ------------------------------------------------------------------------

xxx執行clean install

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building xxx 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ xxx ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\Anliven-Running\Zen\EclipseProjects\xxx\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ xxx ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ xxx ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\Anliven-Running\Zen\EclipseProjects\xxx\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ xxx ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ xxx ---
[INFO] Surefire report directory: D:\Anliven-Running\Zen\EclipseProjects\xxx\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running testDep.XXX.xxx.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.004 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ xxx ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ xxx ---
[INFO] Installing D:\Anliven-Running\Zen\EclipseProjects\xxx\target\xxx-0.0.1-SNAPSHOT.jar to D:\DownLoadFiles\apache-maven-repo\testDep\XXX\xxx\0.0.1-SNAPSHOT\xxx-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\Anliven-Running\Zen\EclipseProjects\xxx\pom.xml to D:\DownLoadFiles\apache-maven-repo\testDep\XXX\xxx\0.0.1-SNAPSHOT\xxx-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.520 s
[INFO] Finished at: 2017-10-24T16:47:36+08:00
[INFO] Final Memory: 11M/245M
[INFO] ------------------------------------------------------------------------

zzz 執行clean install

從輸出日誌能夠看到進行了3次構建,並安裝到本地倉庫中:
Building xxx 0.0.1-SNAPSHOT
Building yyy 0.0.1-SNAPSHOT
Building zzz 0.0.1-SNAPSHOTapache

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] xxx
[INFO] yyy
[INFO] zzz
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building xxx 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ xxx ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\Anliven-Running\Zen\EclipseProjects\xxx\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ xxx ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ xxx ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\Anliven-Running\Zen\EclipseProjects\xxx\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ xxx ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ xxx ---
[INFO] Surefire report directory: D:\Anliven-Running\Zen\EclipseProjects\xxx\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running testDep.XXX.xxx.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.006 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ xxx ---
[INFO] Building jar: D:\Anliven-Running\Zen\EclipseProjects\xxx\target\xxx-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ xxx ---
[INFO] Installing D:\Anliven-Running\Zen\EclipseProjects\xxx\target\xxx-0.0.1-SNAPSHOT.jar to D:\DownLoadFiles\apache-maven-repo\testDep\XXX\xxx\0.0.1-SNAPSHOT\xxx-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\Anliven-Running\Zen\EclipseProjects\xxx\pom.xml to D:\DownLoadFiles\apache-maven-repo\testDep\XXX\xxx\0.0.1-SNAPSHOT\xxx-0.0.1-SNAPSHOT.pom
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building yyy 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ yyy ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\Anliven-Running\Zen\EclipseProjects\yyy\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ yyy ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ yyy ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\Anliven-Running\Zen\EclipseProjects\yyy\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ yyy ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ yyy ---
[INFO] Surefire report directory: D:\Anliven-Running\Zen\EclipseProjects\yyy\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running testDep.YYY.yyy.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.008 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ yyy ---
[INFO] Building jar: D:\Anliven-Running\Zen\EclipseProjects\yyy\target\yyy-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ yyy ---
[INFO] Installing D:\Anliven-Running\Zen\EclipseProjects\yyy\target\yyy-0.0.1-SNAPSHOT.jar to D:\DownLoadFiles\apache-maven-repo\testDep\YYY\yyy\0.0.1-SNAPSHOT\yyy-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\Anliven-Running\Zen\EclipseProjects\yyy\pom.xml to D:\DownLoadFiles\apache-maven-repo\testDep\YYY\yyy\0.0.1-SNAPSHOT\yyy-0.0.1-SNAPSHOT.pom
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building zzz 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ zzz ---
[INFO] Installing D:\Anliven-Running\Zen\EclipseProjects\zzz\pom.xml to D:\DownLoadFiles\apache-maven-repo\testDep\ZZZ\zzz\0.0.1-SNAPSHOT\zzz-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] xxx ................................................ SUCCESS [  2.282 s]
[INFO] yyy ................................................ SUCCESS [  0.351 s]
[INFO] zzz ................................................ SUCCESS [  0.007 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.819 s
[INFO] Finished at: 2017-10-24T16:43:49+08:00
[INFO] Final Memory: 12M/309M
[INFO] ------------------------------------------------------------------------
相關文章
相關標籤/搜索