mybatis-generator-plugin
mybatis-generator-plugin copied to clipboard
Mybatis Gradle Generator Plugin
Mybatis Generator Plugin
Description
This is only the wrapper for MyBatis Generator on Gradle.
Every details about the generate defined in the file which you declare the path in the mybatisGenerator/configFile.
You can override the dependencies to the newest version in the configuration, or other database dependencies.
Usage
In your build.gradle file, add following plugin in two ways:
Using the plugins DSL:
plugins {
id "com.thinkimi.gradle.MybatisGenerator" version "2.4"
}
Using legacy plugin application:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.thinkimi.gradle:mybatis-generator-plugin:2.4"
}
}
apply plugin: "com.thinkimi.gradle.MybatisGenerator"
Add configuration:
configurations {
mybatisGenerator
}
mybatisGenerator {
verbose = true
configFile = 'src/main/resources/autogen/generatorConfig.xml'
mybatisProperties = ['key1' : "value1",'key2' : "value2"]
// optional, here is the override dependencies for the plugin or you can add other database dependencies.
dependencies {
mybatisGenerator 'org.mybatis.generator:mybatis-generator-core:1.4.0'
mybatisGenerator 'mysql:mysql-connector-java:5.1.47'
mybatisGenerator 'org.postgresql:postgresql:42.2.6'
mybatisGenerator // Here add your mariadb dependencies or else
}
}
Properties support in generatorConfig.xml
Properties set under mybatisProperties can be referenced with placeholder syntax in the configFile.
mybatisProperties = ['jdbcUrl' : 'jdbc:postgresql:.....',
'jdbcDriverClass': 'org.postgresql.Driver',
'jdbcUsername' : '...',
'jdbcPassword' : '...',
]
<!-- generatorConfig.xml -->
<!-- reference the parameters by using ${...} -->
<jdbcConnection
driverClass="${jdbcDriverClass}"
connectionURL="${jdbcUrl}"
userId="${jdbcUsername}"
password="${jdbcPassword}">
</jdbcConnection>
Test
Use Spock Framework to test, just run ./gradlew clean check.