增加了使用gradle构建时的文档说明,并增加了在Kotlin中使用注解处理器的说明。

This commit is contained in:
CloudPlayer 2023-08-08 23:08:28 +08:00
parent 11f0b6dd68
commit d6bff881f6
3 changed files with 147 additions and 1 deletions

82
docs/zh/intro/gradle.md Normal file
View File

@ -0,0 +1,82 @@
# Gradle 依赖
> 以下的 xml gradle 依赖示例中,可能并非最新的 MyBatis-Flex 版本,请自行查看最新版本,并修改版本号。
>
> 建议配置 annotationProcessor那么可以省略mybatis-flex-processor的依赖
>
1、只用到了 MyBatis没用到 Spring 的场景:
**【Kotlin】**
```kotlin
dependencies {
implementation("com.mybatis-flex:mybatis-flex-core:1.5.6")
compileOnly("com.mybatis-flex:mybatis-flex-processor:1.5.6")
}
```
**【Groovy】**
```groovy
dependencies {
implementation 'com.mybatis-flex:mybatis-flex-core:1.5.6'
compileOnly 'com.mybatis-flex:mybatis-flex-processor:1.5.6'
}
```
2、用到了 Spring 的场景
**【Kotlin】**
```kotlin
dependencies {
implementation("com.mybatis-flex:mybatis-flex-spring:1.5.6")
compileOnly("com.mybatis-flex:mybatis-flex-processor:1.5.6")
}
```
**【Groovy】**
```groovy
dependencies {
implementation 'com.mybatis-flex:mybatis-flex-spring:1.5.6'
compileOnly 'com.mybatis-flex:mybatis-flex-processor:1.5.6'
}
```
3、用到了 Spring Boot 的场景
**【Kotlin】**
```kotlin
dependencies {
implementation("com.mybatis-flex:mybatis-flex-spring-boot-starter:1.5.6")
compileOnly("com.mybatis-flex:mybatis-flex-processor:1.5.6")
}
```
**【Groovy】**
```groovy
dependencies {
implementation 'com.mybatis-flex:mybatis-flex-spring-boot-starter:1.5.6'
compileOnly 'com.mybatis-flex:mybatis-flex-processor:1.5.6'
}
```
4. 配置 annotationProcessor
`mybatis-flex-processor`提供APT服务可以配置到annotationProcessorPaths配置后无需在依赖中声明`mybatis-flex-processor`依赖。
参考:[APT 设置-和 Lombok、Mapstruct 整合](../others/apt.md)
> 在Kotlin中使用时请参考[在Kotlin中使用注解处理器](../kotlin/kapt.md)
**【Kotlin】**
```kotlin
dependencies {
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor:1.5.6")
}
```
**【Groovy】**
```groovy
dependencies {
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor:1.5.6'
}
```

View File

@ -60,6 +60,8 @@
参考:[APT 设置-和 Lombok、Mapstruct 整合](../others/apt.md) 参考:[APT 设置-和 Lombok、Mapstruct 整合](../others/apt.md)
> 在Kotlin中使用时请参考[在Kotlin中使用注解处理器](../kotlin/kapt.md)
```xml ```xml
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
@ -76,4 +78,3 @@
</configuration> </configuration>
</plugin> </plugin>
``` ```

63
docs/zh/kotlin/kapt.md Normal file
View File

@ -0,0 +1,63 @@
# 在Kotlin中使用注解处理器
> 在Kotlin中想要使`@Table`等注解生效十分简单。只需要使用kapt即可。
>
## 在Gradle中使用
1. 应用Gradle插件kotlin-kapt
**【Kotlin】**
```kotlin
plugins {
kotlin("kapt") version "1.9.0"
}
```
**【Groovy】**
```groovy
plugins {
id "org.jetbrains.kotlin.kapt" version "1.9.0"
}
```
2. 在 dependencies 块中使用 kapt 配置添加相应的依赖项
**【Kotlin】**
```kotlin
dependencies {
kapt("org.springframework.boot:spring-boot-configuration-processor:1.5.6")
}
```
**【Groovy】**
```groovy
dependencies {
kapt 'org.springframework.boot:spring-boot-configuration-processor:1.5.6'
}
```
## 在Maven中使用
在 compile 之前在 kotlin-maven-plugin 中添加 kapt 目标的执行:
```xml
<execution>
<id>kapt</id>
<goals>
<goal>kapt</goal>
</goals>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-processor</artifactId>
<version>1.5.6</version>
</path>
</annotationProcessorPaths>
</configuration>
</execution>
```
> 关于Kapt更详细的说明请看[Kotlin官网说明](https://book.kotlincn.net/text/kapt.html),或[Kotlin语言中文站](https://www.kotlincn.net/docs/reference/kapt.html)。