【问题标题】:Maven javafx plugin creating duplicate dependenciesMaven javafx插件创建重复依赖项
【发布时间】:2022-01-22 05:21:08
【问题描述】:

我正在尝试使用 maven 创建 JavaFX 应用程序,但似乎 JavaFX 插件正在创建重复的依赖项。这是在 mvn javafx:ru​​n 期间吐出的内容

[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.openjfx:javafx-graphics:jar:win -> duplicate declaration of version 17.0.0.1 @ line 129, column 17
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.openjfx:javafx-graphics:jar:win -> duplicate declaration of version 17.0.0.1 @ line 141, column 17
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.openjfx:javafx-base:jar:win -> duplicate declaration of version 17.0.0.1 @ line 153, column 17
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.openjfx:javafx-base:jar:win -> duplicate declaration of version 17.0.0.1 @ line 165, column 17
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.openjfx:javafx-controls:jar:win -> duplicate declaration of version 17.0.0.1 @ line 189, column 17

而在我的 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>me.xxx</groupId>
    <artifactId>xxx</artifactId>
    <version>1.0-ALPHA</version>
    <name>xxx-DEV-1</name>

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

    <repositories>
        <repository>
            <id>charm-glisten</id>
            <name>charm-glisten Repository</name>
            <url>https://nexus.gluonhq.com/nexus/content/repositories/releases/</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>17.0.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>17.0.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-web</artifactId>
            <version>17.0.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.controlsfx</groupId>
            <artifactId>controlsfx</artifactId>
            <version>11.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dlsc.formsfx</groupId>
            <artifactId>formsfx-core</artifactId>
            <version>11.3.2</version>
            <exclusions>
                <exclusion>
                    <groupId>org.openjfx</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>net.synedra</groupId>
            <artifactId>validatorfx</artifactId>
            <version>0.1.13</version>
            <exclusions>
                <exclusion>
                    <groupId>org.openjfx</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.kordamp.bootstrapfx</groupId>
            <artifactId>bootstrapfx-core</artifactId>
            <version>0.4.0</version>
        </dependency>
        <dependency>
            <groupId>eu.hansolo</groupId>
            <artifactId>tilesfx</artifactId>
            <version>11.48</version>
            <exclusions>
                <exclusion>
                    <groupId>org.openjfx</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </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>

    </dependencies>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.7</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running with: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>me.xxx.xxx.xxx</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

我显然没有两次列出任何这些依赖项。我做错了什么?

这是模块信息:

module  me.xxx.xxx{
    requires javafx.controls;
    requires javafx.fxml;
    requires javafx.web;

    requires org.controlsfx.controls;
    requires com.dlsc.formsfx;
    requires validatorfx;
    requires org.kordamp.bootstrapfx.core;
    requires eu.hansolo.tilesfx;


    exports me.xxx.xxx;
}

【问题讨论】:

  • 在Idea中,我使用new JavaFX project wizard创建了一个新项目,选择openjfx 17.0.1。然后,我将向导生成的 pom.xml 文件替换为您提供的 pom.xml(没有任何更改),并将 maven 项目与 idea 项目重新同步。然后它构建并运行良好 mvn:install 和 Idea 运行图标(根据 Idea New JavaFX 项目说明在排水沟中的箭头)。我对生成的项目进行了一些依赖性分析,没有任何问题。测试是在 OS X 11 上完成的。
  • 我也尝试过使用 mvn javafx:ru​​n 命令,它对我来说很好,没有警告或问题。为了让它工作,我需要将插件的依赖关系从 0.0.7 更新到 0.0.8,因为插件的 0.0.7 版本与 Idea 中使用的 Maven 设置之间存在不相关的权限不兼容。否则,设置与之前的评论相同。
  • 根据其documentation,openjfx maven 插件使用maven toolchains 系统查找要使用的JDK。
  • 如果您想使用mvn javafx:run 执行运行命令(而不是直接使用java 命令从模块路径运行生成的jar),然后检查您的maven 是否已安装并且JAVA_HOME根据maven installation instructions 配置,并且(如果需要)toolchains 配置为覆盖(仅当您需要覆盖或明确指定要使用的 java home 或 jdk 时)。从系统中删除旧的 JDK,例如 JDK 8。

标签: java maven javafx


【解决方案1】:

我曾经遇到过类似的问题。您可以尝试将您的“openjfx 排除”也添加到 controlsfx 吗?在我的情况下这是必要的。

【讨论】:

  • 我将排除字段添加到所有其他依赖项中,仍然得到多个重复项:/
  • 只是为了避免误会。一般来说,根本不需要提供这些排除。我的 controlsfx 案例有点特殊,因此我认为它对您的案例也可能有所帮助。
【解决方案2】:

问题在于 maven 使用多个 JDK 来编译源代码。

删除旧的 JDK 8 解决了这个问题

【讨论】:

    猜你喜欢
    • 2012-03-06
    • 1970-01-01
    • 2017-07-29
    • 2013-07-19
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    • 2012-01-15
    • 2015-05-12
    相关资源
    最近更新 更多