refactor(gradle): 重构项目构建配置 #23
| @ -3,7 +3,6 @@ plugins { | ||||
|     alias(libs.plugins.kotlin.jvm) | ||||
|     alias(libs.plugins.kotlin.plugin.spring) | ||||
|     alias(libs.plugins.spring.boot) | ||||
|     alias(libs.plugins.spring.dependency.management) | ||||
|     alias(libs.plugins.jibLocalPlugin) | ||||
| } | ||||
| 
 | ||||
| @ -20,10 +19,11 @@ allprojects { | ||||
|     // 设置全局属性 | ||||
|     ext { | ||||
|         set(ProjectFlags.USE_SPRING_BOOT_WEB, false) | ||||
|         set(ProjectFlags.USE_LLM_CORE_SPI, false) | ||||
|         set(ProjectFlags.USE_LLM_KT_IMPL_DEPENDENCE, false) | ||||
|         set(ProjectFlags.USE_SPRING_CLOUD_BOM, false) | ||||
|         set(ProjectFlags.IS_ROOT_MODULE, false) | ||||
|         set(ProjectFlags.USE_SPRING_BOOT_BOM,false) | ||||
|         set(ProjectFlags.USE_SPRING_BOOT_BOM, false) | ||||
|         set(ProjectFlags.USE_LLM_IMPL_PLATFORM_DEPENDENCE, false) | ||||
|     } | ||||
|     repositories { | ||||
|         mavenLocal() | ||||
| @ -34,9 +34,6 @@ allprojects { | ||||
|         maven { | ||||
|             url = uri("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev") | ||||
|         } | ||||
| //        maven { | ||||
| //            url = uri("https://raw.githubusercontent.com/eurotech/kura_addons/mvn-repo/") | ||||
| //        } | ||||
|         maven { | ||||
|             url = uri("https://maven.aliyun.com/repository/public/") | ||||
|         } | ||||
| @ -68,24 +65,25 @@ allprojects { | ||||
| 
 | ||||
| subprojects { | ||||
|     afterEvaluate { | ||||
|         // springbootWeb | ||||
|         if (project.getPropertyByBoolean(ProjectFlags.USE_SPRING_BOOT_WEB)) { | ||||
|         if (project.getPropertyByBoolean(ProjectFlags.USE_LLM_IMPL_PLATFORM_DEPENDENCE)) { | ||||
|             apply { | ||||
|                 plugin(libs.plugins.spring.dependency.management.get().pluginId) | ||||
|                 plugin(libs.plugins.spring.boot.get().pluginId) | ||||
|                 plugin(libs.plugins.kotlin.plugin.spring.get().pluginId) | ||||
|             } | ||||
|             dependencies { | ||||
|                 implementation(libs.springBootStarter.web) | ||||
| 
 | ||||
|                 testImplementation(libs.springBootStarter.test) | ||||
|                 testRuntimeOnly(libs.junitPlatform.launcher) | ||||
|             ext { | ||||
|                 setProperty(ProjectFlags.USE_SPRING_BOOT_WEB, true) | ||||
|                 setProperty(ProjectFlags.USE_SPRING_CLOUD_BOM, true) | ||||
|                 setProperty(ProjectFlags.USE_LLM_KT_IMPL_DEPENDENCE, true) | ||||
|             } | ||||
|         } | ||||
|         // llmx-core-spi | ||||
|         if (project.getPropertyByBoolean(ProjectFlags.USE_LLM_CORE_SPI)) { | ||||
|             dependencies { | ||||
|                 // Nacos 服务发现和配置 | ||||
|                 implementation(libs.springCloudStarter.alibaba.nacos.discovery) | ||||
|                 // 核心spi依赖 | ||||
|                 implementation(project(Modules.Core.SPI)) | ||||
|                 // okHttp依赖 | ||||
|                 implementation(libs.okHttp) | ||||
|                 // forgeBoot依赖 | ||||
|                 implementation(libs.forgeBoot.core.extension) | ||||
|                 implementation(libs.forgeBoot.core.extension) | ||||
|             } | ||||
|         } | ||||
|         // springCloudBom | ||||
| @ -94,11 +92,34 @@ subprojects { | ||||
|                 implementation(platform(libs.springCloudDependencies.bom)) | ||||
|             } | ||||
|         } | ||||
|         if(project.getPropertyByBoolean(ProjectFlags.USE_SPRING_BOOT_BOM)){ | ||||
|         // springBootBom | ||||
|         if (project.getPropertyByBoolean(ProjectFlags.USE_SPRING_BOOT_BOM)) { | ||||
|             dependencies { | ||||
|                 implementation(platform(libs.springBootDependencies.bom)) | ||||
|             } | ||||
|         } | ||||
|         // springbootWeb | ||||
|         if (project.getPropertyByBoolean(ProjectFlags.USE_SPRING_BOOT_WEB)) { | ||||
|             apply { | ||||
|                 plugin(libs.plugins.spring.boot.get().pluginId) | ||||
|             } | ||||
|             dependencies { | ||||
|                 implementation(libs.springBootStarter.web) | ||||
|                 implementation(platform(libs.springBootDependencies.bom)) | ||||
|                 testImplementation(libs.springBootStarter.test) | ||||
|                 testRuntimeOnly(libs.junitPlatform.launcher) | ||||
|             } | ||||
|         } | ||||
|         // 使用kt实现impl服务依赖 | ||||
|         if (project.getPropertyByBoolean(ProjectFlags.USE_LLM_KT_IMPL_DEPENDENCE)) { | ||||
|             dependencies { | ||||
|                 // jackson kt模块依赖 | ||||
|                 implementation(libs.jackson.module.kotlin) | ||||
|                 // kt协程依赖 | ||||
|                 implementation(libs.kotlinx.coruntes.reactor) | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
|     val libs = rootProject.libs | ||||
|     apply { | ||||
|  | ||||
| @ -2,6 +2,11 @@ object ProjectFlags { | ||||
|     const val USE_SPRING_BOOT_WEB = "useSpringBootWeb" | ||||
|     const val USE_SPRING_BOOT_BOM = "useSpringBootBom" | ||||
|     const val USE_SPRING_CLOUD_BOM = "useSpringCloudBom" | ||||
|     const val USE_LLM_CORE_SPI = "useLLMCoreSPI" | ||||
|     const val USE_LLM_KT_IMPL_DEPENDENCE = "useLLMKtImplDependence" | ||||
|     const val IS_ROOT_MODULE = "isRootModule" | ||||
| 
 | ||||
|     /** | ||||
|      * 使用实现服务第三方平台依赖 | ||||
|      */ | ||||
|     const val USE_LLM_IMPL_PLATFORM_DEPENDENCE = "useLLMImplPlatformDependence" | ||||
| } | ||||
| @ -5,7 +5,7 @@ spring-boot-version = "3.2.4" | ||||
| spring-dependency-management-version = "1.1.7" | ||||
| aliyun-bailian-version = "2.0.0" | ||||
| spring-cloud-starter-alibaba-nacos-discovery-version = "2023.0.1.0" | ||||
| forgeBoot-version = "1.1.0-SNAPSHOT" | ||||
| forgeBoot-version = "1.2.0-SNAPSHOT" | ||||
| okHttp-version = "4.12.0" | ||||
| jib-version = "3.4.2" | ||||
| org-reactivestreams-reactiveStreams-version = "1.0.4" | ||||
|  | ||||
| @ -13,7 +13,7 @@ dependencies { | ||||
|     implementation(libs.springCloudStarter.loadbalancer) | ||||
| 
 | ||||
| 
 | ||||
|     implementation(project(Modules.Core.SPI)) | ||||
|     implementation(project(Modules.Core.COMMON)) | ||||
| 
 | ||||
|     // Kotlin Coroutines | ||||
|     implementation(libs.kotlinx.coruntes.reactor) | ||||
|  | ||||
| @ -6,7 +6,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient | ||||
| 
 | ||||
| @SpringBootApplication | ||||
| @EnableDiscoveryClient | ||||
| class LlmxCoreServiceApplication | ||||
| open class LlmxCoreServiceApplication | ||||
| 
 | ||||
| /** | ||||
|  * 程序的入口点。 | ||||
|  | ||||
| @ -1,36 +1,36 @@ | ||||
| //package org.jcnc.llmx.core.service.config | ||||
| // | ||||
| //import com.gewuyou.forgeboot.core.extension.log | ||||
| //import org.springframework.context.annotation.Configuration | ||||
| //import org.springframework.web.servlet.config.annotation.CorsRegistry | ||||
| //import org.springframework.web.servlet.config.annotation.WebMvcConfigurer | ||||
| // | ||||
| ///** | ||||
| // * CORS配置类 | ||||
| // * | ||||
| // * 该类用于全局配置跨域请求设置,以确保前端应用可以与后端服务进行通信 | ||||
| // * 主要通过重写addCorsMappings方法来配置跨域请求映射,以及通过corsWebFilter方法来提供更细粒度的跨域支持 | ||||
| // * | ||||
| // * @since 2025-04-02 17:03:41 | ||||
| // * @author gewuyou | ||||
| // */ | ||||
| //@Configuration | ||||
| //open class CorsConfig : WebMvcConfigurer { | ||||
| //    /** | ||||
| //     * 添加跨域请求映射 | ||||
| //     * | ||||
| //     * 该方法重写了父接口中的addCorsMappings方法,用于配置全局的跨域请求规则 | ||||
| //     * 主要配置了允许所有路径、所有来源、常见HTTP方法、所有请求头的跨域请求,并设置了不携带Cookie以及预检请求缓存时间 | ||||
| //     * | ||||
| //     * @param registry 跨域请求注册表,用于添加跨域请求映射 | ||||
| //     */ | ||||
| //    override fun addCorsMappings(registry: CorsRegistry) { | ||||
| //        log.info("Web CORS配置生效") | ||||
| //        registry.addMapping("/**")  // 匹配所有路径 | ||||
| //            .allowedOrigins("*")  // 允许所有来源(生产环境建议指定具体域名) | ||||
| //            .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")  // 允许的HTTP方法 | ||||
| //            .allowedHeaders("*")  // 允许所有请求头 | ||||
| //            .allowCredentials(false)  // 是否允许携带Cookie(true时需要明确指定allowedOrigins,不能为*) | ||||
| //            .maxAge(3600)  // 预检请求缓存时间(秒) | ||||
| //    } | ||||
| //} | ||||
| package org.jcnc.llmx.core.service.config | ||||
| 
 | ||||
| import com.gewuyou.forgeboot.core.extension.log | ||||
| import org.springframework.context.annotation.Configuration | ||||
| import org.springframework.web.servlet.config.annotation.CorsRegistry | ||||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurer | ||||
| 
 | ||||
| /** | ||||
|  * CORS配置类 | ||||
|  * | ||||
|  * 该类用于全局配置跨域请求设置,以确保前端应用可以与后端服务进行通信 | ||||
|  * 主要通过重写addCorsMappings方法来配置跨域请求映射,以及通过corsWebFilter方法来提供更细粒度的跨域支持 | ||||
|  * | ||||
|  * @since 2025-04-02 17:03:41 | ||||
|  * @author gewuyou | ||||
|  */ | ||||
| @Configuration | ||||
| open class CorsConfig : WebMvcConfigurer { | ||||
|     /** | ||||
|      * 添加跨域请求映射 | ||||
|      * | ||||
|      * 该方法重写了父接口中的addCorsMappings方法,用于配置全局的跨域请求规则 | ||||
|      * 主要配置了允许所有路径、所有来源、常见HTTP方法、所有请求头的跨域请求,并设置了不携带Cookie以及预检请求缓存时间 | ||||
|      * | ||||
|      * @param registry 跨域请求注册表,用于添加跨域请求映射 | ||||
|      */ | ||||
|     override fun addCorsMappings(registry: CorsRegistry) { | ||||
|         log.info("Web CORS配置生效") | ||||
|         registry.addMapping("/**")  // 匹配所有路径 | ||||
|             .allowedOrigins("*")  // 允许所有来源(生产环境建议指定具体域名) | ||||
|             .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")  // 允许的HTTP方法 | ||||
|             .allowedHeaders("*")  // 允许所有请求头 | ||||
|             .allowCredentials(false)  // 是否允许携带Cookie(true时需要明确指定allowedOrigins,不能为*) | ||||
|             .maxAge(3600)  // 预检请求缓存时间(秒) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -5,11 +5,8 @@ import com.gewuyou.forgeboot.webmvc.version.annotation.ApiVersion | ||||
| import org.jcnc.llmx.core.common.entities.request.ChatRequest | ||||
| import org.jcnc.llmx.core.common.entities.response.ChatResponsePart | ||||
| import org.jcnc.llmx.core.service.service.impl.LLMServiceImpl | ||||
| 
 | ||||
| import org.reactivestreams.Publisher | ||||
| import org.springframework.http.MediaType | ||||
| import org.springframework.web.bind.annotation.CrossOrigin | ||||
| 
 | ||||
| import org.springframework.web.bind.annotation.PostMapping | ||||
| import org.springframework.web.bind.annotation.RequestBody | ||||
| import org.springframework.web.bind.annotation.RequestMapping | ||||
| @ -24,7 +21,6 @@ import org.springframework.web.bind.annotation.RestController | ||||
| @ApiVersion | ||||
| @RestController | ||||
| @RequestMapping("/chat") | ||||
| @CrossOrigin(origins = ["*"]) // 放宽跨域 | ||||
| class ChatController( | ||||
|     private val llmServiceImpl: LLMServiceImpl | ||||
| ) { | ||||
|  | ||||
| @ -1,24 +1,6 @@ | ||||
| 
 | ||||
| // 开启springboot | ||||
| setProperty(ProjectFlags.USE_SPRING_BOOT_WEB, true) | ||||
| setProperty(ProjectFlags.USE_SPRING_CLOUD_BOM,true) | ||||
| // 开启LLM实现平台依赖 | ||||
| setProperty(ProjectFlags.USE_LLM_IMPL_PLATFORM_DEPENDENCE, true) | ||||
| dependencies { | ||||
|     // Nacos 服务发现和配置 | ||||
|     implementation(libs.springCloudStarter.alibaba.nacos.discovery) | ||||
| 
 | ||||
|     implementation(project(Modules.Core.SPI)) | ||||
| 
 | ||||
|     implementation(libs.kotlinx.coruntes.reactor) | ||||
| 
 | ||||
|     implementation(libs.okHttp) | ||||
| 
 | ||||
|     implementation(libs.forgeBoot.core.extension) | ||||
| 
 | ||||
|     implementation(libs.jackson.module.kotlin) | ||||
| 
 | ||||
|     implementation(libs.forgeBoot.core.extension) | ||||
| 
 | ||||
|     implementation(libs.aliyun.bailian) | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -1,19 +1,5 @@ | ||||
| // 开启springboot | ||||
| setProperty(ProjectFlags.USE_SPRING_BOOT_WEB, true) | ||||
| setProperty(ProjectFlags.USE_SPRING_CLOUD_BOM,true) | ||||
| // 开启LLM实现平台依赖 | ||||
| setProperty(ProjectFlags.USE_LLM_IMPL_PLATFORM_DEPENDENCE, true) | ||||
| dependencies { | ||||
|     // Nacos 服务发现和配置 | ||||
|     implementation(libs.springCloudStarter.alibaba.nacos.discovery) | ||||
| 
 | ||||
|     implementation(project(Modules.Core.SPI)) | ||||
| 
 | ||||
|     implementation(libs.kotlinx.coruntes.reactor) | ||||
| 
 | ||||
|     implementation(libs.okHttp) | ||||
| 
 | ||||
|     implementation(libs.forgeBoot.core.extension) | ||||
| 
 | ||||
|     implementation(libs.jackson.module.kotlin) | ||||
| 
 | ||||
|     implementation(libs.forgeBoot.core.extension) | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user