-
在gradle加一个configurations
configurations{ mybatisGenerator }
-
然后在依赖中加入mybatisGenerator的依赖:
mybatisGenerator 'org.mybatis.generator:mybatis-generator-core:1.3.2' mybatisGenerator 'mysql:mysql-connector-java:5.1.36' mybatisGenerator 'tk.mybatis:mapper:3.3.2'
-
在grade了加入一个task,configfile的值为mybatis-generator的配置文件路径:
task mybatisGenerate << { ant.taskdef( name: 'mbgenerator', classname: 'org.mybatis.generator.ant.GeneratorAntTask', classpath: configurations.mybatisGenerator.asPath ) ant.mbgenerator(overwrite: true, configfile: 'src/main/resources/generatorConfig.xml', verbose: true)
}
- 配置mybatis-generator的配置文件generatorConfig.xml
#配置mybatis的xml路径 mybatis.mapper-locations: classpath:mybatis/*.xml