今天发现mybatis generator maven plugin在重复生成的时候xml文件只会merge,不会覆盖。
明明在pom.xml中配置了如下:
<configuration>
<configurationFile>src/main/resources/mybatis/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
去github上查找与overwrite相关的issue,找到了这个提交。

上面的意思是:当你取消了所有注释,你在重复运行generator时在mapper.xml中会出现重复的元素。并且这个plugin可以解决这个问题,版本是1.3.7
去查看generatorConfiguration,确实配置了取消生成注释。
<!-- 配置生成器 -->
<generatorConfiguration>
<properties resource="mybatis/jdbc.properties"/>
<context id="MyBatis" targetRuntime="MyBatis3" defaultModelType="flat">
<!-- 不生成注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
... ...
<generatorConfiguration>
那怎么既想取消注释又想覆盖XML文件生成呢?答案就是上面说的使用UnmergeableXmlMappersPlugin
在<context>下增加一个<plugin>
<!-- 配置生成器 -->
<generatorConfiguration>
<properties resource="mybatis/jdbc.properties"/>
<context id="MyBatis" targetRuntime="MyBatis3" defaultModelType="flat">
<!--覆盖生成XML文件-->
<plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />
<!-- 不生成注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
... ...
<generatorConfiguration>
GitHub地址:https://github.com/syoukaihou/sbsm
原文:https://www.cnblogs.com/xxoome/p/10068780.html