Maven 实战 05 聚合与继承

聚合:一条命令构建多个模块
 <project>
        <modelVersion>4.0.0</modelVersion>        
        <groupId>com.jubenxu.mvnbook.account</groupId>
        <artifactId>account-aggregator</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <!-- packaging为POM类型 -->
          <packaging>pom</packaging>
        <name>Account Aggregator</name>
          <modules>
            <!-- 每个module的值都是一个当前POM的相对目录 -->
            <module>../account-email</module>
            <module>../account-persist</module>
            <!-- 将父模块加入到聚合中 -->
            <module>../account-parent</module>
          </modules>

    </project>

继承:简化配置
父模块
    <project>
        <modelVersion>4.0.0</modelVersion>

        <groupId>com.juvenxu.mvnbook.account</groupId>
        <artifactId>account-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <!-- packaging为POM类型 -->
        <packaging>pom</packaging>

        <name>account-parent</name>

        <properties>
            <springframework.version>2.5.6</springframework.version>
            <junit.version>4.10</junit.version>
        </properties>
        <!-- 依赖管理 不会引入任何依赖 -->
        < dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-core</artifactId>
                    <version>${springframework.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-beans</artifactId>
                    <version>${springframework.version}</version>
                </dependency>
                <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <version>${junit.version}</version>
                </dependency>
            </dependencies>
        </dependencyManagement>

        <build>
            <!-- 插件管理 不会引入插件 -->
            < pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>2.1.1</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.3.2</version>
                        <configuration>
                            <source>1.5</source>
                            <target>1.5</target>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>2.5</version>
                        <configuration>
                            <encoding>UTF-8</encoding>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </project>

 子模块
    <project>
        <modelVersion>4.0.0</modelVersion>
          <!-- 指定父模块 -->
         <parent>
            <groupId>com.juvenxu.mvnbook.account</groupId>
            <artifactId>account-parent</artifactId>
            <version>0.0.1-SNAPSHOT</version>
              <!-- 父模块POM的相对路径 -->
              <relativePath>../account-parent/pom.xml</relativePath>
         </parent>

        <artifactId>account-email</artifactId>
        <name>account-email</name>

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

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

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </project>

     <parent>的子元素的<relativePath>表示父模块POM的相对路径

默认情况,在聚会POM处运行 mvn clean install 会构建所有模块,有时只想构建某几个模块可以:
mvn clean install -pl ../account-email


转载于:https://my.oschina.net/Yaland/blog/424960

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值