IntelliJ中JavaFX+Gradle项目启动报错:JavaFX runtime components are missing 求助
Hey there! Let's work through fixing your JavaFX + Gradle setup step by step. Based on the configs you shared, here are the key adjustments and checks to get your app running:
1. Fix Missing JavaFX Dependency & Clean Up Module Info
Looking at your files:
- Your
module-info.javadeclares a dependency onjavafx.fxml, but your Gradle build doesn't include this module in dependencies. This will cause runtime errors when the module system can't resolve the dependency. requires java.baseis redundant—every Java module automatically depends onjava.base, so you can remove this line.
Updated module-info.java:
module com.skb { requires javafx.fxml; requires javafx.controls; requires javafx.graphics; opens com.skb; }
2. Simplify Gradle Configuration with Official JavaFX Plugin
Your custom getJavaFXPlatform() method uses an internal Gradle API (DefaultNativePlatform), which can break across Gradle versions. Instead, use the official OpenJFX Gradle plugin—it handles platform-specific dependencies automatically, eliminating the need for custom OS detection.
Updated build.gradle:
plugins { id 'application' // Use official OpenJFX plugin to manage JavaFX dependencies id 'org.openjfx.javafxplugin' version '0.0.10' } group 'com.skb' version '1.0-SNAPSHOT' repositories { mavenCentral() } // Configure JavaFX via the plugin javafx { version = "15.0.1" modules = ['javafx.controls', 'javafx.fxml', 'javafx.graphics'] } application { mainModule.set('com.skb') mainClass.set('com.skb.EditorApp') } java { modularity.inferModulePath.set(true) }
3. Verify IntelliJ Run Configuration
When running modular JavaFX apps with Gradle, always use the Gradle task instead of directly running the EditorApp class:
- Open the Gradle tool window in IntelliJ (right sidebar).
- Navigate to
Tasks > application > run. - Right-click the
runtask and select "Run" to launch your app.
Directly running the class can cause module path resolution issues, as IntelliJ may not properly inject Gradle-managed dependencies into the module path.
4. Test the Setup
After making these changes:
- Click the "Refresh Gradle Project" button in the Gradle tool window to sync your config.
- Run the
application:runtask—you should see the "Running..." output in the console if everything works correctly.
内容的提问来源于stack exchange,提问作者Sourav Kannantha B

