diff --git a/.github/workflows/openapi.yml b/.github/workflows/openapi.yml index 9cc0ba66..a1bac7c5 100644 --- a/.github/workflows/openapi.yml +++ b/.github/workflows/openapi.yml @@ -39,10 +39,10 @@ jobs: major-identifier: "breaking:" minor-identifier: "feature:" - - uses: actions/setup-java@v3 + - uses: actions/setup-java@v4 with: - distribution: zulu - java-version: 17 + distribution: temurin + java-version: 21 # - name: Startup Mongodb # uses: supercharge/mongodb-github-action@1.8.0 @@ -52,11 +52,11 @@ jobs: - name: Remove aliyun maven mirror run: | - sed -i '/maven {/,+2d' build.gradle + sed -i '/maven(url/d' build.gradle.kts - name: Set versions run: | - sed -i "s/^version.*$/version '${{ steps.version.outputs.version }}'/g" build.gradle + sed -i "s/^version.*$/version = \"${{ steps.version.outputs.version }}\"/g" build.gradle.kts sed -i 's/"packageVersion.*,/"packageVersion": "${{ steps.version.outputs.version }}",/g' client-config/cpp.json sed -i 's/"packageVersion.*,/"packageVersion": "${{ steps.version.outputs.version }}",/g' client-config/csharp-netcore.json sed -i 's/"packageVersion.*,/"packageVersion": "${{ steps.version.outputs.version }}",/g' client-config/rust.json diff --git a/Dockerfile b/Dockerfile index 0e3fb809..75f496fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM amazoncorretto:17-alpine as runner +FROM amazoncorretto:21-alpine as runner WORKDIR /app COPY ./build/libs/MaaBackendCenter*.jar /MaaBackendCenter.jar EXPOSE 7000-9000 diff --git a/build.gradle b/build.gradle deleted file mode 100644 index f3269cf0..00000000 --- a/build.gradle +++ /dev/null @@ -1,154 +0,0 @@ -plugins { - id 'java' - id 'org.springframework.boot' version '3.1.5' - id 'io.spring.dependency-management' version '1.1.3' - id 'org.springdoc.openapi-gradle-plugin' version '1.8.0' - id 'org.hidetake.swagger.generator' version '2.19.2' -// id 'org.graalvm.buildtools.native' version '0.9.28' - id 'com.gorylenko.gradle-git-properties' version '2.4.1' - id 'org.jetbrains.kotlin.jvm' version '1.9.22' - id "org.jetbrains.kotlin.plugin.spring" version "1.9.22" - id "org.jetbrains.kotlin.kapt" version "1.9.22" -} - -group 'plus.maa' -version '1.0-SNAPSHOT' - -repositories { - maven { - url 'https://maven.aliyun.com/repository/public/' - } - maven { - url 'https://maven.aliyun.com/repository/spring/' - } - mavenCentral() -} - -ext { - // 统一管理版本号 - hutoolVersion = '5.8.22' - mapstructVersion = '1.5.5.Final' -} - -dependencies { - - kapt 'org.springframework.boot:spring-boot-configuration-processor' - - testImplementation 'io.mockk:mockk:1.13.9' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.springframework.boot:spring-boot-starter-webflux' - implementation 'org.springframework.boot:spring-boot-starter-security' - implementation 'org.springframework.boot:spring-boot-starter-data-redis' - implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' - implementation 'org.springframework.boot:spring-boot-starter-validation' - implementation 'org.springframework.boot:spring-boot-starter-cache' - - //springdoc相关依赖没有被自动管理,必须保留版本号 - implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0' - implementation 'com.github.therapi:therapi-runtime-javadoc:0.13.0' - kapt 'com.github.therapi:therapi-runtime-javadoc-scribe:0.15.0' - - // kotlin - implementation "com.fasterxml.jackson.module:jackson-module-kotlin" - implementation "org.jetbrains.kotlin:kotlin-reflect" - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - - // kotlin-logging - implementation 'io.github.oshai:kotlin-logging-jvm:5.1.0' - - implementation 'com.squareup.okhttp3:okhttp:4.10.0' - implementation 'com.sun.mail:javax.mail:1.6.2' - // 双引号才能使用变量 - implementation "cn.hutool:hutool-extra:$hutoolVersion" - implementation "cn.hutool:hutool-jwt:$hutoolVersion" - implementation "cn.hutool:hutool-dfa:$hutoolVersion" - - // mapstruct - implementation "org.mapstruct:mapstruct:${mapstructVersion}" - kapt "org.mapstruct:mapstruct-processor:${mapstructVersion}" - - implementation 'org.eclipse.jgit:org.eclipse.jgit:6.6.0.202305301015-r' - implementation 'org.eclipse.jgit:org.eclipse.jgit.ssh.apache.agent:6.6.0.202305301015-r' - implementation 'org.freemarker:freemarker:2.3.32' - implementation 'com.github.ben-manes.caffeine:caffeine:3.1.6' - implementation 'com.github.erosb:everit-json-schema:1.14.2' - implementation 'com.google.guava:guava:32.1.1-jre' - implementation 'org.aspectj:aspectjweaver:1.9.19' - implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310' - - swaggerCodegen 'org.openapitools:openapi-generator-cli:6.5.0' - -} - -kapt { - keepJavacAnnotationProcessors = true -} - -test { - useJUnitPlatform() -} - -def swagger_output_dir = "$buildDir/docs" -def swagger_output_name = 'swagger.json' - - -openApi { - apiDocsUrl.set("http://localhost:8848/v3/api-docs") - outputDir.set(file(swagger_output_dir)) - outputFileName.set(swagger_output_name) - waitTimeInSeconds.set(30) -} - -swaggerSources { - def client_dir = "$buildDir/clients" - TsFetch { - inputFile = file("$swagger_output_dir/$swagger_output_name") - code { - language = 'typescript-fetch' - configFile = file('client-config/ts-fetch.json') -// templateDir = file('client-config/typescript-fetch') - rawOptions = ["-e", "mustache"] - outputDir = file("$client_dir/ts-fetch-client") - } - } - CSharp { - inputFile = file("$swagger_output_dir/$swagger_output_name") - code { - language = 'csharp-netcore' - configFile = file('client-config/csharp-netcore.json') - outputDir = file("$client_dir/csharp-client") -// rawOptions = [ -// "--type-mappings", "binary=System.IO.Stream" -// ] - } - } - Cpp { - inputFile = file("$swagger_output_dir/$swagger_output_name") - code { - language = 'cpp-restsdk' - configFile = file('client-config/cpp.json') - outputDir = file("$client_dir/cpp-client") - } - } - Rust { - inputFile = file("$swagger_output_dir/$swagger_output_name") - code { - language = 'rust' - configFile = file('client-config/rust.json') - outputDir = file("$client_dir/rust-client") - } - } -} - -rootProject.afterEvaluate() { - def forkedSpringBootRun = project.tasks.named("forkedSpringBootRun") - forkedSpringBootRun.configure { - doNotTrackState("See https://github.com/springdoc/springdoc-openapi-gradle-plugin/issues/102") - } -} - -gitProperties { - failOnNoGitDirectory = false - keys = ["git.branch", "git.commit.id", "git.commit.id.abbrev", "git.commit.time"] -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..350b48fa --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,159 @@ +import org.hidetake.gradle.swagger.generator.GenerateSwaggerCode +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + java + id("org.springframework.boot") version "3.2.2" + id("io.spring.dependency-management") version "1.1.4" + id("org.springdoc.openapi-gradle-plugin") version "1.8.0" +// id("org.graalvm.buildtools.native") version "0.9.28" + id("org.hidetake.swagger.generator") version "2.19.2" + id("com.gorylenko.gradle-git-properties") version "2.4.1" + + kotlin("jvm") version "1.9.22" + kotlin("plugin.spring") version "1.9.22" + kotlin("kapt") version "1.9.22" +} + +group = "plus.maa" +version = "2.0" + +java { + sourceCompatibility = JavaVersion.VERSION_21 +} + +repositories { + maven(url = "https://maven.aliyun.com/repository/public/") + maven(url = "https://maven.aliyun.com/repository/spring/") + mavenCentral() +} + + +dependencies { + val hutoolVersion = "5.8.26" + val mapstructVersion = "1.5.5.Final" + + kapt("org.springframework.boot:spring-boot-configuration-processor") + + testImplementation("io.mockk:mockk:1.13.9") + testImplementation("org.springframework.boot:spring-boot-starter-test") + + implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.springframework.boot:spring-boot-starter-webflux") + implementation("org.springframework.boot:spring-boot-starter-security") + implementation("org.springframework.boot:spring-boot-starter-data-redis") + implementation("org.springframework.boot:spring-boot-starter-data-mongodb") + implementation("org.springframework.boot:spring-boot-starter-validation") + implementation("org.springframework.boot:spring-boot-starter-cache") + // springdoc 相关依赖没有被自动管理,必须保留版本号, + // springdoc-openapi-starter-webmvc-ui 升级到 2.3.0 以及以上版本会导致 therapi 不兼容 + implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0") + implementation("com.github.therapi:therapi-runtime-javadoc:0.15.0") + kapt("com.github.therapi:therapi-runtime-javadoc-scribe:0.15.0") + + // kotlin + implementation("com.fasterxml.jackson.module:jackson-module-kotlin") + implementation("org.jetbrains.kotlin:kotlin-reflect") + + // kotlin-logging + implementation("io.github.oshai:kotlin-logging-jvm:6.0.3") + + implementation("com.squareup.okhttp3:okhttp:4.12.0") + // hutool 的邮箱工具类依赖 + implementation("com.sun.mail:javax.mail:1.6.2") + implementation("cn.hutool:hutool-extra:$hutoolVersion") + implementation("cn.hutool:hutool-jwt:$hutoolVersion") + implementation("cn.hutool:hutool-dfa:$hutoolVersion") + + // mapstruct + implementation("org.mapstruct:mapstruct:${mapstructVersion}") + kapt("org.mapstruct:mapstruct-processor:${mapstructVersion}") + + implementation("org.eclipse.jgit:org.eclipse.jgit:6.8.0.202311291450-r") + implementation("org.eclipse.jgit:org.eclipse.jgit.ssh.apache.agent:6.8.0.202311291450-r") + implementation("org.freemarker:freemarker:2.3.32") + implementation("com.github.ben-manes.caffeine:caffeine:3.1.8") + implementation("com.github.erosb:everit-json-schema:1.14.4") { + exclude("commons-logging", "commons-logging") + } + implementation("com.google.guava:guava:32.1.3-jre") + implementation("org.aspectj:aspectjweaver:1.9.21") + + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") + + swaggerCodegen("org.openapitools:openapi-generator-cli:7.2.0") + +} + +kapt { + keepJavacAnnotationProcessors = true +} + +tasks.withType { + kotlinOptions { + freeCompilerArgs += "-Xjsr305=strict" + jvmTarget = "21" + } +} + +tasks.withType { + useJUnitPlatform() +} + + +val swaggerOutputDir = layout.buildDirectory.dir("docs") +val swaggerOutputName = "swagger.json" + + +openApi { + apiDocsUrl = "http://localhost:8848/v3/api-docs" + outputDir = swaggerOutputDir + outputFileName = swaggerOutputName + waitTimeInSeconds = 30 +} + +swaggerSources { + val clientDir = layout.buildDirectory.dir("clients").get() + val swaggerOutputFile = swaggerOutputDir.get().file(swaggerOutputName) + create("TsFetch") { + setInputFile(file(swaggerOutputFile)) + code(closureOf { + language = "typescript-fetch" + configFile = file("client-config/ts-fetch.json") +// templateDir = file('client-config/typescript-fetch') + rawOptions = listOf("-e", "mustache") + outputDir = file(clientDir.dir("ts-fetch-client")) + }) + } + create("CSharp") { + setInputFile(file(swaggerOutputFile)) + code(closureOf { + language = "csharp" + configFile = file("client-config/csharp-netcore.json") + outputDir = file(clientDir.dir("csharp-client")) +// rawOptions = listOf("--type-mappings", "binary=System.IO.Stream") + }) + } + create("Cpp") { + setInputFile(file(swaggerOutputFile)) + code(closureOf { + language = "cpp-restsdk" + configFile = file("client-config/cpp.json") + outputDir = file(clientDir.dir("cpp-client")) + }) + } + create("Rust") { + setInputFile(file(swaggerOutputFile)) + code(closureOf { + language = "rust" + configFile = file("client-config/rust.json") + outputDir = file(clientDir.dir("rust-client")) + }) + } +} + + +gitProperties { + failOnNoGitDirectory = false + keys = listOf("git.branch", "git.commit.id", "git.commit.id.abbrev", "git.commit.time") +} diff --git a/dev-docker/test-docker/docker-compose.yml b/dev-docker/test-docker/docker-compose.yml index f4da9ca3..442c915d 100644 --- a/dev-docker/test-docker/docker-compose.yml +++ b/dev-docker/test-docker/docker-compose.yml @@ -15,7 +15,7 @@ services: networks: - maa maa_backend: - image: dragove/maa-backend-center:latest + image: ghcr.io/maaassistantarknights/maabackendcenter:dev container_name: maa-backend environment: - SPRING_DATA_MONGODB_URI=mongodb://mongo/MaaBackend diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 143ed513..00000000 --- a/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'MaaBackendCenter' - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..6e011c5f --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "MaaBackendCenter" diff --git a/src/main/kotlin/plus/maa/backend/config/HttpInterfaceConfig.kt b/src/main/kotlin/plus/maa/backend/config/HttpInterfaceConfig.kt index 223811bb..9f22afdc 100644 --- a/src/main/kotlin/plus/maa/backend/config/HttpInterfaceConfig.kt +++ b/src/main/kotlin/plus/maa/backend/config/HttpInterfaceConfig.kt @@ -41,7 +41,7 @@ class HttpInterfaceConfig { headers.add("X-GitHub-Api-Version", "2022-11-28") } .build() - return HttpServiceProxyFactory.builder(WebClientAdapter.forClient(client)) + return HttpServiceProxyFactory.builderFor(WebClientAdapter.create(client)) .build() .createClient(GithubRepository::class.java) } diff --git a/src/main/kotlin/plus/maa/backend/config/ThreadPoolConfig.kt b/src/main/kotlin/plus/maa/backend/config/ThreadPoolConfig.kt index 4c9dbb7a..99a04010 100644 --- a/src/main/kotlin/plus/maa/backend/config/ThreadPoolConfig.kt +++ b/src/main/kotlin/plus/maa/backend/config/ThreadPoolConfig.kt @@ -1,7 +1,7 @@ package plus.maa.backend.config import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration -import org.springframework.boot.task.TaskExecutorBuilder +import org.springframework.boot.task.ThreadPoolTaskExecutorBuilder import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Lazy @@ -14,9 +14,12 @@ class ThreadPoolConfig { @Lazy @Primary @Bean( - name = [TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME, AsyncAnnotationBeanPostProcessor.DEFAULT_TASK_EXECUTOR_BEAN_NAME] + name = [ + TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME, + AsyncAnnotationBeanPostProcessor.DEFAULT_TASK_EXECUTOR_BEAN_NAME + ] ) - fun defaultTaskExecutor(builder: TaskExecutorBuilder): ThreadPoolTaskExecutor = builder.build() + fun defaultTaskExecutor(builder: ThreadPoolTaskExecutorBuilder): ThreadPoolTaskExecutor = builder.build() @Bean fun emailTaskExecutor(): ThreadPoolTaskExecutor { @@ -24,7 +27,7 @@ class ThreadPoolConfig { val taskExecutor = ThreadPoolTaskExecutor() // I/O 密集型配置 taskExecutor.corePoolSize = Runtime.getRuntime().availableProcessors() * 2 - taskExecutor.threadNamePrefix = "email-task-" + taskExecutor.setThreadNamePrefix("email-task-") // 动态的核心线程数量 taskExecutor.setAllowCoreThreadTimeOut(true) return taskExecutor