feat: 拆分APT模块, 优化APT配置说明

This commit is contained in:
snow 2023-04-27 11:49:42 +08:00
parent 33dc9cc594
commit 12260fce53
11 changed files with 187 additions and 89 deletions

View File

@ -29,8 +29,18 @@ Maven示例
<artifactId>mybatis-flex-core</artifactId>
<version>1.2.0</version>
</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示例
```groovy

View File

@ -1,6 +1,9 @@
# Maven 依赖
> 以下的 xml maven 依赖示例中,可能并非最新的 Mybatis-Flex 版本,请自行查看最新版本,并修改版本号。
>
> 建议配置 annotationProcessorPaths那么可以省略mybatis-flex-processor的依赖
>
1、只用到了 Mybatis没用到 Spring 的场景:
@ -11,6 +14,12 @@
<artifactId>mybatis-flex-core</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-processor</artifactId>
<version>1.2.0</version>
<scope>provided</scope>
</dependency>
```
2、用到了 Spring 的场景
@ -21,6 +30,12 @@
<artifactId>mybatis-flex-spring</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-processor</artifactId>
<version>1.2.0</version>
<scope>provided</scope>
</dependency>
``````
3、用到了 Spring Boot 的场景
@ -31,4 +46,34 @@
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
<version>1.2.0</version>
</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>
```

View File

@ -5,6 +5,25 @@ Mybatis-Flex 使用了 APTAnnotation Processing Tool技术在项目编
![](../../assets/images/build_idea.png)
> 从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>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-annotation</artifactId>
<artifactId>mybatis-flex-processor</artifactId>
<version>${mybatis-flex.version}</version>
</path>
</annotationProcessorPaths>
@ -159,7 +178,7 @@ processor.baseMapperClass=com.domain.mapper.MyBaseMapper
```
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 {
![](../../assets/images/apt_idea.png)

View File

@ -16,42 +16,4 @@
<artifactId>mybatis</artifactId>
</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>

View 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>

View File

@ -30,7 +30,8 @@ import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Types;
import javax.tools.*;
import javax.tools.Diagnostic;
import javax.tools.JavaFileObject;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
@ -116,7 +117,7 @@ public class QueryEntityProcessor extends AbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
System.out.println("mybatis flex processor run start...");
MyBatisFlexProps props = new MyBatisFlexProps(filer);
String enable = props.getProperties().getProperty("processor.enable", "");

View File

@ -95,48 +95,4 @@
</dependency>
</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>

View File

@ -23,4 +23,47 @@
<maven.compiler.target>8</maven.compiler.target>
</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>

View File

@ -47,6 +47,7 @@
<module>mybatis-flex-spring-boot-starter</module>
<module>mybatis-flex-solon-plugin</module>
<module>mybatis-flex-test</module>
<module>mybatis-flex-processor</module>
</modules>
<properties>