使用Maven编译VIVO项目时代码变更被清除,如何解决?
解决VIVO项目Maven构建时本地修改被覆盖的问题
1. 先定位覆盖文件的根源
执行带调试日志的构建命令,查看具体是哪个Maven插件或步骤在覆盖你的修改:
mvn install -e -s installer/settings.xml -X
重点关注日志里包含copy、generate、overwrite关键字的条目,找到对应的插件(比如maven-resources-plugin、VIVO自定义的安装插件等)和执行目标。
2. 临时解决方案:跳过特定插件/步骤
如果已经找到肇事插件,直接在构建命令中添加跳过参数:
- 若为资源复制插件(maven-resources-plugin):
mvn install -e -s installer/settings.xml -Dmaven.resources.skip=true - 若为VIVO自定义的安装插件,查看项目pom.xml里的插件配置,找到对应的跳过参数(比如
-Dvivo.installer.skip=true),添加到命令中; - 若涉及清理步骤,跳过clean插件:
mvn install -e -s installer/settings.xml -Dmaven.clean.skip=true
3. 长期解决方案:修改项目构建配置
直接修改项目的pom.xml(或installer目录下的配置文件),避免修改文件被覆盖:
- 排除特定文件:找到负责复制/生成文件的插件配置,添加
excludes节点排除你修改过的文件。比如针对maven-resources-plugin:<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <executions> <execution> <id>copy-resources</id> <phase>process-resources</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.outputDirectory}</outputDirectory> <resources> <resource> <directory>src/main/templates</directory> <filtering>true</filtering> <excludes> <!-- 替换为你修改的文件路径 --> <exclude>path/to/your/modified/file.properties</exclude> </excludes> </resource> </resources> </configuration> </execution> </executions> </plugin> - 添加开关参数:给插件配置添加可跳过的参数,方便后续按需控制。比如:
之后构建时只需添加参数即可跳过覆盖:<plugin> <!-- 对应插件信息 --> <configuration> <skip>${skip.modified.files.overwrite}</skip> </configuration> </plugin>mvn install -e -s installer/settings.xml -Dskip.modified.files.overwrite=true
4. 检查VIVO安装器的特殊逻辑
查看installer/settings.xml和项目根目录的pom.xml,确认是否有VIVO专属的构建步骤(比如Ant任务、自定义脚本)在重置文件。如果有,修改对应脚本的逻辑,比如添加文件存在则跳过的判断。
内容的提问来源于stack exchange,提问作者Jose Cabrera Zuniga
相关产品推荐
相关产品推荐

