### Build and Prepare Release Artifacts
Source: https://github.com/mybatis/generator/blob/master/eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/publishing.html
Run this command to activate the release-composite profile, which prepares artifacts for uploading to GitHub. Ensure you have internet access and GPG setup.
```bash
./mvnw clean verify -Prelease-composite
```
--------------------------------
### Configure JDK Toolchain for Maven Build
Source: https://github.com/mybatis/generator/blob/master/eclipse/README.md
Set up a toolchain for Maven builds by creating a `toolchains.xml` file in your `~/.m2` directory. This example configures a JDK 17 from Temurin.
```xml
jdk
17
temurin
/Users/xxx/.sdkman/candidates/java/17.0.16-tem
```
--------------------------------
### Built-in RenameExampleClassPlugin Configuration
Source: https://context7.com/mybatis/generator/llms.txt
Renames generated Example classes using regular expressions. Specify the search string and the replacement string.
```xml
```
--------------------------------
### SQL Script for Database Setup
Source: https://github.com/mybatis/generator/blob/master/eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/manualTesting.html
This SQL script is used to set up the database schema and tables required for MyBatis Generator testing. It includes dropping existing objects and creating new ones.
```sql
drop table a if exists;
drop table mbgtest.b if exists;
drop table mbgtest.b if exists;
drop table mbgtest.c if exists;
drop table mbgtest.d if exists;
drop table mbgtest.e if exists;
drop table mbgtest.f if exists;
drop table mbgtest.g if exists;
drop table mbgtest.h if exists;
drop table mbgtest.i if exists;
drop table mbgtest.j if exists;
drop schema if exists mbgtest;
create schema mbgtest;
create table a (id int not null, description varchar(50), primary key(id));
create table mbgtest.b (id int not null, description varchar(50), primary key(id));
create table mbgtest.c (id int not null, description varchar(50), primary key(id));
create table mbgtest.d (id int not null, description varchar(50), primary key(id));
create table mbgtest.e (id int not null, description varchar(50), primary key(id));
create table mbgtest.f (id int not null, description varchar(50), primary key(id));
create table mbgtest.g (id int not null, description varchar(50), primary key(id));
create table mbgtest.h (id int not null, description varchar(50), primary key(id));
create table mbgtest.i (id int not null, description varchar(50), primary key(id));
create table mbgtest.j (id int not null, description varchar(50), primary key(id));
```
--------------------------------
### Setup GPG TTY for Release
Source: https://github.com/mybatis/generator/blob/master/RELEASING.md
On Unix or Mac systems, set the GPG_TTY environment variable to use the terminal for GPG password prompts during the release process.
```shell
export GPG_TTY=$(tty)
```
--------------------------------
### MyBatis3Simple (Legacy) Context Configuration
Source: https://context7.com/mybatis/generator/llms.txt
Configure a context for the MyBatis3Simple runtime, which generates basic CRUD operations without Example classes. This example demonstrates setting a default order clause for select statements.
```xml
```
--------------------------------
### Run MyBatis Generator Programmatically
Source: https://context7.com/mybatis/generator/llms.txt
Use the MyBatisGenerator.Builder to configure and run code generation. This example shows parsing an XML configuration, building the generator with specific options, and then generating and writing files to disk.
```java
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class MBGRunner {
public static void main(String[] args) throws Exception {
List warnings = new ArrayList<>();
// 1. Parse the XML configuration
ConfigurationParser cp = new ConfigurationParser();
Configuration config = cp.parseConfiguration(new File("src/main/resources/generatorConfig.xml"));
warnings.addAll(cp.getWarnings());
// 2. Build the generator (overwrite existing Java files, enable Java file merging)
MyBatisGenerator generator = new MyBatisGenerator.Builder()
.withConfiguration(config)
.withShellCallback(new DefaultShellCallback()) // resolves target directories
.withOverwriteEnabled(true) // overwrite existing files on collision
.withJavaFileMergeEnabled(false) // set true to lexically merge Java files
.withContextIds(Set.of("MySQLContext")) // run only this context (empty = all)
.withFullyQualifiedTableNames(Set.of("user", "order")) // empty = all tables in config
.build();
// 3a. Generate AND write to disk
warnings.addAll(generator.generateAndWrite());
// 3b. OR generate in-memory only and inspect results
// warnings.addAll(generator.generateOnly());
// generator.getGeneratedJavaFiles().forEach(f -> System.out.println(f.getFileName()));
// generator.getGeneratedXmlFiles().forEach(f -> System.out.println(f.getFileName()));
warnings.forEach(System.out::println);
}
}
```
--------------------------------
### Create a Custom Plugin with PluginAdapter
Source: https://context7.com/mybatis/generator/llms.txt
Extend PluginAdapter and override methods to customize code generation. This example adds a custom annotation to mapper interfaces and a toString() method to model classes. Configure plugin-specific properties in the XML configuration.
```java
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.java.Interface;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.TopLevelClass;
import java.util.List;
import java.util.Properties;
/**
* Example plugin: adds a custom @Repository annotation to every generated
* mapper interface and a custom toString() to every model class.
*/
public class RepositoryAnnotationPlugin extends PluginAdapter {
private String annotationClass;
@Override
public void setProperties(Properties properties) {
super.setProperties(properties);
// Read plugin-specific config:
annotationClass = properties.getProperty("annotationClass",
"org.springframework.stereotype.Repository");
}
/** Called once; return false to disable the plugin and skip validation. */
@Override
public boolean validate(List warnings) {
if (annotationClass == null || annotationClass.isBlank()) {
warnings.add("RepositoryAnnotationPlugin: annotationClass property is required");
return false;
}
return true;
}
/** Called for each generated mapper interface. */
@Override
public boolean clientGenerated(Interface interfaze, IntrospectedTable introspectedTable) {
// Add import and annotation
interfaze.addImportedType(
new org.mybatis.generator.api.dom.java.FullyQualifiedJavaType(annotationClass));
interfaze.addAnnotation("@" + annotationClass.substring(annotationClass.lastIndexOf('.') + 1));
return true; // true = keep generated artifact; false = discard it
}
/** Called after each base record (model) class is generated. */
@Override
public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass,
IntrospectedTable introspectedTable) {
// You can manipulate the DOM of the class here – add methods, fields, imports, etc.
return true;
}
}
```
```xml
```
--------------------------------
### MyBatis3Kotlin Context Configuration
Source: https://context7.com/mybatis/generator/llms.txt
Configure a context for MyBatis3Kotlin, which generates Kotlin code with Dynamic SQL. This example includes JDBC connection details and specifies Kotlin model and client generator paths.
```xml
```
--------------------------------
### SQLProvider ApplyWhere Method Logic
Source: https://github.com/mybatis/generator/blob/master/core/mybatis-generator-core/src/main/resources/org/mybatis/generator/runtime/mybatis3/javamapper/elements/sqlprovider/ApplyWhereMethod.txt
This code forms the core logic for the 'applyWhere' method in a generated SQL provider. It iterates through example criteria and builds a dynamic WHERE clause string. Use this when generating dynamic SQL queries based on complex filtering criteria.
```Java
if (example == null) {
return;
}
String parmPhrase1;
String parmPhrase1_th;
String parmPhrase2;
String parmPhrase2_th;
String parmPhrase3;
String parmPhrase3_th;
if (includeExamplePhrase) {
parmPhrase1 = "%s #{example.oredCriteria[%d].allCriteria[%d].value}";
parmPhrase1_th = "%s #{example.oredCriteria[%d].allCriteria[%d].value,typeHandler=%s}";
parmPhrase2 = "%s #{example.oredCriteria[%d].allCriteria[%d].value} and #{example.oredCriteria[%d].criteria[%d].secondValue}";
parmPhrase2_th = "%s #{example.oredCriteria[%d].allCriteria[%d].value,typeHandler=%s} and #{example.oredCriteria[%d].criteria[%d].secondValue,typeHandler=%s}";
parmPhrase3 = "#{example.example.oredCriteria[%d].allCriteria[%d].value[%d]}";
parmPhrase3_th = "#{example.oredCriteria[%d].allCriteria[%d].value[%d],typeHandler=%s}";
} else {
parmPhrase1 = "%s #{oredCriteria[%d].allCriteria[%d].value}";
parmPhrase1_th = "%s #{oredCriteria[%d].allCriteria[%d].value,typeHandler=%s}";
parmPhrase2 = "%s #{oredCriteria[%d].allCriteria[%d].value} and #{oredCriteria[%d].criteria[%d].secondValue}";
parmPhrase2_th = "%s #{oredCriteria[%d].allCriteria[%d].value,typeHandler=%s} and #{oredCriteria[%d].criteria[%d].secondValue,typeHandler=%s}";
parmPhrase3 = "#{oredCriteria[%d].allCriteria[%d].value[%d]}";
parmPhrase3_th = "#{oredCriteria[%d].allCriteria[%d].value[%d],typeHandler=%s}";
}
StringBuilder sb = new StringBuilder();
List oredCriteria = example.getOredCriteria();
boolean firstCriteria = true;
for (int i = 0; i < oredCriteria.size(); i++) {
Criteria criteria = oredCriteria.get(i);
if (criteria.isValid()) {
if (firstCriteria) {
firstCriteria = false;
} else {
sb.append(" or ");
}
sb.append('(');
List criterions = criteria.getAllCriteria();
boolean firstCriterion = true;
for (int j = 0; j < criterions.size(); j++) {
Criterion criterion = criterions.get(j);
if (firstCriterion) {
firstCriterion = false;
} else {
sb.append(" and ");
}
if (criterion.isNoValue()) {
sb.append(criterion.getCondition());
} else if (criterion.isSingleValue()) {
if (criterion.getTypeHandler() == null) {
sb.append(String.format(parmPhrase1, criterion.getCondition(), i, j));
} else {
sb.append(String.format(parmPhrase1_th, criterion.getCondition(), i, j,criterion.getTypeHandler()));
}
} else if (criterion.isBetweenValue()) {
if (criterion.getTypeHandler() == null) {
sb.append(String.format(parmPhrase2, criterion.getCondition(), i, j, i, j));
} else {
sb.append(String.format(parmPhrase2_th, criterion.getCondition(), i, j, criterion.getTypeHandler(), i, j, criterion.getTypeHandler()));
}
} else if (criterion.isListValue()) {
sb.append(criterion.getCondition());
sb.append(" (");
List> listItems = (List>) criterion.getValue();
boolean comma = false;
for (int k = 0; k < listItems.size(); k++) {
if (comma) {
sb.append(", ");
} else {
comma = true;
}
if (criterion.getTypeHandler() == null) {
sb.append(String.format(parmPhrase3, i, j, k));
} else {
sb.append(String.format(parmPhrase3_th, i, j, k, criterion.getTypeHandler()));
}
}
sb.append(')');
}
}
sb.append(')');
}
}
if (sb.length() > 0) {
sql.WHERE(sb.toString());
}
```
--------------------------------
### Parse MyBatis Generator XML Configuration with Properties
Source: https://context7.com/mybatis/generator/llms.txt
Use ConfigurationParser to convert an XML configuration file into a Configuration object. This example demonstrates parsing from a classpath resource and providing extra properties for placeholder substitution.
```java
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.XMLParserException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
// Pass Maven/Ant project properties as extra substitution values
Properties extraProps = new Properties();
extraProps.setProperty("database.url", "jdbc:mysql://localhost:3306/mydb");
ConfigurationParser cp = new ConfigurationParser(extraProps);
// Parse from classpath resource
try (InputStream is = MBGRunner.class.getResourceAsStream("/generatorConfig.xml")) {
Configuration config = cp.parseConfiguration(is);
// Warnings (e.g., unknown properties) – not fatal
cp.getWarnings().forEach(System.err::println);
System.out.println("Contexts: " + config.getContexts().size());
} catch (IOException | XMLParserException e) {
// XMLParserException carries a list of individual parse errors
if (e instanceof XMLParserException xpe) {
xpe.getExtraMessages().forEach(System.err::println);
}
throw e;
}
```
--------------------------------
### MyBatis Generator XML Configuration
Source: https://context7.com/mybatis/generator/llms.txt
This is a comprehensive example of an MBG XML configuration file. It includes settings for database connection, target runtime, model generation, mapper generation, plugins, and table-specific overrides. Ensure the JDBC driver JAR is accessible and properties like database credentials are set correctly.
```xml
```
--------------------------------
### MyBatis Generator Ant Task Example
Source: https://github.com/mybatis/generator/blob/master/eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/usingAnt.html
This Ant build file demonstrates how to use the integrated 'mybatis.generate' task. It first converts a workspace resource path to an absolute path using 'eclipse.convertPath' and then invokes the MyBatis Generator with the configuration file.
```xml
```
--------------------------------
### Maven Plugin Configuration for MyBatis Generator
Source: https://context7.com/mybatis/generator/llms.txt
Integrate MyBatis Generator into your Maven build process by configuring the `mybatis-generator-maven-plugin` in your `pom.xml`. This example shows how to specify the configuration file, enable overwriting, and include compile-scope dependencies.
```xml
org.mybatis.generator
mybatis-generator-maven-plugin
2.0.1
src/main/resources/generatorConfig.xml
true
true
false
true
user,order
MySQLContext
generate-mybatis-sources
generate
com.mysql
mysql-connector-j
8.0.31
```
--------------------------------
### MyBatis3 (Legacy) Context Configuration
Source: https://context7.com/mybatis/generator/llms.txt
Configure a context for the legacy MyBatis3 runtime, which generates XML mappers and optional annotations. This setup includes configurations for Java model, SQL map, and Java client generators.
```xml
```
--------------------------------
### Ant Build Script for MyBatis Generator
Source: https://github.com/mybatis/generator/blob/master/eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/manualTesting.html
This Ant script configures and runs the MyBatis Generator. It includes tasks for SQL file conversion, database connection setup, and MyBatis Generator execution. Ensure the HSQLDB driver is available on the classpath for the Ant build.
```xml
```
--------------------------------
### Release Core Product and Maven Plugin
Source: https://github.com/mybatis/generator/blob/master/RELEASING.md
Execute Maven release prepare and perform goals to release the core product and Maven plugin. Ensure you are in the 'core' directory.
```shell
cd core
./mvnw release:prepare
./mvnw release:perform
```
--------------------------------
### Publish Core Site
Source: https://github.com/mybatis/generator/blob/master/RELEASING.md
Execute the Maven command to clean, build the site, and publish it via SCM.
```shell
./mvnw clean site scm-publish:publish-scm
```
--------------------------------
### Configure Maven Settings for Release
Source: https://github.com/mybatis/generator/blob/master/RELEASING.md
Ensure your Maven settings.xml includes server configurations for 'gh-pages-scm' and 'central' with necessary credentials for publishing.
```xml
gh-pages-scm
branch
gh-pages
central
[tokenized user name]
[tokenized password]
```
--------------------------------
### Run MyBatis Generator from Command Line
Source: https://context7.com/mybatis/generator/llms.txt
Invoke MyBatis Generator using the bundled JAR file. This shows basic usage and how to specify configuration files, contexts, tables, and overwrite behavior.
```bash
# Basic usage – generate everything in the config file
java -jar mybatis-generator-core-2.0.1.jar \
-configfile src/main/resources/generatorConfig.xml \
-overwrite
# Verbose output; generate only specific context and tables
java -jar mybatis-generator-core-2.0.1.jar \
-configfile generatorConfig.xml \
-contextids MySQLContext \
-tables user,order \
-verbose \
-overwrite
```
--------------------------------
### Build Eclipse Feature
Source: https://github.com/mybatis/generator/blob/master/RELEASING.md
Navigate to the 'eclipse' directory and build the feature using Maven, applying the 'release-composite' profile.
```shell
cd eclipse
./mvnw clean verify -Prelease-composite
```
--------------------------------
### Copyright Header for New Files
Source: https://github.com/mybatis/generator/blob/master/CONTRIBUTING.md
All new files must include this copyright and license header. Ensure the year is updated accordingly.
```java
/*
* Copyright [year] the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
```
--------------------------------
### Build MyBatis Generator Eclipse Feature with Maven
Source: https://github.com/mybatis/generator/blob/master/eclipse/README.md
Use Maven wrapper commands to build the project. The first command ensures the build works, while the second prepares a new version for publishing.
```shell
./mvnw clean integration-test
```
```shell
./mvnw -Prelease-composite clean integration-test
```
--------------------------------
### MyBatisGenerator - generateAndWrite() and generateOnly()
Source: https://context7.com/mybatis/generator/llms.txt
Demonstrates how to use the MyBatisGenerator class to generate MyBatis artifacts. It shows both writing files to disk and generating them in memory.
```APIDOC
## MyBatisGenerator - generateAndWrite() and generateOnly()
### Description
This section details the usage of the `MyBatisGenerator` class for generating MyBatis artifacts. It covers methods for writing generated files to disk (`generateAndWrite()`) and for generating files only in memory (`generateOnly()`), allowing for inspection of the results.
### Class
`org.mybatis.generator.api.MyBatisGenerator`
### Methods
- `generateAndWrite()`: Generates code and writes it to the file system.
- `generateOnly()`: Generates code in memory without writing to the file system.
### Usage Example (Java)
```java
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class MBGRunner {
public static void main(String[] args) throws Exception {
List warnings = new ArrayList<>();
// 1. Parse the XML configuration
ConfigurationParser cp = new ConfigurationParser();
Configuration config = cp.parseConfiguration(new File("src/main/resources/generatorConfig.xml"));
warnings.addAll(cp.getWarnings());
// 2. Build the generator (overwrite existing Java files, enable Java file merging)
MyBatisGenerator generator = new MyBatisGenerator.Builder()
.withConfiguration(config)
.withShellCallback(new DefaultShellCallback()) // resolves target directories
.withOverwriteEnabled(true) // overwrite existing files on collision
.withJavaFileMergeEnabled(false) // set true to lexically merge Java files
.withContextIds(Set.of("MySQLContext")) // run only this context (empty = all)
.withFullyQualifiedTableNames(Set.of("user", "order")) // empty = all tables in config
.build();
// 3a. Generate AND write to disk
warnings.addAll(generator.generateAndWrite());
// 3b. OR generate in-memory only and inspect results
// warnings.addAll(generator.generateOnly());
// generator.getGeneratedJavaFiles().forEach(f -> System.out.println(f.getFileName()));
// generator.getGeneratedXmlFiles().forEach(f -> System.out.println(f.getFileName()));
warnings.forEach(System.out::println);
}
}
```
### Inspecting Generated Files (after `generateOnly()`)
- `getGeneratedJavaFiles()`
- `getGeneratedXmlFiles()`
- `getGeneratedKotlinFiles()`
- `getGeneratedGenericFiles()`
```
--------------------------------
### Copy Generated Site to Update Repo
Source: https://github.com/mybatis/generator/blob/master/RELEASING.md
Copy the generated P2 composite repository from the target directory to your local clone of the update site repository.
```shell
cd org.mybatis.generator.eclipse.site/target/p2-composite-repo
cp -R . ~/git/GitHub/jeffgbutler/mybatis-generator-update-site
```
--------------------------------
### ConfigurationParser - Parsing XML Configuration
Source: https://context7.com/mybatis/generator/llms.txt
Explains how to use the ConfigurationParser class to parse MyBatis Generator XML configuration files into a Configuration object.
```APIDOC
## ConfigurationParser - Parsing XML Configuration
### Description
The `ConfigurationParser` class is used to convert an XML configuration file into a `Configuration` object. It can parse from a `File`, `InputStream`, or `Reader`. An optional `Properties` object can be provided for placeholder substitution.
### Class
`org.mybatis.generator.config.xml.ConfigurationParser`
### Constructor
- `ConfigurationParser(Properties extraProperties)`: Initializes the parser with extra properties for substitution.
### Method
- `parseConfiguration(File file)`: Parses the configuration from a file.
- `parseConfiguration(InputStream inputStream)`: Parses the configuration from an input stream.
- `getWarnings()`: Retrieves a list of warnings encountered during parsing.
### Usage Example (Java)
```java
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.XMLParserException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
// Pass Maven/Ant project properties as extra substitution values
Properties extraProps = new Properties();
extraProps.setProperty("database.url", "jdbc:mysql://localhost:3306/mydb");
ConfigurationParser cp = new ConfigurationParser(extraProps);
// Parse from classpath resource
try (InputStream is = MBGRunner.class.getResourceAsStream("/generatorConfig.xml")) {
Configuration config = cp.parseConfiguration(is);
// Warnings (e.g., unknown properties) – not fatal
cp.getWarnings().forEach(System.err::println);
System.out.println("Contexts: " + config.getContexts().size());
} catch (IOException | XMLParserException e) {
// XMLParserException carries a list of individual parse errors
if (e instanceof XMLParserException xpe) {
xpe.getExtraMessages().forEach(System.err::println);
}
throw e;
}
```
```
--------------------------------
### Querying P2 Repository with OSGi Console
Source: https://github.com/mybatis/generator/blob/master/eclipse/releng/README.md
Use this command in the OSGi console to query a P2 repository for features that bundle a specific artifact. This helps in identifying where dependencies are located within the Eclipse update site.
```shell
ss p2.console
```
```shell
start <>
```
```shell
provlquery http://download.eclipse.org/releases/2024-09 "select(parent | parent.properties['org.eclipse.equinox.p2.type.group'] == true && parent.requirements.exists(rc | everything.exists(iu | iu.id == 'org.apache.commons.commons-logging' && iu ~= rc)))" true
```
--------------------------------
### MyBatis3DynamicSql Context Configuration
Source: https://context7.com/mybatis/generator/llms.txt
Configure a context for MyBatis3DynamicSql, the default and recommended runtime for generating type-safe Dynamic SQL mappers. Specify model and client generator packages and target projects.
```xml
```
--------------------------------
### Dry Run Site Publishing
Source: https://github.com/mybatis/generator/blob/master/RELEASING.md
Perform a dry run of the site publishing process to preview what will be published without actually deploying.
```shell
./mvnw clean site scm-publish:publish-scm -Dscmpublish.dryRun=true
```
--------------------------------
### Configure Table Mappings with XML
Source: https://context7.com/mybatis/generator/llms.txt
Use the `` element to customize how a database table is mapped to Java objects. Supports aliases, generated keys, column overrides, ignored columns, and renaming rules.
```xml
```
--------------------------------
### Clone and Branch Update Site Repo
Source: https://github.com/mybatis/generator/blob/master/RELEASING.md
Clone the mybatis-generator-update-site repository and create a new branch for the release. Replace 'mybatis-generator-2.0.0' with the desired version.
```shell
git clone git@github.com:jeffgbutler/mybatis-generator-update-site.git
cd mybatis-generator-update-site
git switch -c mybatis-generator-2.0.0
```
--------------------------------
### Running MyBatis Generator Maven Goal
Source: https://context7.com/mybatis/generator/llms.txt
Execute the MyBatis Generator Maven goal to generate sources. You can also skip generation using a Maven property.
```bash
# Run standalone without full build
mvn mybatis-generator:generate
```
```bash
# Skip generation
mvn mybatis-generator:generate -Dmybatis.generator.skip=true
```
--------------------------------
### Built-in EqualsHashCodePlugin Configuration
Source: https://context7.com/mybatis/generator/llms.txt
Adds equals() and hashCode() methods to model classes. Set 'useEqualsHashCodeFromRoot' to true to call super.equals/hashCode from a root class.
```xml
```
--------------------------------
### Enable Java File Merging with Standalone MBG
Source: https://context7.com/mybatis/generator/llms.txt
Use this command to run the MyBatis Generator core JAR, enabling lexical merging of newly generated Java files with existing ones. Ensure `generatorConfig.xml` is correctly configured.
```bash
java -jar mybatis-generator-core-2.0.1.jar \
-configfile generatorConfig.xml \
-javaMergeEnabled \
-overwrite
```
--------------------------------
### Checkout Release Tag for Eclipse Feature
Source: https://github.com/mybatis/generator/blob/master/RELEASING.md
Clone the main mybatis-generator repository and checkout the specific release tag for building the Eclipse feature.
```shell
git clone https://github.com/mybatis/generator.git
cd generator
git checkout mybatis-generator-2.0.0
```
--------------------------------
### Implement ProgressCallback for Generation Monitoring
Source: https://context7.com/mybatis/generator/llms.txt
Implement the ProgressCallback interface to receive lifecycle notifications during the generation process. This is useful for IDE integrations or custom logging. Throw InterruptedException in checkCancel() to abort generation.
```java
import org.mybatis.generator.api.ProgressCallback;
public class LoggingProgressCallback implements ProgressCallback {
@Override
public void introspectionStarted(int totalTasks) {
System.out.printf("Starting introspection: %d table(s)%n", totalTasks);
}
@Override
public void generationStarted(int totalTasks) {
System.out.printf("Starting generation: %d task(s)%n", totalTasks);
}
@Override
public void saveStarted(int totalTasks) {
System.out.printf("Writing %d file(s) to disk%n", totalTasks);
}
@Override
public void startTask(String taskName) {
System.out.println(" -> " + taskName);
}
@Override
public void done() {
System.out.println("Generation complete.");
}
/** Throw InterruptedException here to cancel the generation mid-run. */
@Override
public void checkCancel() throws InterruptedException {
if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException("Cancelled by user");
}
}
}
// Usage:
MyBatisGenerator generator = new MyBatisGenerator.Builder()
.withConfiguration(config)
.withProgressCallback(new LoggingProgressCallback())
.build();
generator.generateAndWrite();
```
--------------------------------
### Reset Maven Sites Directory
Source: https://github.com/mybatis/generator/blob/master/RELEASING.md
If encountering issues with the site publishing process, remove the local Maven sites directory to clear potential stale data.
```shell
sudo rm -r ~/maven-sites
```
--------------------------------
### Built-in FluentBuilderMethodsPlugin
Source: https://context7.com/mybatis/generator/llms.txt
Adds a fluent builder pattern implementation to every generated model class.
```xml
```
--------------------------------
### Disable Tycho Caching for Release
Source: https://github.com/mybatis/generator/blob/master/RELEASING.md
Attempt to resolve Tycho caching issues by cleaning and verifying with the '-U' flag to force updates.
```shell
./mvnw clean verify -Prelease-composite -U
```
--------------------------------
### Built-in ToStringPlugin
Source: https://context7.com/mybatis/generator/llms.txt
Adds a toString() method to every generated model class.
```xml
```
--------------------------------
### MyBatis Generator Configuration XML
Source: https://github.com/mybatis/generator/blob/master/eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/manualTesting.html
This XML configuration defines multiple contexts for generating MyBatis artifacts, including model, SQL map, and client generators. It specifies target packages and projects for different generation scenarios.
```xml
```
--------------------------------
### Specify Root Interface for DAO Generator
Source: https://github.com/mybatis/generator/blob/master/core/mybatis-generator-core/doc/ReleaseNotes.txt
Define the root interface for generated DAO interfaces by setting the 'rootInterface' property on the element. The validity of the specified interface is not checked.
```xml
```