kotlin-orm / ktorm

A lightweight ORM framework for Kotlin with strong-typed SQL DSL and sequence APIs.
https://www.ktorm.org
Apache License 2.0
2.09k stars 148 forks source link

请问ktorm的ksp的文档有吗 #578

Open nanxia990105 opened 1 week ago

vincentlauvlwj commented 1 week ago

https://github.com/kotlin-orm/ktorm/releases/tag/v4.0.0

nanxia990105 commented 1 week ago

感谢 @vincentlauvlwj

nanxia990105 commented 1 week ago

有两个问题(我不太了解ksp和gradle) 1:在kotlin指定为1.9.25时编译会报错,我认为这应该是ktorm-ksp-compiler-maven-plugin 内部指定的ksp版本原因,当我将kotlin版本修改为1.9.23(与ktorm-ksp-compiler-maven-plugin的ksp的kotlin版本一致)编译通过。当我指定kotlin为1.9.25并且手动引入 ksp1.9.25 也是一样的错误。(请问有什么方向吗) image 这是我的pom文件

 <?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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.wxy</groupId>
    <artifactId>outer</artifactId>
    <version>1.0-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.3.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>21</java.version>
        <hanlp.version>portable-1.8.4</hanlp.version>
        <schild.version>3.5.0</schild.version>
        <ktorm.version>4.1.1</ktorm.version>
        <kotlin.version>1.9.23</kotlin.version>
        <build.herlper.version>3.6.0</build.herlper.version>
    </properties>
    <build>
        <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
        <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <!--ktorm ksp 生成代码-->
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <compilerPlugins>
                                <compilerPlugin>ksp</compilerPlugin>
                            </compilerPlugins>
                            <pluginOptions>
                                <option>ksp:apoption=ktorm.dbNamingStrategy=lower-snake-case</option>
                            </pluginOptions>
                        </configuration>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                        <configuration>
                            <compilerPlugins>
                                <compilerPlugin>ksp</compilerPlugin>
                            </compilerPlugins>
                            <pluginOptions>
                                <option>ksp:apoption=ktorm.dbNamingStrategy=lower-snake-case</option>
                            </pluginOptions>
                        </configuration>
                    </execution>
                </executions>
                <!--ktorm ksp 生成代码-->
                <configuration>
                    <args>
                        <arg>-Xjsr305=strict</arg>
                    </args>
                    <compilerPlugins>
                        <plugin>spring</plugin>
                    </compilerPlugins>
                </configuration>
                <dependencies>
                    <!--allopen-->
                    <dependency>
                        <groupId>org.jetbrains.kotlin</groupId>
                        <artifactId>kotlin-maven-allopen</artifactId>
                        <version>${kotlin.version}</version>
                    </dependency>
                    <!--ktorm ksp 生成代码-->
                    <dependency>
                        <groupId>org.ktorm</groupId>
                        <artifactId>ktorm-ksp-compiler-maven-plugin</artifactId>
                        <version>${ktorm.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <!--生成的代码在IDEA中有提示-->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.basedir}/generated-sources/ksp</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-kotlin</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-reflect</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib</artifactId>
        </dependency>
        <!--mp3转码-->
        <dependency>
            <groupId>ws.schild</groupId>
            <artifactId>jave-core</artifactId>
            <version>${schild.version}</version>
        </dependency>
        <dependency>
            <groupId>ws.schild</groupId>
            <artifactId>jave-nativebin-linux64</artifactId>
            <version>${schild.version}</version>
        </dependency>
        <dependency>
            <groupId>ws.schild</groupId>
            <artifactId>jave-nativebin-win64</artifactId>
            <version>${schild.version}</version>
        </dependency>
        <!--mp3转码结束-->
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!--ktorm-->
        <dependency>
            <groupId>org.ktorm</groupId>
            <artifactId>ktorm-core</artifactId>
            <version>${ktorm.version}</version>
        </dependency>
        <dependency>
            <groupId>org.ktorm</groupId>
            <artifactId>ktorm-support-mysql</artifactId>
            <version>${ktorm.version}</version>
        </dependency>
        <dependency>
            <groupId>org.ktorm</groupId>
            <artifactId>ktorm-jackson</artifactId>
            <version>${ktorm.version}</version>
        </dependency>
        <dependency>
            <groupId>org.ktorm</groupId>
            <artifactId>ktorm-ksp-annotations</artifactId>
            <version>${ktorm.version}</version>
        </dependency>
        <dependency>
            <groupId>org.ktorm</groupId>
            <artifactId>ktorm-ksp-compiler</artifactId>
            <version>${ktorm.version}</version>
            <scope>provided</scope>
        </dependency>

        <!--ktorm-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-test-junit5</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

2:IDEA提示问题(这个与ktorm无关),目前我是使用了build-helper-maven-plugin来指定额外的源代码目录使IDEA有提示,或者IDEA右键 target/generated-source -> Mark Directory As -> Source Root 常规做法应该是如何呢?不知道我这样是否会有额外的副作用。 3:编译的时间略长,目前我是一个文件。时长大约41秒。是否有优化的空间。

image image

vincentlauvlwj commented 1 week ago
  1. 这个明显是 kotlin 版本和 ksp 版本不兼容,只要保证两者版本一致就可以了
  2. build-helper-maven-plugin 可以不需要,生成的源码会自动识别,运行生成之后,点一下 IDEA Maven 插件里面的 reload 就可以,当然你加上这个插件也不会有什么副作用
  3. 性能问题可以提供下项目代码和机器配置,方便排查
nanxia990105 commented 1 week ago

1,2了解 3的问题代码不太方便提供出去, 机器配置 CPU i5-10600kf 4.10GHz 内存 64GB 颗粒与通道不太了解 硬盘 8T stat 机械硬盘

nanxia990105 commented 1 week ago

代码基本是一个简单的springboot 项目 没有多少代码。感觉和 ktorm-springboot-example 差不多