{"record":{"id":"31d27ea037706691","repo":"Anuken/Mindustry","slug":"this-mod-plugin-has-loaded-mindustry-dependencies","errorCode":null,"errorMessage":"This mod/plugin has loaded Mindustry dependencies from its own class loader. You are incorrectly including Mindustry dependencies in the mod JAR - make sure Mindustry is declared as `compileOnly` in Gradle, and that the JAR is created with `runtimeClasspath`!","messagePattern":"This mod/plugin has loaded Mindustry dependencies from its own class loader\\. You are incorrectly including Mindustry dependencies in the mod JAR - make sure Mindustry is declared as `compileOnly` in Gradle, and that the JAR is created with `runtimeClasspath`!","errorType":"validation","errorClass":"ModLoadException","httpStatus":null,"severity":"error","filePath":"core/src/mindustry/mod/Mods.java","lineNumber":1175,"sourceCode":"                Core.settings.getBool(\"mod-\" + baseName + \"-enabled\", true) &&\n                Version.isAtLeast(meta.minGameVersion) &&\n                (meta.getMinMajor() >= minJavaModGameVersion || headless || meta.legacyCompatible) &&\n                !meta.isBlacklisted() &&\n                !skipModCode &&\n                initialize\n            ){\n                if(ios){\n                    throw new ModLoadException(\"Java class mods are not supported on iOS.\");\n                }\n\n                loader = platform.loadJar(sourceFile, mainLoader);\n                mainLoader.addChild(loader);\n                Class<?> main = Class.forName(mainClass, true, loader);\n\n                //detect mods that incorrectly package mindustry in the jar\n                if((main.getSuperclass().getName().equals(\"mindustry.mod.Plugin\") || main.getSuperclass().getName().equals(\"mindustry.mod.Mod\")) &&\n                    main.getSuperclass().getClassLoader() != Mod.class.getClassLoader()){\n                    throw new ModLoadException(\n                        \"This mod/plugin has loaded Mindustry dependencies from its own class loader. \" +\n                        \"You are incorrectly including Mindustry dependencies in the mod JAR - \" +\n                        \"make sure Mindustry is declared as `compileOnly` in Gradle, and that the JAR is created with `runtimeClasspath`!\"\n                    );\n                }\n\n                metas.put(main, meta);\n                mainMod = (Mod)main.getDeclaredConstructor().newInstance();\n            }else{\n                mainMod = null;\n            }\n\n            //all plugins are hidden implicitly\n            if(mainMod instanceof Plugin){\n                meta.hidden = true;\n            }\n\n            //disallow putting a description after the version","sourceCodeStart":1157,"sourceCodeEnd":1193,"githubUrl":"https://github.com/Anuken/Mindustry/blob/f695ad7e60323ebced984fa26d0bcf0bc54296b4/core/src/mindustry/mod/Mods.java#L1157-L1193","documentation":"loadMod detects when a mod's Plugin/Mod superclass was loaded by the mod's own classloader rather than the game's, proving Mindustry itself is packaged inside the mod JAR. This causes class-cast/linkage failures, so it is rejected with guidance to use compileOnly + runtimeClasspath.","triggerScenarios":"The mod JAR bundles Mindustry (and/or arc) classes; the superclass resolves from the mod loader instead of the game loader.","commonSituations":"Gradle declares Mindustry with implementation/api instead of compileOnly; a fat/shadow jar includes runtime dependencies; build uses 'application' fat packaging.","solutions":["Declare Mindustry (and arc) as compileOnly in Gradle.","Build the JAR from runtimeClasspath so deps are not embedded.","If using ShadowJar, exclude mindustry/arc artifacts from the shadow config.","Verify the built jar does not contain mindustry/ packages (unzip -l | grep mindustry)."],"exampleFix":"// before\ndependencies {\n    implementation 'com.github.Anuken:Mindustry:VERSION'\n}\njar { from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } }\n\n// after\ndependencies {\n    compileOnly 'com.github.Anuken:Mindustry:VERSION'\n}\ntasks.named('jar') {\n    from { configurations.runtimeClasspath.collect { zipTree(it) } }\n    // mindustry/arc are compileOnly -> never included\n}","handlingStrategy":"validation","validationCode":"// Build-time check: assert the packaged jar does not contain Mindustry classes.\n// (run in CI) e.g.\n// if unzip -l build/libs/*.jar | grep -q '^.*mindustry/'; then exit 1; fi","typeGuard":null,"tryCatchPattern":"try {\n    mods.loadMod(file);\n} catch(ModLoadException e) {\n    if(e.getMessage().contains(\"incorrectly including Mindustry dependencies\")) {\n        // rebuild with compileOnly + runtimeClasspath jar\n    } else throw e;\n}","preventionTips":["Declare Mindustry/arc as compileOnly, never implementation/api.","Build the mod jar from runtimeClasspath, not a full fat/shadow jar.","In CI, assert the produced jar contains no mindustry/ or arc/ packages."],"tags":["modding","gradle","classloading","packaging","build"],"backgroundTag":null,"analyzedSha":"f695ad7e60323ebced984fa26d0bcf0bc54296b4","analyzedAt":"2026-08-14T04:31:16.262Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}