IntelliJ IDEA中LibGDX项目运行失败的配置指导求助
Hey there! As a fellow LibGDX beginner who’s been through this exact headache, let’s walk through fixing that exit value 1 error step by step. It’s almost always a small config tweak that’s causing the issue—here’s what to check:
LibGDX versions and JDKs need to play nice together, and this is the most common culprit:
- First, check your LibGDX version in the root
build.gradlefile (look for thegdxVersionline). If it’s older than1.12.0, it might not fully support JDK 17. Update it to the latest stable version if needed. - In IntelliJ, go to
File > Settings > Build, Execution, Deployment > Build Tools > Gradleand make sure the "Gradle JVM" matches the JDK you’re using (JDK 11 or 17 works best with modern LibGDX).
The desktop launcher is often where things go awry for new users:
- Open the
desktopmodule’sbuild.gradleand confirm these lines match your JDK version:sourceCompatibility = 17 targetCompatibility = 17 - Make sure your
DesktopLauncherclass hasn’t been accidentally modified. It should look something like this (replaceMyGdxGamewith your actual game main class):
Missing or incorrect code here will immediately throw an exit value 1 error.public class DesktopLauncher { public static void main(String[] arg) { LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); new LwjglApplication(new MyGdxGame(), config); } }
Stale build cache can cause weird, unexplained errors—let’s wipe it out:
- In IntelliJ, click
File > Invalidate Caches...and select "Invalidate and Restart" to clear IDE-level cache. - Open the Gradle panel (right sidebar), expand your project, then run
Tasks > build > cleanfollowed byTasks > build > buildto rebuild everything from scratch. - For more detailed error logs, try running the project via the command line instead of IntelliJ:
- On Windows: Open a terminal in your project root, run
gradlew.bat desktop:run - On Mac/Linux: Run
./gradlew desktop:run
This will show you the full stack trace, which is way more helpful than the truncated IntelliJ console output.
- On Windows: Open a terminal in your project root, run
Older LWJGL versions (the library that powers LibGDX’s desktop backend) can clash with JDK 17. In your root build.gradle, make sure the lwjglVersion is set to a modern version (matching your LibGDX version—for LibGDX 1.12.0+, use 3.3.2):
lwjglVersion = "3.3.2"
If none of these steps fix the issue, run gradlew desktop:run --stacktrace (or gradlew.bat desktop:run --stacktrace on Windows) and share the full stack trace—this will let us pinpoint exactly what’s breaking.
内容的提问来源于stack exchange,提问作者Jamal

