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

如何为Minecraft Fabric项目添加第三方API/库?构建报错求助

解决Fabric模组开发中引入Trinkets/Cloth Config的Gradle构建错误

问题描述

刚入门Minecraft Fabric模组开发,已成功添加自定义物品,现在尝试引入Trinkets和Cloth Config第三方API,但遇到Gradle构建失败的问题。

当前build.gradle中的仓库与依赖配置如下:

repositories {
// Trinkets API
maven {
name = "TerraformersMC"
url = "https://maven.terraformersmc.com/releases"
}
maven {
name = "Ladysnake Libs"
url = 'https://maven.ladysnake.org/releases'
}
// Cloth Config
maven {
url "https://maven.shedaniel.me/"
}
}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.
// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
// Trinkets API
modImplementation "dev.emi:trinkets:${trinkets_version}"
// Cloth Config
modApi "me.shedaniel.cloth:cloth-config-fabric:11.1.106" {
exclude(group: "net.fabricmc.fabric-api")
}
}

曾尝试将两个API的Jar包放入mod-id/build/libs目录,但问题依旧,构建时的错误信息如下:

[error] FAILURE: Build failed with an exception.
* Where:
Build file 'E:\MinecraftModProject\Fabric\shengs-wearable\shengs-wearable-template-1.20.1\build.gradle' line: 83
* What went wrong:
A problem occurred evaluating root project 'shengs-wearable-template-1.20.1'.
> Could not get unknown property 'trinkets_version' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
CONFIGURE FAILED in 6s
[error] [gradle-server] The supplied build action failed with an exception.
[error] Error getting build for e:\MinecraftModProject\Fabric\shengs-wearable\shengs-wearable-template-1.20.1: The supplied build action failed with an exception.
[info] Java Home: C:\Program Files\Java\jdk-17
[info] JVM Args: --add-opens=java.base/java.util=ALL-UNNAMED,--add-opens=java.base/java.lang=ALL-UNNAMED,--add-opens=java.base/java.lang.invoke=ALL-UNNAMED,--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED,--add-opens=java.base/java.nio.charset=ALL-UNNAMED,--add-opens=java.base/java.net=ALL-UNNAMED,--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED,-Xmx1G,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant
[info] Gradle User Home: C:\Users\sheng\.gradle
[info] Gradle Version: 8.3
[info] > Configure project :
Fabric Loom: 1.4.4
[error] FAILURE: Build failed with an exception.
* Where:
Build file 'E:\MinecraftModProject\Fabric\shengs-wearable\shengs-wearable-template-1.20.1\build.gradle' line: 83
* What went wrong:
A problem occurred evaluating root project 'shengs-wearable-template-1.20.1'.
> Could not get unknown property 'trinkets_version' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
CONFIGURE FAILED in 181ms
[error] [gradle-server] The supplied build action failed with an exception.
[error] Error getting build for e:\MinecraftModProject\Fabric\shengs-wearable\shengs-wearable-template-1.20.1: The supplied build action failed with an exception.
[info] Found 0 tasks
[info] Build file opened: e:\MinecraftModProject\Fabric\shengs-wearable\shengs-wearable-template-1.20.1\build.gradle

解决方案

1. 修复trinkets_version未定义错误

错误核心是build.gradle中使用了${trinkets_version}变量,但该变量未在gradle.properties中声明。

  • 打开项目根目录下的gradle.properties文件
  • 添加Trinkets版本配置(以1.20.1适配版本为例):
    trinkets_version=3.7.1
    
    版本号需与你的Minecraft版本兼容,确保匹配即可。

2. 统一版本管理(可选但推荐)

为了和项目其他版本配置保持一致,建议将Cloth Config的版本也移入gradle.properties:

  • 在gradle.properties中添加:
    cloth_config_version=11.1.106
    
  • 修改build.gradle中的Cloth Config依赖行:
    modApi "me.shedaniel.cloth:cloth-config-fabric:${cloth_config_version}" {
        exclude(group: "net.fabricmc.fabric-api")
    }
    

3. 移除手动添加的Jar包

手动放入build/libs的API Jar包完全多余,Gradle会自动从配置的Maven仓库拉取依赖,直接删除这些文件即可。

4. 重新同步Gradle配置

完成上述修改后,在IDE中点击Gradle同步按钮,或在终端执行./gradlew clean build命令,等待依赖下载完成即可解决构建错误。

额外提示

  • 所有第三方API版本必须与你的Minecraft版本、Fabric版本兼容,避免出现版本不匹配的其他问题
  • 无需手动管理API Jar包,Gradle会自动处理依赖的下载与引入流程

内容的提问来源于stack exchange,提问作者Huan Sheng Tew

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 12:26:13