javamavenjavafx

Maven project fails to resolve JavaFX dependencies


I would need some advice on how to troubleshoot this issue I'm having with my project, so there's not going to be a minimal reproducible code example, as it's not about the code itself.

Maven and Java are properly setup and working on all machines and OSes. Project was initially created with IntelliJ on Linux and working on any Linux machine without issues. However, trying to run mvn clean install on Windows or macOS on the project will always result in the following error:

[ERROR] Failed to execute goal on project RNGame: Could not resolve dependencies for project com.ceebee:RNGame:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: org.openjfx:javafx-controls:jar:${javafx.platform}:21.0.3 (absent), org.openjfx:javafx-graphics:jar:${javafx.platform}:21.0.3 (absent), org.openjfx:javafx-base:jar:${javafx.platform}:21.0.3 (absent), org.openjfx:javafx-fxml:jar:${javafx.platform}:21.0.3 (absent), org.openjfx:javafx-media:jar:${javafx.platform}:21.0.3 (absent): Could not find artifact org.openjfx:javafx-controls:jar:${javafx.platform}:21.0.3 in central (https://repo.maven.apache.org/maven2)

This is my current pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.ceebee</groupId>
    <artifactId>RNGame</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>RNGame</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit.version>5.8.2</junit.version>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx</artifactId>
            <version>21.0.3</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>21.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>21.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>21.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.32</version>
                <scope>provided</scope>
            </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.17.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <source>20</source>
                    <target>20</target>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>1.18.32</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running with: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>com.ceebee.rngame/com.ceebee.rngame.RNGame</mainClass>
                            <launcher>RNGame.sh</launcher>
                            <jlinkZipName>RNGame</jlinkZipName>
                            <jlinkImageName>RNGame</jlinkImageName>
                            <stripDebug>true</stripDebug>
                            <stripJavaDebugAttributes>true</stripJavaDebugAttributes>
                            <noManPages>true</noManPages>
                            <stripDebug>true</stripDebug>
                            <noHeaderFiles>true</noHeaderFiles>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <id>copy-external-resources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/res</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>res</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

I'm on both macOS 13.4.1 and Windows 10. Here is the output of mvn --version for mac including all necessary info:

Apache Maven 3.9.7 (8b094c9513efc1b9ce2d952b3b9c8eaedaf8cbf0) Maven home: /usr/local/Cellar/maven/3.9.7/libexec Java version: 21.0.3, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk/21.0.3/libexec/openjdk.jdk/Contents/Home Default locale: en_GB, platform encoding: UTF-8 OS name: "mac os x", version: "13.4.1", arch: "x86_64", family: "mac"

Maven version on Linux is 3.9.6. I haven't found much info on this particular issue online. My environments are set up all the same way on every machine. The project can be build just fine on any other Linux machine, but not Windows/macOS. The related JavaFX artifacts are being downloaded and are present in the .m2 directory, yet Maven can't seem to resolve them. There are no specific Maven settings in place. The hint about {javafx.platform} doesn't help me much, as specifying this property as e.g. <classifier>mac</classifier> doesn't help.

All setups are fresh on Windows/macOS with proper environment variables and java and mvn commands being recognised on the command line/terminal. Any pointers on how to go on about this issue would be appreciated.


Solution

  • I face the exact same issue when using maven 3.9.7. It still works with maven 3.9.6.

    A maven ticket already exists https://issues.apache.org/jira/browse/MNG-8131