Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加一个基于 Spring Boot v2.7.x 的兼容版本 starter 实现模块 #828

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions buildSrc/src/main/kotlin/JvmConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ inline fun Project.configJavaCompileWithModule(

// see https://kotlinlang.org/docs/gradle-configure-project.html#configure-with-java-modules-jpms-enabled
if (moduleName != null) {
options.compilerArgumentProviders.add(CommandLineArgumentProvider {
// Provide compiled Kotlin classes to javac – needed for Java/Kotlin mixed sources to work
listOf("--patch-module", "$moduleName=${sourceSets["main"].output.asPath}")
})
options.compilerArgumentProviders.add(
CommandLineArgumentProvider {
// Provide compiled Kotlin classes to javac – needed for Java/Kotlin mixed sources to work
listOf("--patch-module", "$moduleName=${sourceSets["main"].output.asPath}")
}
)
}

block()
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ javax-inject = "javax.inject:javax.inject:1"
javax-annotation-api = "javax.annotation:javax.annotation-api:1.3.2"

# spring-boot-v2
spring-boot-v2-dependencies = { group = "org.springframework.boot", name = "spring-boot-dependencies", version.ref = "spring-boot-v2" }
spring-boot-v2-autoconfigure = { group = "org.springframework.boot", name = "spring-boot-autoconfigure", version.ref = "spring-boot-v2" }
spring-boot-v2-logging = { group = "org.springframework.boot", name = "spring-boot-starter-logging", version.ref = "spring-boot-v2" }
spring-boot-v2-actuator = { group = "org.springframework.boot", name = "spring-boot-starter-actuator", version.ref = "spring-boot-v2" }
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ include(":simbot-quantcat:simbot-quantcat-common")

include(":simbot-cores:simbot-core-spring-boot-starter-common")
include(":simbot-cores:simbot-core-spring-boot-starter") // v3
//include(":simbot-cores:simbot-core-spring-boot-v2-starter")
include(":simbot-cores:simbot-core-spring-boot-starter-v2")

// extensions
include(":simbot-extensions:simbot-extension-continuous-session")
Expand Down
6 changes: 6 additions & 0 deletions simbot-cores/simbot-core-spring-boot-starter-v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Spring Boot starter 的 Spring Boot v2.7 兼容版本。

> [!warning]
> Spring Boot starter 的 v2 版本的维护成本较高,不会持续维护很久。
> 并且现在 Spring Boot v2.7.x已经在 2023-11-24 结束支持,请考虑迁移至 Spring Boot v3.x。

Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
/*
* Copyright (c) 2024. ForteScarlet.
*
* Project https://github.com/simple-robot/simpler-robot
* Email [email protected]
*
* This file is part of the Simple Robot Library (Alias: simple-robot, simbot, etc.).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
*
* You should have received a copy of the Lesser GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

import love.forte.gradle.common.core.project.setup

/*
* Copyright (c) 2021-2024. ForteScarlet.
*
Expand All @@ -22,41 +47,48 @@
*/

plugins {
// id("simbot.boot-module-conventions")
// `simbot-jvm-maven-publish`
kotlin("jvm")
kotlin("plugin.serialization")
kotlin("kapt")
id("simbot.dokka-module-configuration")
}

configJavaCompileWithModule("simbot.core.springboot.common")
setup(P.Simbot)
configJavaCompileWithModule("simbot.spring2boot.starter")

kotlin {
explicitApi()
configKotlinJvm(JVMConstants.KT_JVM_TARGET_VALUE)
}

@Suppress("VulnerableLibrariesLocal")
dependencies {
compileOnly(project(":simbot-commons:simbot-common-annotations"))
api(project(":simbot-quantcat:simbot-quantcat-common"))
api(project(":simbot-cores:simbot-core"))
api(project(":simbot-cores:simbot-core-spring-boot-starter-common"))
api(kotlin("reflect"))
api(libs.kotlinx.serialization.json)

compileOnly(libs.spring.boot.v2.logging)

compileOnly(libs.spring.boot.v2.autoconfigure)
compileOnly(libs.spring.boot.v2.configuration.processor)
annotationProcessor(libs.spring.boot.v2.configuration.processor)
kapt(libs.spring.boot.v2.configuration.processor)

compileOnly(libs.javax.annotation.api)

testImplementation(kotlin("test"))
testImplementation(project(":simbot-commons:simbot-common-annotations"))
testImplementation(project(":simbot-test"))
testImplementation(libs.spring.boot.v2.test)
testImplementation(libs.kotlinx.serialization.json)
testImplementation(libs.kotlinx.serialization.properties)
testImplementation(libs.kotlinx.serialization.protobuf)
testImplementation(libs.spring.boot.v2.aop)
testImplementation(libs.spring.boot.v2.autoconfigure)
testImplementation(libs.spring.boot.v2.configuration.processor)
testImplementation(libs.kotlinx.coroutines.test)
testImplementation(libs.spring.boot.v2.logging)
}

tasks.test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module simbot.spring2boot.starter {
// Kotlin
requires kotlin.stdlib;
requires kotlin.reflect;
requires kotlinx.coroutines.core;
requires kotlinx.serialization.json;
// spring
requires spring.core;
requires spring.context;
requires spring.boot;
requires spring.boot.autoconfigure;
requires spring.beans;
requires spring.aop;
// simbot
requires transitive simbot.logger;
requires simbot.spring.common;
requires simbot.common.core;
requires static simbot.common.annotations;

exports love.forte.simbot.spring2;
exports love.forte.simbot.spring2.application;
exports love.forte.simbot.spring2.configuration;
exports love.forte.simbot.spring2.configuration.application;
exports love.forte.simbot.spring2.configuration.binder;
exports love.forte.simbot.spring2.configuration.config;
exports love.forte.simbot.spring2.configuration.listener;
exports love.forte.simbot.spring2.warn;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2024. ForteScarlet.
*
* Project https://github.com/simple-robot/simpler-robot
* Email [email protected]
*
* This file is part of the Simple Robot Library (Alias: simple-robot, simbot, etc.).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
*
* You should have received a copy of the Lesser GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

package love.forte.simbot.spring2

import love.forte.simbot.spring2.configuration.*
import love.forte.simbot.spring2.configuration.application.*
import love.forte.simbot.spring2.configuration.binder.DefaultBinderManagerProvidersConfiguration
import love.forte.simbot.spring2.configuration.binder.ResolveBinderManagerProcessor
import love.forte.simbot.spring2.configuration.config.DefaultSimbotApplicationConfigurationProcessorConfiguration
import love.forte.simbot.spring2.configuration.listener.SimbotEventListenerFunctionProcessor
import love.forte.simbot.spring2.warn.MigratingSpringBootVersion
import love.forte.simbot.spring2.warn.MigratingSpringBootVersionWarningPrinter
import org.springframework.context.annotation.Import

/**
* 启用 simbot 的各项配置。
*
* 将其标记在你的启动类或某个配置类上。
*
* Kotlin
*
* ```kotlin
* @EnableSimbot
* @SpringBootApplication
* open class MyApplication {
* // ...
* }
* ```
*
* ```kotlin
* @EnableSimbot
* @Configuration
* open class MyConfig {
* // ...
* }
* ```
*
* Java
*
* ```java
* @EnableSimbot
* @SpringBootApplication
* public class MyApplication {
* // ...
* }
* ```
*
* ```java
* @EnableSimbot
* @Configuration
* public class MyConfig {
* // ...
* }
* ```
*
*/
@Target(AnnotationTarget.CLASS)
@Import(
MigratingSpringBootVersionWarningPrinter::class,
SimbotSpringPropertiesConfiguration::class,
// defaults
DefaultSimbotApplicationConfigurationProcessorConfiguration::class,
DefaultSimbotDispatcherProcessorConfiguration::class,
DefaultSimbotComponentInstallProcessorConfiguration::class,
DefaultSimbotPluginInstallProcessorConfiguration::class,
DefaultSimbotEventDispatcherProcessorConfiguration::class,
DefaultBinderManagerProvidersConfiguration::class,
// listeners directly
DefaultSimbotEventListenerRegistrarProcessorConfiguration::class,
// launcher factory & launcher
DefaultSimbotSpringApplicationLauncherFactoryConfiguration::class,
DefaultSimbotApplicationLauncherFactoryProcessorConfiguration::class,
SimbotApplicationConfiguration::class,
// app
DefaultSimbotSpringApplicationProcessorConfiguration::class,
// binders
ResolveBinderManagerProcessor::class,
// post listeners
SimbotEventListenerFunctionProcessor::class,
SimbotApplicationRunner::class
)
@MigratingSpringBootVersion
public annotation class EnableSimbot
Loading
Loading