'error: package javafx.scene.media does not exist

I'm trying to create javafx media player as gradle project, but got this error.error: package javafx.scene.media does not exist on line: import javafx.scene.media.Media;

Here is my build.gradle

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'

}

group 'life.antonov'
version '1.0'

mainClassName='life.antonov.muza.Main'
sourceCompatibility = 11

jar {
    manifest {
        attributes "Main-Class": "$mainClassName"
    }

    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

javafx {
    version = "13"
    modules = [ 'javafx.controls', 'javafx.fxml' ]
}
repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile group: 'org.openjfx', name: 'javafx-controls', version: '13'
    compile group: 'org.openjfx', name: 'javafx-fxml', version: '13 '
    compile group: 'org.openjfx', name: 'javafx-media', version: '13'


}

I'm tried to unzip downloaded javafx-media jar file and it is almost empty:

$ unzip javafx-media-13.jar 
Archive:  javafx-media-13.jar
   creating: META-INF/
  inflating: META-INF/MANIFEST.MF    

Why? Maybe I wrote wrong dependencies? What I have to do to make my application compile and work?



Solution 1:[1]

I have not tested it, but:

Replace:

    modules = [ 'javafx.controls', 'javafx.fxml' ]

With

    modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.media' ]

Solution 2:[2]

If you want to use MediaView control in javafx you must to do 2 steps

Step1: add requires javafx.media;

module com.codegym.videoplayerfx {
    requires javafx.controls;
    requires javafx.fxml;
    requires javafx.media; // You must add this line


    opens com.codegym.videoplayerfx to javafx.fxml;
    exports com.codegym.videoplayerfx;
}

Step2: Add dependency in pom.xml for maven (or build.gradle for gradle). After that you must press build. Try orther dependency version if does't work

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>16</version>
        </dependency>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MelvinWM
Solution 2 quangdang