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

将Minecraft 1.18.2模组移植到1.19.2时IntelliJ依赖解析失败求助

问题

我正尝试把Minecraft 1.18.2版本的AnimalCrops模组移植到1.19.2版本,按教程配置IntelliJ时,工具提示「Could not resolve dependency: net.minecraftforge:forge:1.19.2:userdev」。我是模组开发新手,用Git Bash和记事本编辑文件,当前的build.gradle内容如下,模组代码托管在GitHub:

buildscript {
    repositories {
        maven { url = 'https://maven.minecraftforge.net' }
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
    }
}

apply plugin: 'net.minecraftforge.gradle'

group = "knightminer"
archivesBaseName = "AnimalCrops"
java.toolchain.languageVersion = JavaLanguageVersion.of(17)

configurations {
    deployerJars
}

version = "${minecraft_version}-${mod_version}"

sourceSets {
    main {
        resources {
            srcDirs "$rootDir/src/generated/resources"
            // Exclude the cache of the generated data from what gets built
            exclude '.cache'
        }
    }
}

minecraft {
    mappings channel: 'official', version: "1.19.2-46.0.1"
    accessTransformer project.file("src/main/resources/META-INF/accesstransformer.cfg")

    runs {
        client {
            workingDirectory project.file('run')

            // Recommended logging data for a userdev environment
            property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

            // Recommended logging level for the console
            property 'forge.logging.console.level', 'debug'

            mods {
                animalcrops {
                    source sourceSets.main
                }
            }
        }

        server {
            workingDirectory project.file('run')

            // Recommended logging data for a userdev environment
            property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

            // Recommended logging level for the console
            property 'forge.logging.console.level', 'debug'

            mods {
                animalcrops {
                    source sourceSets.main
                }
            }
        }

        data {
            workingDirectory project.file('run')

            // Recommended logging data for a userdev environment
            property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

            // Recommended logging level for the console
            property 'forge.logging.console.level', 'debug'

        // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
      args '--mod', 'animalcrops', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')

      mods {
        animalcrops {
          source sourceSets.main
        }
      }
    }
  }
}

repositories {
    // JEI
  maven {
    // location of the maven that hosts JEI files
    name = "Progwml6 maven"
    url = "https://dvs1.progwml6.com/files/maven"
  }
  maven {
    // location of a maven mirror for JEI files, as a fallback
    name = "ModMaven"
    url = "https://modmaven.k-4u.nl"
  }
}

dependencies {
  minecraft "net.minecraftforge:forge:1.19.2"
  // compile against the JEI API but do not include it at runtime
  compileOnly fg.deobf("mezz.jei:jei-${jei_version}:api")
  // at runtime, use the full JEI jars
  runtimeOnly fg.deobf("mezz.jei:jei-${jei_version}")
}

// process mods.toml to inject variables
def modsTomlSpec = copySpec{
  from(sourceSets.main.resources) {
    include 'META-INF/mods.toml'
    expand 'version': mod_version,
            'loader_range': loader_range,
            'minecraft_range': minecraft_range,
            'forge_range': forge_range
  }
}
// need to copy into each build directory, unfortunately does not seem easy to do this automatically
def buildPaths = [
        "$rootDir/out/production/resources", // IDEA
        "$rootDir/bin", // Eclipse
]

// task to add mods.toml to all relevant folders
task replaceResources {
  // copy for gradle
  copy {
    outputs.upToDateWhen { false }
    with modsTomlSpec
    into processResources.destinationDir
  }
  // copy for IDEs
  buildPaths.each { path ->
    if (new File(path).exists()) {
      copy {
        outputs.upToDateWhen { false }
        with modsTomlSpec
        into path
      }
    }
  }
}

processResources {
  exclude 'META-INF/mods.toml'
  finalizedBy replaceResources
}

jar {
  manifest {
    attributes([
      "Specification-Title": "Animal Crops",
      "Specification-Vendor": "KnightMiner",
      "Specification-Version": "1", // We are version 1 of ourselves
      "Implementation-Title": project.name,
      "Implementation-Version": "${version}",
      "Implementation-Vendor": "KnightMiner",
      "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
    ])
  }
}

// because the normal output has been made to be obfuscated
task sourcesJar(type: Jar) {
  from sourceSets.main.allJava
  classifier = 'sources'
}

artifacts {
  archives sourcesJar
}
解决方案

核心问题分析

这个错误是因为依赖版本不完整、缺失必要的版本变量,导致Gradle无法定位到对应的Forge开发包。

具体修复步骤

  1. 补充缺失的版本变量
    在build.gradle最开头添加以下代码,定义所有用到的版本占位符(可根据需求调整):
def minecraft_version = "1.19.2"
def mod_version = "1.0.0"
def jei_version = "1.19.2-9.7.0.248"
def loader_range = "[46,)"
def minecraft_range = "[1.19.2,1.20)"
def forge_range = "[46.0.1,)"
  1. 修正Forge依赖的完整版本
    找到dependencies块中的Forge依赖,把:
minecraft "net.minecraftforge:forge:1.19.2"

替换为:

minecraft "net.minecraftforge:forge:${minecraft_version}-46.0.1"

版本号46.0.1要和你mappings配置里的1.19.2-46.0.1保持一致,确保依赖完全匹配。

  1. 确认ForgeGradle版本兼容性
    1.19.2对应的稳定ForgeGradle版本是5.1.x,你当前用的5.1.+没问题,也可以指定具体稳定版避免自动更新带来的问题,比如:
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.37', changing: true
  1. 刷新Gradle依赖
  • 在IntelliJ中点击右侧Gradle面板的「刷新」按钮
  • 或者在Git Bash中运行命令:
./gradlew clean build --refresh-dependencies

额外提示

  • 所有版本号要对应:JEI版本必须匹配Minecraft 1.19.2,可确认官方兼容版本
  • 若仍有问题,检查网络连接是否能访问Maven仓库,必要时可切换国内镜像源

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 15:15:15