You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于update4j的应用添加JavaFX依赖后执行generateBundle任务失败

Update4j + JavaFX 构建依赖解析错误解决方案

问题场景

开发基于Update4j的应用,引入JavaFX依赖后执行gradlew generateBundle任务,出现依赖解析失败错误。

当前Build.gradle.kts配置

plugins {
    application
    kotlin("jvm") version "1.8.21"
    id("ua.tiras.update4j-plugin") version "0.1.21"
    // others
    id("org.openjfx.javafxplugin") version "0.1.0"
}

buildscript {
    repositories {
        maven {
            setUrl("https://plugins.gradle.org/m2/")
        }
    }
    dependencies {
        classpath("org.openjfx:javafx-plugin:0.1.0")
    }
}
apply(plugin = "org.openjfx.javafxplugin")

javafx {
    setPlatform("win")
    version = "17.0.2"
    modules("javafx.controls", "javafx.fxml", "javafx.web", "javafx.media")
}

dependencies {
    // others 
    implementation("org.openjfx:javafx-controls:17.0.2:win")
    implementation("org.openjfx:javafx-fxml:17.0.2:win")
    implementation("org.openjfx:javafx-web:17.0.2:win")
    implementation("org.openjfx:javafx-media:17.0.2:win")
}

// others configs

update4j {
    // name of the generated config xml. optional, default: update.xml
    configurationFileName = "update.xml"
    // directory in which to find the files. mandatory!
    remoteLocation = "https://update.exaple.com"
    // launcher class. mandatory!
    launcherClass = "aaa.proj.Launcher"
    // use maven links in the update.xml. optional, default: true
    // if false, it copies all dependencies into the output folder
    useMaven = false
    basePath = "\${user.home}/aaaProj"
    artifactsConfiguration = "default"
    extraFiles = listOf(
        file("lib/jai_imageio.jar"),
        file("lib/morena.jar"),
        file("lib/morena_license.jar"),
        file("lib/morena_windows.jar")
    )
}

错误信息

Execution failed for task ':generateBundle'.
> 无法解析配置':default'的所有依赖项。
   > 无法解析org.openjfx:javafx-controls:17.0.8。
     被以下项目依赖:
         project :
      > 无法在org.openjfx:javafx-controls:17.0.8的以下变体中做出选择:
          - linux-aarch64Runtime
          - linuxRuntime
          - mac-aarch64Runtime
          - macRuntime
          - runtime
          - winRuntime
        所有变体均匹配消费者属性:
          - 变体'linux-aarch64Runtime'具备org.openjfx:javafx-controls:17.0.8能力:
              - 不匹配的属性:
                  - 提供org.gradle.category 'library'但消费者未要求
                  - 提供org.gradle.libraryelements 'jar'但消费者未要求
                  - 提供org.gradle.native.architecture 'aarch64'但消费者未要求
                  - 提供org.gradle.native.operatingSystem 'linux'但消费者未要求
                  - 提供org.gradle.status 'release'但消费者未要求
                  - 提供org.gradle.usage 'java-runtime'但消费者未要求
          - 变体'linuxRuntime'具备org.openjfx:javafx-controls:17.0.8能力:
              - 不匹配的属性:
                  - 提供org.gradle.category 'library'但消费者未要求
                  - 提供org.gradle.libraryelements 'jar'但消费者未要求
                  - 提供org.gradle.native.architecture 'x86-64'但消费者未要求
                  - 提供org.gradle.native.operatingSystem 'linux'但消费者未要求
                  - 提供org.gradle.status 'release'但消费者未要求
                  - 提供org.gradle.usage 'java-runtime'但消费者未要求
          - 变体'mac-aarch64Runtime'具备org.openjfx:javafx-controls:17.0.8能力:
              - 不匹配的属性:
                  - 提供org.gradle.category 'library'但消费者未要求
                  - 提供org.gradle.libraryelements 'jar'但消费者未要求
                  - 提供org.gradle.native.architecture 'aarch64'但消费者未要求
                  - 提供org.gradle.native.operatingSystem 'macos'但消费者未要求
                  - 提供org.gradle.status 'release'但消费者未要求
                  - 提供org.gradle.usage 'java-runtime'但消费者未要求
          - 变体'macRuntime'具备org.openjfx:javafx-controls:17.0.8能力:
              - 不匹配的属性:
                  - 提供org.gradle.category 'library'但消费者未要求
                  - 提供org.gradle.libraryelements 'jar'但消费者未要求
                  - 提供org.gradle.native.architecture 'x86-64'但消费者未要求
                  - 提供org.gradle.native.operatingSystem 'macos'但消费者未要求
                  - 提供org.gradle.status 'release'但消费者未要求
                  - 提供org.gradle.usage 'java-runtime'但消费者未要求

解决方案

1. 统一JavaFX版本

错误中解析的是17.0.8版本,但配置里指定的是17.0.2,版本不一致导致冲突。确保所有JavaFX相关配置版本统一:

  • 保持javafx块中的version = "17.0.2"
  • 检查项目中其他依赖,将所有17.0.8版本的JavaFX依赖替换为17.0.2

2. 移除重复的JavaFX依赖声明

org.openjfx.javafxplugin插件会根据javafx块配置自动添加对应平台的依赖,手动在dependencies块中添加的implementation声明属于重复配置,直接删除:

// 删除以下重复依赖
implementation("org.openjfx:javafx-controls:17.0.2:win")
implementation("org.openjfx:javafx-fxml:17.0.2:win")
implementation("org.openjfx:javafx-web:17.0.2:win")
implementation("org.openjfx:javafx-media:17.0.2:win")

3. 调整Update4j的artifactsConfiguration

update4j块中artifactsConfiguration = "default"指定的配置未包含JavaFX的运行时变体,改为使用runtimeClasspath配置,该配置包含运行时所需的所有依赖(包括平台特定的JavaFX变体):

update4j {
    // ... 其他配置
    artifactsConfiguration = "runtimeClasspath"
    // ... 其他配置
}

4. 明确指定平台属性(可选)

若上述步骤仍有问题,在项目根目录的gradle.properties中添加以下属性,强制Gradle解析Windows平台的依赖:

org.gradle.jvmArgs=-Dorg.gradle.native.platform=windows
org.gradle.native.architecture=x86-64

修改后的完整配置示例

plugins {
    application
    kotlin("jvm") version "1.8.21"
    id("ua.tiras.update4j-plugin") version "0.1.21"
    id("org.openjfx.javafxplugin") version "0.1.0"
}

buildscript {
    repositories {
        maven {
            setUrl("https://plugins.gradle.org/m2/")
        }
    }
    dependencies {
        classpath("org.openjfx:javafx-plugin:0.1.0")
    }
}

javafx {
    setPlatform("win")
    version = "17.0.2"
    modules("javafx.controls", "javafx.fxml", "javafx.web", "javafx.media")
}

dependencies {
    // 保留其他非JavaFX依赖
}

update4j {
    configurationFileName = "update.xml"
    remoteLocation = "https://update.exaple.com"
    launcherClass = "aaa.proj.Launcher"
    useMaven = false
    basePath = "\${user.home}/aaaProj"
    artifactsConfiguration = "runtimeClasspath"
    extraFiles = listOf(
        file("lib/jai_imageio.jar"),
        file("lib/morena.jar"),
        file("lib/morena_license.jar"),
        file("lib/morena_windows.jar")
    )
}

内容的提问来源于stack exchange,提问作者Paweł Dziełak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 16:25:54