Skip to content

kimichen13/mybatis-generator-plugin

Repository files navigation

Mybatis Generator Plugin

Travis GitHub stars GitHub forks GitHub license

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.qqviaja.gradle.MybatisGenerator" version "2.5"
}
buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "com.qqviaja.gradle:mybatis-generator-plugin:2.5"
  }
}

apply plugin: "com.qqviaja.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.2'
        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.