maven 多模块最佳实践

多模块统一管理

说明:flatten-maven-plugin 插件的统一更新的功劳
注意点:建议使用环境配置profiles,profiles的properties里面要加revision版本;子级的pom版本中的parent中的版本也使用revision,然后自己的版本不写,跟父级版本一致

父级pom(基础配置):

此处是必须的最基础的配置,其他的配置信息未列出,需要根据自身情况来

  <build>
    <plugins>
      <plugin>
       <!-- flatten-maven-plugin 插件可快速更新子级所有包版本 -->
        <artifactId>flatten-maven-plugin</artifactId>
        <configuration>
          <!-- 是否更新pom文件,此处还有更高级的用法 -->
          <flattenMode>resolveCiFriendliesOnly</flattenMode>
          <updatePomFile>true</updatePomFile>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>flatten</goal>
            </goals>
            <id>flatten</id>
            <phase>process-resources</phase>
          </execution>
          <execution>
            <goals>
              <goal>clean</goal>
            </goals>
            <id>flatten.clean</id>
            <phase>clean</phase>
          </execution>
        </executions>
        <groupId>org.codehaus.mojo</groupId>
        <version>1.1.0</version>
      </plugin>
      <plugin>
        <artifactId>maven-source-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>jar</goal>
            </goals>
            <id>attach-sources</id>
          </execution>
        </executions>
        <groupId>org.apache.maven.plugins</groupId>
        <version>3.2.1</version>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
        <groupId>org.apache.maven.plugins</groupId>
        <version>2.22.2</version>
      </plugin>
    </plugins>
  </build>
  <modules>
  <!-- start module(此module只是个例子,自己需求来建,此处不讨论模型脚手架) -->
    <module>start</module>
  </modules>
  <profiles>
    <profile>
      <activation>
        <!--这个字段表示默认激活-->
        <activeByDefault>true</activeByDefault>
      </activation>
      <id>dev</id>
      <properties>
      <!-- 由于flatten-maven-plugin,所以版本号只能为${revision} -->
        <revision>0.0.1-SNAPSHOT</revision>
      </properties>
    </profile>
    <profile>
      <id>test</id>
      <properties>
        <revision>0.0.1-SNAPSHOT</revision>
      </properties>
    </profile>
    <profile>
      <id>pre</id>
      <properties>
        <revision>0.0.1-RELEASE</revision>
      </properties>
    </profile>
    <profile>
      <id>master</id>
      <properties>
        <revision>0.0.1-RELEASE</revision>
      </properties>
    </profile>
  </profiles>
  <!-- 此处由于flatten-maven-plugin,所以版本号只能为${revision} -->
  <version>${revision}</version>
  <properties>
    <!--可能第一次编辑会有找不到revision版本的问题,所以需要此处加一个,
    只需要第一次编译通过后,这个配置就可以去掉了,当然不去掉也可以,默认是使用的的profile里激活的配置,这里也不需要每次更新它-->
    <revision>0.0.1-SNAPSHOT</revision>
  
  </properties>
  ....
  ....

子级pom(基础配置):

start.pom.xml

<parent>
    <artifactId>...</artifactId>
    <groupId>...</groupId>
    <version>${revision}</version>
</parent>

 <artifactId>start</artifactId>
  ....
  ....

deploy发布到仓库跳过模块

一般我们给三方或二方提供服务包的时候,需要将某个包deploy到远程仓库中,例如是提供的FeignClient包,因为我们加上前面的统一版本的配置,所以在父pom上直接deploy时,不需要提供给三方或二方的子module里加上跳过deploy

某个pom:

  <properties>
    <maven.deploy.skip>true</maven.deploy.skip>
  </properties>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值