mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
feat: 拆分APT模块, 优化APT配置说明
This commit is contained in:
parent
33dc9cc594
commit
12260fce53
@ -29,8 +29,18 @@ Maven示例:
|
|||||||
<artifactId>mybatis-flex-core</artifactId>
|
<artifactId>mybatis-flex-core</artifactId>
|
||||||
<version>1.2.0</version>
|
<version>1.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
|
<version>1.2.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> 如果配置了annotationProcessorPaths,此处可以省略mybatis-flex-processor的依赖
|
||||||
|
>
|
||||||
|
> 参考:[APT 设置章节](../others/apt.md)
|
||||||
|
|
||||||
Gradle示例:
|
Gradle示例:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
# Maven 依赖
|
# Maven 依赖
|
||||||
|
|
||||||
> 以下的 xml maven 依赖示例中,可能并非最新的 Mybatis-Flex 版本,请自行查看最新版本,并修改版本号。
|
> 以下的 xml maven 依赖示例中,可能并非最新的 Mybatis-Flex 版本,请自行查看最新版本,并修改版本号。
|
||||||
|
>
|
||||||
|
> 建议配置 annotationProcessorPaths,那么可以省略mybatis-flex-processor的依赖
|
||||||
|
>
|
||||||
|
|
||||||
|
|
||||||
1、只用到了 Mybatis,没用到 Spring 的场景:
|
1、只用到了 Mybatis,没用到 Spring 的场景:
|
||||||
@ -11,6 +14,12 @@
|
|||||||
<artifactId>mybatis-flex-core</artifactId>
|
<artifactId>mybatis-flex-core</artifactId>
|
||||||
<version>1.2.0</version>
|
<version>1.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
|
<version>1.2.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
2、用到了 Spring 的场景
|
2、用到了 Spring 的场景
|
||||||
@ -21,6 +30,12 @@
|
|||||||
<artifactId>mybatis-flex-spring</artifactId>
|
<artifactId>mybatis-flex-spring</artifactId>
|
||||||
<version>1.2.0</version>
|
<version>1.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
|
<version>1.2.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
``````
|
``````
|
||||||
|
|
||||||
3、用到了 Spring Boot 的场景
|
3、用到了 Spring Boot 的场景
|
||||||
@ -31,4 +46,34 @@
|
|||||||
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
|
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
|
||||||
<version>1.2.0</version>
|
<version>1.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
<dependency>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
|
<version>1.2.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
4. 配置 annotationProcessor
|
||||||
|
|
||||||
|
`mybatis-flex-processor`提供APT服务,可以配置到annotationProcessorPaths,配置后,无需在依赖中声明`mybatis-flex-processor`依赖。
|
||||||
|
|
||||||
|
参考:[APT 设置-和 Lombok、Mapstruct 整合](../others/apt.md)
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
|
<version>1.2.0</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
```
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,25 @@ Mybatis-Flex 使用了 APT(Annotation Processing Tool)技术,在项目编
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
> 从1.1.9版本开始,APT默认不生成 Mapper 类文件。如需开启,参考下方配置选项。
|
||||||
|
|
||||||
|
## 配置文件和选项
|
||||||
|
|
||||||
|
要对Mybatis-Flex 的APT细节选项进行配置,你需要在`resources`目录下创建名为`mybatis-flex.properties`的文件。
|
||||||
|
|
||||||
|
支持的配置选项如下:
|
||||||
|
|
||||||
|
| 属性名 | 含义 | 约束 | 默认值 |
|
||||||
|
| ------------------------------- | ------------------------ | -------------------------------------------------------- | ------------------------------------ |
|
||||||
|
| processor.enable | 全局启用apt开关 | true/false | true |
|
||||||
|
| processor.mappersGenerateEnable | 开启 Mapper 自动生成 | true/false | false |
|
||||||
|
| processor.genPath | APT 代码生成路径 | 合法的绝对或相对路径 | target/generated-sources/annotations |
|
||||||
|
| processor.tablesPackage | Tables 类名 | 合法的包名 | ${entityPackage}.table |
|
||||||
|
| processor.tablesClassName | Tables 类名 | 合法的类名 | Tables |
|
||||||
|
| processor.baseMapperClass | 自定义 Mapper 的父类 | 全路径类名 | com.mybatisflex.core.BaseMapper |
|
||||||
|
| processor.mappersPackage | 自定义 Mapper 生成的包名 | 合法的包名 | ${entityPackage}.mapper |
|
||||||
|
| processor.tablesNameStyle | 生成辅助类的字段风格 | upperCase, lowerCase<br />upperCamelCase, lowerCamelCase | upperCase |
|
||||||
|
| processor.entity.ignoreSuffixes | 过滤 Entity 后缀 | string | - |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -144,7 +163,7 @@ processor.baseMapperClass=com.domain.mapper.MyBaseMapper
|
|||||||
</path>
|
</path>
|
||||||
<path>
|
<path>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<artifactId>mybatis-flex-annotation</artifactId>
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
<version>${mybatis-flex.version}</version>
|
<version>${mybatis-flex.version}</version>
|
||||||
</path>
|
</path>
|
||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
||||||
@ -159,7 +178,7 @@ processor.baseMapperClass=com.domain.mapper.MyBaseMapper
|
|||||||
```
|
```
|
||||||
dependencies {
|
dependencies {
|
||||||
...
|
...
|
||||||
annotationProcessor 'com.mybatis-flex:mybatis-flex-annotation:1.2.0'
|
annotationProcessor 'com.mybatis-flex:mybatis-flex-processor:1.2.0'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -172,4 +191,3 @@ dependencies {
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -16,42 +16,4 @@
|
|||||||
<artifactId>mybatis</artifactId>
|
<artifactId>mybatis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<includes>
|
|
||||||
<include>**/*</include>
|
|
||||||
</includes>
|
|
||||||
<excludes>
|
|
||||||
<exclude>
|
|
||||||
*.properties
|
|
||||||
</exclude>
|
|
||||||
</excludes>
|
|
||||||
</resource>
|
|
||||||
<resource>
|
|
||||||
<directory>target/generated-sources</directory>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.8.1</version>
|
|
||||||
<configuration>
|
|
||||||
<proc>none</proc>
|
|
||||||
<source>1.8</source>
|
|
||||||
<target>1.8</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
62
mybatis-flex-processor/pom.xml
Normal file
62
mybatis-flex-processor/pom.xml
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>parent</artifactId>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<version>1.2.0</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis</groupId>
|
||||||
|
<artifactId>mybatis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-annotation</artifactId>
|
||||||
|
<version>1.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/*</include>
|
||||||
|
</includes>
|
||||||
|
<excludes>
|
||||||
|
<exclude>
|
||||||
|
*.properties
|
||||||
|
</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>target/generated-sources</directory>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<proc>none</proc>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
@ -30,7 +30,8 @@ import javax.lang.model.type.DeclaredType;
|
|||||||
import javax.lang.model.type.TypeKind;
|
import javax.lang.model.type.TypeKind;
|
||||||
import javax.lang.model.type.TypeMirror;
|
import javax.lang.model.type.TypeMirror;
|
||||||
import javax.lang.model.util.Types;
|
import javax.lang.model.util.Types;
|
||||||
import javax.tools.*;
|
import javax.tools.Diagnostic;
|
||||||
|
import javax.tools.JavaFileObject;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
@ -116,7 +117,7 @@ public class QueryEntityProcessor extends AbstractProcessor {
|
|||||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||||
|
|
||||||
if (!roundEnv.processingOver()) {
|
if (!roundEnv.processingOver()) {
|
||||||
|
System.out.println("mybatis flex processor run start...");
|
||||||
MyBatisFlexProps props = new MyBatisFlexProps(filer);
|
MyBatisFlexProps props = new MyBatisFlexProps(filer);
|
||||||
|
|
||||||
String enable = props.getProperties().getProperty("processor.enable", "");
|
String enable = props.getProperties().getProperty("processor.enable", "");
|
||||||
@ -95,48 +95,4 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
|
||||||
<!-- <resources>-->
|
|
||||||
<!-- <resource>-->
|
|
||||||
<!-- <directory>src/main/resources</directory>-->
|
|
||||||
<!-- <includes>-->
|
|
||||||
<!-- <include>**/*</include>-->
|
|
||||||
<!-- </includes>-->
|
|
||||||
<!-- </resource>-->
|
|
||||||
<!-- </resources>-->
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.8.1</version>
|
|
||||||
<configuration>
|
|
||||||
<source>1.8</source>
|
|
||||||
<target>1.8</target>
|
|
||||||
<annotationProcessorPaths>
|
|
||||||
<!-- <path>-->
|
|
||||||
<!-- <groupId>org.projectlombok</groupId>-->
|
|
||||||
<!-- <artifactId>lombok</artifactId>-->
|
|
||||||
<!-- <version>${org.projectlombok.version}</version>-->
|
|
||||||
<!-- </path>-->
|
|
||||||
<!-- <path>-->
|
|
||||||
<!-- <groupId>org.projectlombok</groupId>-->
|
|
||||||
<!-- <artifactId>lombok-mapstruct-binding</artifactId>-->
|
|
||||||
<!-- <version>${lombok-mapstruct-binding.version}</version>-->
|
|
||||||
<!-- </path>-->
|
|
||||||
<!-- <path>-->
|
|
||||||
<!-- <groupId>org.mapstruct</groupId>-->
|
|
||||||
<!-- <artifactId>mapstruct-processor</artifactId>-->
|
|
||||||
<!-- <version>${org.mapstruct.version}</version>-->
|
|
||||||
<!-- </path>-->
|
|
||||||
<path>
|
|
||||||
<groupId>com.mybatis-flex</groupId>
|
|
||||||
<artifactId>mybatis-flex-annotation</artifactId>
|
|
||||||
<version>1.2.0</version>
|
|
||||||
</path>
|
|
||||||
</annotationProcessorPaths>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
<artifactId>mybatis-flex-test</artifactId>
|
<artifactId>mybatis-flex-test</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>mybatis-flex-native-test</module>
|
<module>mybatis-flex-native-test</module>
|
||||||
<module>mybatis-flex-spring-test</module>
|
<module>mybatis-flex-spring-test</module>
|
||||||
@ -23,4 +23,47 @@
|
|||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<!-- <resources>-->
|
||||||
|
<!-- <resource>-->
|
||||||
|
<!-- <directory>src/main/resources</directory>-->
|
||||||
|
<!-- <includes>-->
|
||||||
|
<!-- <include>**/*</include>-->
|
||||||
|
<!-- </includes>-->
|
||||||
|
<!-- </resource>-->
|
||||||
|
<!-- </resources>-->
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<!-- <path>-->
|
||||||
|
<!-- <groupId>org.projectlombok</groupId>-->
|
||||||
|
<!-- <artifactId>lombok</artifactId>-->
|
||||||
|
<!-- <version>${org.projectlombok.version}</version>-->
|
||||||
|
<!-- </path>-->
|
||||||
|
<!-- <path>-->
|
||||||
|
<!-- <groupId>org.projectlombok</groupId>-->
|
||||||
|
<!-- <artifactId>lombok-mapstruct-binding</artifactId>-->
|
||||||
|
<!-- <version>${lombok-mapstruct-binding.version}</version>-->
|
||||||
|
<!-- </path>-->
|
||||||
|
<!-- <path>-->
|
||||||
|
<!-- <groupId>org.mapstruct</groupId>-->
|
||||||
|
<!-- <artifactId>mapstruct-processor</artifactId>-->
|
||||||
|
<!-- <version>${org.mapstruct.version}</version>-->
|
||||||
|
<!-- </path>-->
|
||||||
|
<path>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
|
<version>1.2.0</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
1
pom.xml
1
pom.xml
@ -47,6 +47,7 @@
|
|||||||
<module>mybatis-flex-spring-boot-starter</module>
|
<module>mybatis-flex-spring-boot-starter</module>
|
||||||
<module>mybatis-flex-solon-plugin</module>
|
<module>mybatis-flex-solon-plugin</module>
|
||||||
<module>mybatis-flex-test</module>
|
<module>mybatis-flex-test</module>
|
||||||
|
<module>mybatis-flex-processor</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user