如何阻止maven-remote-resources-plugin覆盖资源文件
解决maven-remote-resources-plugin同名文件不覆盖的配置方法
在引入moduleC资源的模块(moduleA、moduleB)的pom.xml中,通过给maven-remote-resources-plugin的process-remote-resources目标添加overwrite参数并设为false,即可实现本地已有同名文件时不被moduleC的资源覆盖的需求。
具体配置示例
在moduleA或moduleB的pom.xml中添加如下插件配置:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-remote-resources-plugin</artifactId> <version>3.1.0</version> <!-- 使用最新稳定版本即可 --> <executions> <execution> <id>process-remote-resources</id> <goals> <goal>process-remote-resources</goal> </goals> <configuration> <!-- 指定要引入的远程资源模块 --> <resourceBundles> <resourceBundle>your.group.id:moduleC:${project.version}</resourceBundle> </resourceBundles> <!-- 关键配置:禁用同名文件覆盖 --> <overwrite>false</overwrite> </configuration> </execution> </executions> </plugin> </plugins> </build>
补充说明
overwrite参数默认值为true,会强制覆盖本地同名文件;设为false后,插件会跳过本地已存在的文件,仅复制本地没有的资源(比如moduleB会复制moduleC的fileA和fileB,而moduleA只会复制fileB)。- 建议使用3.0.0及以上版本的插件,该参数在这些版本中稳定可用。
内容的提问来源于stack exchange,提问作者Czachodym
相关产品推荐
相关产品推荐

