Skip to content

Commit

Permalink
使用kapt执行Spring Boot配置处理器
Browse files Browse the repository at this point in the history
  • Loading branch information
kosaka-bun committed Dec 28, 2024
1 parent bbc9e7f commit bea9b0b
Show file tree
Hide file tree
Showing 44 changed files with 393 additions and 415 deletions.
20 changes: 15 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
`maven-publish`
alias(libs.plugins.dependency.management)
alias(libs.plugins.kotlin) apply false
alias(libs.plugins.kotlin.kapt)
/*
* Lombok Kotlin compiler plugin is an experimental feature.
* See: https://kotlinlang.org/docs/components-stability.html.
Expand All @@ -26,6 +27,7 @@ subprojects {
apply(plugin = "maven-publish")
apply(plugin = "io.spring.dependency-management")
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "org.jetbrains.kotlin.kapt")
apply(plugin = "org.jetbrains.kotlin.plugin.lombok")

val libs = rootProject.libs
Expand All @@ -45,7 +47,7 @@ subprojects {
}

dependencies {
kotlin(rootProject)
kotlin(project)
//仅用于避免libs.versions.toml中产生version变量未使用的提示
libs.versions.kotlin.coroutines
libs.lombok.let {
Expand All @@ -62,16 +64,20 @@ subprojects {
compileJava {
options.run {
encoding = StandardCharsets.UTF_8.name()
compilerArgs.run {
add("-parameters")
}
val compilerArgs = compilerArgs as MutableCollection<String>
compilerArgs += listOf(
"-parameters"
)
}
}

withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs += "-Xjsr305=strict"
jvmTarget = java.sourceCompatibility.toString()
freeCompilerArgs += listOf(
"-Xjsr305=strict",
"-Xjvm-default=all"
)
}
}

Expand All @@ -85,6 +91,10 @@ subprojects {
mavenLocal()
}
}

kapt {
keepJavacAnnotationProcessors = true
}
}

defineCheckVersionOfProjectsTask()
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.gradle.api.internal.catalog.VersionModel

@Suppress("UNCHECKED_CAST")
fun Project.libVersions(): Map<String, VersionModel> {
val libs = extensions.getByName("libs")
val libs = rootProject.extensions.getByName("libs")
val versions = libs.javaClass.getDeclaredMethod("getVersions").invoke(libs)
val catalog = versions.javaClass.superclass.getDeclaredField("config").run {
isAccessible = true
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ lombok = "1.18.26"

[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
kotlin-lombok = { id = "org.jetbrains.kotlin.plugin.lombok", version.ref = "kotlin" }
kotlin-spring = { id = "org.jetbrains.kotlin.plugin.spring", version.ref = "kotlin" }
kotlin-jpa = { id = "org.jetbrains.kotlin.plugin.spring", version.ref = "kotlin" }
Expand Down
5 changes: 1 addition & 4 deletions qqrobot-spring-boot-starter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ dependencies {
compileOnly(libs.mirai.console.compiler.annotations)
implementation("com.github.houbb:opencc4j:1.6.0")
implementation("com.h2database:h2:2.1.214")
"org.springframework.boot:spring-boot-configuration-processor".let {
implementation(it)
annotationProcessor(it)
}
kapt("org.springframework.boot:spring-boot-configuration-processor")
}

tasks {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package de.honoka.qqrobot.framework

enum class FrameworkEnum {

TESTER,

MIRAI,

ONEBOT
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package de.honoka.qqrobot.framework.config

import net.mamoe.mirai.utils.BotConfiguration.MiraiProtocol
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration

@EnableConfigurationProperties(MiraiProperties::class)
@ComponentScan("de.honoka.qqrobot.framework.impl.mirai")
@ConditionalOnProperty(prefix = "honoka.qqrobot.framework", name = ["impl"], havingValue = "mirai")
@Configuration
class MiraiConfig

@ConfigurationProperties("honoka.qqrobot.framework.mirai")
data class MiraiProperties(

/**
* 平台输出与依赖文件的存放目录
*/
var workDirectory: String = "/qqrobot/mirai",

/**
* 是否转移日志到文件中
*/
var redirectLogs: Boolean = false,

/**
* 采用的登录协议
*/
var protocol: MiraiProtocol = MiraiProtocol.ANDROID_PAD
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
package de.honoka.qqrobot.framework.config

import de.honoka.qqrobot.framework.config.property.OnebotProperties
import de.honoka.sdk.util.file.FileUtils
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import kotlin.io.path.Path

@EnableConfigurationProperties(OnebotProperties::class)
@ComponentScan("de.honoka.qqrobot.framework.impl.onebot")
@ConditionalOnProperty(prefix = "honoka.qqrobot.framework", name = ["impl"], havingValue = "onebot")
@Configuration
class OnebotConfig
class OnebotConfig

@ConfigurationProperties("honoka.qqrobot.framework.onebot")
data class OnebotProperties(

var host: String? = null,

var httpPort: Int? = null,

var websocketPort: Int? = null,

var fileReceiverPort: Int? = null,

/**
* 定义缓存文件所存放的目录。
*
* 发送图片或文件前,需要先将InputStream中的数据写出到文件中,才能被OneBot服务使用。
*/
var cachePath: String = Path(FileUtils.getMainClasspath(), "cache").run {
normalize().toString()
}
) {

val urlPrefix: String
get() = "http://$host:$httpPort"

val websocketUrlPrefix: String
get() = "ws://$host:$websocketPort"

val fileReceiverUrlPrefix: String
get() = "http://$host:$fileReceiverPort"

val imagePath: String
get() = Path(cachePath, "image").toString()

val fileToUploadPath: String
get() = Path(cachePath, "fileToUpload").toString()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package de.honoka.qqrobot.framework.config

import de.honoka.sdk.util.file.FileUtils
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import kotlin.io.path.Path

@EnableConfigurationProperties(TesterProperties::class)
@ComponentScan("de.honoka.qqrobot.framework.impl.tester")
@ConditionalOnProperty(
prefix = "honoka.qqrobot.framework",
name = ["impl"],
havingValue = "tester",
matchIfMissing = true
)
@Configuration
class TesterConfig {

@Value("\${server.port:8080}")
var serverPort = 0

@Value("\${server.servlet.context-path:}")
var contextPath = "/"

val testerUrl: String
get() = "http://localhost:$serverPort$contextPath${TesterProperties.WEB_PREFIX}/index.html"
}

@ConfigurationProperties("honoka.qqrobot.framework.tester")
data class TesterProperties(

var groupNumber: Long = 10000L,

var imagePath: String = run {
Path(FileUtils.getMainClasspath(), "tester-framework", "image").toString()
}
) {

companion object {

const val WEB_PREFIX = "/tester-framework"
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit bea9b0b

Please sign in to comment.