Skip to content

cuisongliu/mybatis_generator_gradle_plugin

Repository files navigation

Build Status Dependency Status license license

MyBatis Generator Gradle Plugin(MBG)

This plugin is based on https://github.com/mybatis/generator. This is a gradle plugin of mybatisGeneratorPlugin(mbg). This plugin has all the features of mybatisGeneratorPlugin(mbg), but the plugin realization of groovy from gradle3.3.

简体中文

Add the plugin to you project

Build script snippet for use in all Gradle versions:
buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.com.cuisongliu.plugin:mybatis-generator:0.9.6"
  }
}

apply plugin: "com.cuisongliu.plugin.mybatis-generator"

Build script snippet for new, incubating, plugin mechanism introduced in Gradle 2.1:

plugins {
  id "com.cuisongliu.plugin.mybatis-generator" version "0.9.6"
}

Specify settings

mbg {
  overwrite = false
  consoleable = true
  jdbc{
    driver = "com.mysql.jdbc.Driver"
    url    = "jdbc:mysql://[ip]:[port]/[dbname]?useSSL=false"
    username = "username"
    password = "password"
  }
  xml{
      resourcesProject = "src/main/java"
      mapperPlugin = tk.mybatis.mapper.generator.MapperPlugin.class
      mapperMapper = "com.cuisongliu.springboot.core.mapper.MyMapper"
      mapperPackage= "com.cuisongliu.mapper"
      modelPackage = "com.cuisongliu.entity"
      xmlPackage =   "com.cuisongliu.mapper"
      tableName ="s_system"
      objectName ="System"
      mapperSuffix ="Mapper"
  }
}

If no settings are provided, the plugin tries to use sensible defaults.

Setting Name Type Description Default
overwrite boolean Specifies whether the mojo overwrites existing files. Default is true. true
generatorFile String Location of the configuration file. generatorConfig.xml
sqlScript String Location of a SQL script file to run before generating code. null
consoleable boolean Specifies whether progress messages to the console. false
skip boolean Skip generator. false
contexts String Comma delimited list of contexts to generate. null
tableNames String Comma delimited list of table names to generate. null
Setting Name Type Description Default
jdbc driver String JDBC Driver name.Not Null null
url String JDBC URL.Not Null null
username String JDBC user name.Not Null root
password String JDBC password.Not Null null
xml javaProject String Mybatis generator output sources directory. src/main/java
resourcesProject String Mybatis generator output resources directory. src/main/resources
mapperPackage String Mybatis generator output javaClient package.Not Null null
modelPackage String Mybatis generator output javaModel package.Not Null null
xmlPackage String Mybatis generator output sqlMapper package.Not Null null
mapperPlugin Class Mybatis generator plugin class.Not Null tk.mybatis.mapper. generator.MapperPlugin. class
mapperMapper String Mybatis generator javaClient extends class.Not Null tk.mybatis.mapper. common.Mapper
tableName String Mybatis generator db table name.Not Null null
objectName String Mybatis generator object class name.Not Null null
mapperSuffix String Mybatis generator javaClient mapper suffix. Mapper

Run the mbg task

  1. Add generatorConfig.xml to your execution module.Set the variable in the table information.
  2. In the build.gradle file append Specify settings
  3. In the build.gradle directory execute gradle mbg
  4. The default support for mysql.If you use oracle or other database need to add the following additional configuration to Specify settings.
    buildscript{
        def baseUrl = "http://maven.cuisongliu.com"
        def nexusUrl = "$baseUrl/content/groups/public/"
        repositories {
            mavenLocal()
            maven { url "$nexusUrl" }
        }
        dependencies {
            classpath "com.oracle:ojdbc6:11.1.0.7.0"
        }
    }

Add buildscript before using the plugin,configure the classpath driver depends on the jar package (where the maven address changes as the case may be)