!274 gradle文档更新及kapt文档的更新

Merge pull request !274 from CloudPlayer/main
This commit is contained in:
Michael Yang 2023-08-12 12:07:17 +00:00 committed by Gitee
commit c43b5fe549
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 71 additions and 41 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

View File

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

View File

@ -1,10 +1,11 @@
# 在 Kotlin 中使用注解处理器 # 在Kotlin中使用注解处理器
> 在 Kotlin 中想要使 `@Table` 等注解生效十分简单。只需要使用 KAPT 即可。 > 在Kotlin中想要使`@Table`等注解生效十分简单。只需要使用kapt即可。
>
## 在 Gradle 中使用 ## 在Gradle中使用
1、应用 Gradle 插件:`kotlin-kapt` 1. 应用Gradle插件kotlin-kapt
**【Kotlin】** **【Kotlin】**
@ -18,14 +19,12 @@
```groovy ```groovy
plugins { plugins {
id "org.jetbrains.kotlin.kapt" version "1.9.0" id 'org.jetbrains.kotlin.kapt' version '1.9.0'
} }
``` ```
2、在 dependencies 块中使用 KAPT 配置添加相应的依赖项 2. 在 dependencies 块中使用 kapt 配置添加相应的依赖项
**【Kotlin】**
**【Kotlin】**
```kotlin ```kotlin
dependencies { dependencies {
@ -34,17 +33,19 @@ dependencies {
``` ```
**【Groovy】** **【Groovy】**
```groovy ```groovy
dependencies { dependencies {
kapt 'org.springframework.boot:spring-boot-configuration-processor:1.5.6' kapt 'org.springframework.boot:spring-boot-configuration-processor:1.5.6'
} }
``` ```
## 在 Maven 中使用 ## 在Maven中使用
在 compile 之前在 kotlin-maven-plugin 中添加 kapt 目标的执行: 1. 将以下kapt配置插入指定位置。
```xml ```xml
<execution> <execution>
<id>kapt</id> <id>kapt</id>
<goals> <goals>
@ -55,11 +56,52 @@ dependencies {
<path> <path>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-processor</artifactId> <artifactId>mybatis-flex-processor</artifactId>
<version>1.5.7</version> <version>1.5.6</version>
</path> </path>
</annotationProcessorPaths> </annotationProcessorPaths>
</configuration> </configuration>
</execution> </execution>
``` ```
> 关于 KAPT 更详细的说明,请看 [Kotlin 官网说明](https://book.kotlincn.net/text/kapt.html),或 [Kotlin 语言中文站](https://www.kotlincn.net/docs/reference/kapt.html)。 你需要使kapt在compile前工作。将其插入到`kotlin-maven-plugin`中的compile前
然后将compile的时机改为`process-sources`
```xml
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<!--上述代码需插入到此处compile前-->
<execution>
<id>compile</id>
<!--将此处的phase改为process-sources-->
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
```
2. 令kapt在构建前运行
以idea举例
1. 点击maven图标
2. 找到对应项目
3. 点击插件
4. 点击kotlin
5. 右击kotlin:kapt在选项中点击"**构建前执行**"以让kapt能够正确的生成代码。
![](../../assets/images/kapt1.png)
> 关于Kapt更详细的说明请看[Kotlin官网说明](https://book.kotlincn.net/text/kapt.html)
> ,或[Kotlin语言中文站](https://www.kotlincn.net/docs/reference/kapt.html)。