You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Fabric模组中Spring Boot传递依赖打包缺失问题排查

问题解决:Fabric模组打包后缺失Spring Boot依赖

问题根源

Fabric Loom的默认构建逻辑不会自动将Spring Boot这类第三方依赖打包进最终的模组Jar,本地用gradlew.bat runServer运行时,Gradle会自动把依赖加入类路径所以一切正常,但部署时Jar里没有这些类就会触发NoClassDefFoundError。另外你同时启用了Spring Boot插件,它的可执行Jar打包逻辑和Fabric Loom的模组Jar构建逻辑冲突,这也是问题的诱因之一。

具体修复步骤

1. 移除冲突插件

删掉Spring Boot插件,只保留Spring依赖管理插件来统一管控版本:

plugins {
   id 'fabric-loom' version '0.11-SNAPSHOT'
   id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

2. 调整依赖配置

使用Fabric Loom的modImplementation配合include()强制将依赖打包进模组Jar,同时通过BOM统一管理Spring相关版本:

configurations {
   all {
      // 排除Spring Boot的日志依赖,避免和Minecraft自带的Log4j冲突
      exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
   }
}

dependencies {
   // 保留原有的Minecraft相关依赖配置
   minecraft "com.mojang:minecraft:${project.minecraft_version}"
   mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
   modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
   modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

   // 引入Spring Boot BOM管理所有相关依赖版本
   dependencyManagement {
      imports {
          mavenBom 'org.springframework.boot:spring-boot-dependencies:2.5.14'
      }
   }

   // Spring Boot核心依赖,用modImplementation + include确保打包进模组Jar
   modImplementation include('org.springframework.boot:spring-boot-starter')
   modImplementation include('org.springframework.boot:spring-boot-starter-web')
   modImplementation include('org.springframework.boot:spring-boot-starter-websocket')

   // 其他第三方依赖同样用modImplementation + include处理
   modImplementation include('org.springdoc:springdoc-openapi-ui:1.6.13')
   modImplementation include('com.discord4j:discord4j-core:3.2.3')
}

3. 确保Jar打包逻辑正确

保留原有的jar任务配置,同时确保Loom的remapJar任务(最终生成的可部署模组Jar)正确处理依赖:

jar {
   from("LICENSE") {
      rename { "${it}_${project.archivesBaseName}"}
   }
}

// 处理可能的重复类问题
tasks.named('remapJar') {
   duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

验证修复

执行gradlew.bat clean build,构建完成后找到build/libs目录下的*-remapped.jar文件,解压后检查是否包含org/springframework等Spring相关类文件。将这个remapped版本的Jar部署到服务器即可正常运行。

内容的提问来源于stack exchange,提问作者MrSolarius

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 19:31:15