Minecraft模组开发Gradle运行配置报TrialMod项目不存在错误解决
Forge 1.8.9模组开发运行配置缺失、提示引用无效项目修复方案
问题现象
- 参照基于Gradle的Forge模组开发教程操作,教程给出的空模组启动路径为:
Run > Run Configuration > Java Application > run client - 进入运行配置页面后,无任何预置配置项;手动新建运行配置时弹出错误提示:Launch configuration Trial references non-existing project TrialMod.
- 界面后台可看到项目实际存在,相关截图:
- 当前使用的
build.gradle配置内容:
// For those who want the bleeding edge buildscript { repositories { jcenter() maven { name = "forge" url = "http://files.minecraftforge.net/maven" } } dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT' } } apply plugin: 'net.minecraftforge.gradle.forge' /* // for people who want stable - not yet functional for MC 1.8.8 - we require the forgegradle 2.1 snapshot plugins { id "net.minecraftforge.gradle.forge" version "2.0.2" } */ version = "2.0" group= "com.oopermass.trialmod" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "trialmod" minecraft { version = "1.8.9-11.15.1.2318-1.8.9" runDir = "run" // the mappings can be changed at any time, and must be in the following format. // snapshot_YYYYMMDD snapshot are built nightly. // stable_# stables are built at the discretion of the MCP team. // Use non-default mappings at your own risk. they may not allways work. // simply re-run your setup task after changing the mappings to update your workspace. mappings = "stable_20" // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. } dependencies { // you may put jars on which you depend on in ./libs // or you may define them like so.. //compile "some.group:artifact:version:classifier" //compile "some.group:artifact:version" // real examples //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env //compile 'com.googlecode.efficient-matrix-library:ejml:0.24' // adds ejml to the dev env // the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime. //provided 'com.mod-buildcraft:buildcraft:6.0.8:dev' // the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided, // except that these dependencies get remapped to your current MCP mappings //deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev' //deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev' // for more info... // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html // http://www.gradle.org/docs/current/userguide/dependency_management.html } processResources { // this will ensure that this task is redone when the versions change. inputs.property "version", project.version inputs.property "mcversion", project.minecraft.version // replace stuff in mcmod.info, nothing else from(sourceSets.main.resources.srcDirs) { include 'mcmod.info' // replace version and mcversion expand 'version':project.version, 'mcversion':project.minecraft.version } // copy everything else, thats not the mcmod.info from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' } }
故障原因
该问题和build.gradle配置内容无关,核心原因是导入项目后没有执行ForgeGradle的工作区初始化任务,IDE既没有自动生成预置的客户端/服务端运行配置,也没有完成项目结构的正确关联,手动新建配置时填写的项目名和Gradle实际识别的项目名不匹配,就会触发“引用不存在项目”的报错。
修复步骤
按顺序执行以下操作即可解决:
- 关闭所有运行配置弹窗,回到IDE主界面,打开内置终端,确认终端当前路径为项目根目录(和
build.gradle文件同层级) - 依次执行Gradle任务:
- 执行清理命令:
gradlew clean - 根据你使用的IDE执行对应的工作区初始化命令:
- 使用IDEA开发:
gradlew setupDecompWorkspace idea - 使用Eclipse开发:
gradlew setupDecompWorkspace eclipse
注意:该步骤需要联网下载Minecraft、Forge的依赖与反编译资源,耗时根据网络情况从数分钟到数十分钟不等,不要中途中断执行
- 使用IDEA开发:
- 执行清理命令:
- 任务全部执行完成后,刷新Gradle项目:
- IDEA用户点击右侧Gradle面板的刷新按钮,重新加载所有项目依赖
- Eclipse用户右键项目,选择
Gradle > Refresh Gradle Project
- 不要手动新建运行配置,重新打开
Run > Run Configuration页面,Java Application分类下会自动生成run client、run server两个预置配置,直接选中run client即可正常启动测试客户端。
常见踩坑提示:如果完成上述操作后仍看不到自动生成的运行配置,检查项目导入方式是否正确:必须将
build.gradle所在的根目录作为Gradle项目导入,不要将内层src文件夹或其他子目录单独作为项目导入,否则IDE无法识别正确的项目结构,运行配置也无法关联到对应项目。
内容的提问来源于stack exchange,提问作者CubeTastick N
相关产品推荐
相关产品推荐

