maven resource 覆盖配置使用

maven resource 插件可以对于resource 进行处理,比如合并,copy,有一种比较常见的用法是进行覆盖
比如我们基于配置插件,在resource 阶段将依赖其他配置中心或者repo 的配置文件合并并覆盖到我们的构建包中

参考配置

  • 标准插件配置
 
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <executions>
      <execution>
          <id>Copy  target static folder</id>
          <phase>process-resources</phase>
          <goals>
              <goal>copy-resources</goal>
          </goals>
          <configuration>
              <outputDirectory>${project.build.outputDirectory}/public</outputDirectory>
              <overwrite>true</overwrite> // 此命令比较重要
              <resources>
                  <resource>
                      <directory>web/dist</directory>
                      <filtering>false</filtering>
                  </resource>
              </resources>
          </configuration>
      </execution>
  </executions>
</plugin>
  • 基于properties 配置
<maven.resources.overwrite>true</maven.resources.overwrite>

一种参考玩法

将不同环境的配置放在git repo 或者config 中心中,对于构建基于jenkins 使用maven 的resource 插件可以将配置进行合并,然后打包,对于基于容器的
可以基于jib-maven-plugin 实现不依赖docker engine 的镜像构建

 

 

参考资料

https://maven.apache.org/plugins/maven-resources-plugin/copy-resources-mojo.html
https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin

posted on 2022-10-12 20:30  荣锋亮  阅读(456)  评论(0编辑  收藏  举报

导航