升级JavaFX Gradle插件后下载源码遇变体选择错误求助
问题分析:JavaFX Gradle插件0.1.0版本源码下载失败
升级org.openjfx.javafxplugin至0.1.0版本后,尝试下载JavaFX源码时出现以下错误:
Execution failed for task ':ijDownloadSourceseac56644-f3d'. > Could not resolve all files for configuration ':downloadSources_d8a57fab-051b-40e6-9c30-2d1f5d9d5ae1'. > Could not resolve org.openjfx:javafx-fxml:21. Required by: project : > Cannot choose between the following variants of org.openjfx:javafx-fxml:21: - linux-aarch64Runtime - linuxRuntime - mac-aarch64Runtime - macRuntime - runtime - winRuntime All of them match the consumer attributes: - Variant 'linux-aarch64Runtime' capability org.openjfx:javafx-fxml:21: - Unmatched attributes: - Provides org.gradle.category 'library' but the consumer didn't ask for it - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it - Provides org.gradle.native.architecture 'aarch64' but the consumer didn't ask for it - Provides org.gradle.native.operatingSystem 'linux' but the consumer didn't ask for it - Provides org.gradle.status 'release' but the consumer didn't ask for it - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it - Variant 'linuxRuntime' capability org.openjfx:javafx-fxml:21: - Unmatched attributes: - Provides org.gradle.category 'library' but the consumer didn't ask for it - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it - Provides org.gradle.native.architecture 'x86-64' but the consumer didn't ask for it - Provides org.gradle.native.operatingSystem 'linux' but the consumer didn't ask for it - Provides org.gradle.status 'release' but the consumer didn't ask for it - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it - Variant 'mac-aarch64Runtime' capability org.openjfx:javafx-fxml:21: - Unmatched attributes: - Provides org.gradle.category 'library' but the consumer didn't ask for it - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it - Provides org.gradle.native.architecture 'aarch64' but the consumer didn't ask for it - Provides org.gradle.native.operatingSystem 'macos' but the consumer didn't ask for it - Provides org.gradle.status 'release' but the consumer didn't ask for it - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it - Variant 'macRuntime' capability org.openjfx:javafx-fxml:21: - Unmatched attributes: - Provides org.gradle.category 'library' but the consumer didn't ask for it - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it - Provides org.gradle.native.architecture 'x86-64' but the consumer didn't ask for it - Provides org.gradle.native.operatingSystem 'macos' but the consumer didn't ask for it - Provides org.gradle.status 'release' but the consumer didn't ask for it - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it - Variant 'runtime' capability org.openjfx:javafx-fxml:21: - Unmatched attributes: - Provides org.gradle.category 'library' but the consumer didn't ask for it - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it - Provides org.gradle.status 'release' but the consumer didn't ask for it - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it - Variant 'winRuntime' capability org.openjfx:javafx-fxml:21: - Unmatched attributes: - Provides org.gradle.category 'library' but the consumer didn't ask for it - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it - Provides org.gradle.native.architecture 'x86-64' but the consumer didn't ask for it - Provides org.gradle.native.operatingSystem 'windows' but the consumer didn't ask for it - Provides org.gradle.status 'release' but the consumer didn't ask for it - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. For more on this, please refer to https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation. BUILD FAILED in 111ms 1 actionable task: 1 executed
已尝试配置osConfiguration但问题依旧,当前build.gradle配置如下:
import org.openjfx.gradle.JavaFXPlatform plugins { id 'java' id 'application' id 'org.javamodularity.moduleplugin' version '1.8.12' id 'org.openjfx.javafxplugin' version '0.1.0' id "com.google.osdetector" version "1.7.3" id 'org.beryx.jlink' version '3.0.1' id "io.freefair.lombok" version "8.6" } group 'io.github.vcvitaly' version '1.0-SNAPSHOT' repositories { mavenCentral() } ext { junitVersion = '5.10.2' platform = getPlatform() } configurations { osConfiguration } java { sourceCompatibility = JavaVersion.VERSION_21 targetCompatibility = JavaVersion.VERSION_21 } tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } application { mainModule = 'io.github.vcvitaly.k8cp' mainClass = 'io.github.vcvitaly.k8cp.HelloApplication' } javafx { version = JavaVersion.VERSION_21 modules = ['javafx.controls', 'javafx.fxml'] } dependencies { implementation('org.controlsfx:controlsfx:11.1.2') implementation('net.synedra:validatorfx:0.4.0') { exclude(group: 'org.openjfx') } implementation('org.kordamp.ikonli:ikonli-javafx:12.3.1') implementation 'org.kordamp.ikonli:ikonli-fontawesome-pack:12.3.1' implementation 'org.kordamp.ikonli:ikonli-fontawesome5-pack:12.3.1' implementation('org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0') implementation 'ch.qos.logback:logback-core:1.5.2' implementation 'org.slf4j:slf4j-api:2.0.12' implementation 'ch.qos.logback:logback-classic:1.5.2' implementation ("io.kubernetes:client-java:20.0.0") { exclude group: "com.google.code.findbugs", module: "jsr305" exclude group: "com.amazonaws", module: "aws-java-sdk-sts" } testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}" testImplementation "org.junit.jupiter:junit-jupiter-params:${junitVersion}" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}" testImplementation 'org.mockito:mockito-core:5.11.0' testImplementation "org.assertj:assertj-core:3.25.1" } test { useJUnitPlatform() } jlink { imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip") options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages'] launcher { name = 'app' } } jlinkZip { group = 'distribution' } configurations.osConfiguration { attributes { attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named(OperatingSystemFamily, platform.osFamily)) attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named(MachineArchitecture, platform.arch)) } } def getPlatform() { return JavaFXPlatform.detect(osdetector); }
配置未生效的原因分析
1. 自定义配置未关联到源码下载任务
错误中的任务是ijDownloadSourcesxxx,对应的Gradle配置是downloadSources_xxx,而你定义的osConfiguration是独立的自定义配置,没有对源码下载的配置产生任何影响,自然无法解决变体选择问题。
2. 属性类型不匹配
你为osConfiguration设置的是Usage.JAVA_RUNTIME属性,但源码下载任务需要的是编译时/源码变体(对应Usage.JAVA_API或源码专属属性)。JavaFX的源码包是和特定平台的编译时变体绑定的,而非运行时变体,属性类型不匹配导致配置无效。
3. 新版本插件的逻辑变化
org.openjfx.javafxplugin 0.1.0版本可能已经调整了变体处理逻辑,不再需要手动创建osConfiguration,而是通过插件自身的platform属性自动处理平台适配。但源码下载任务没有继承插件的平台配置,导致无法自动匹配对应平台的源码变体。
解决方案建议
方案1:让JavaFX插件自动处理平台
移除自定义的osConfiguration,直接在javafx块中指定平台:
javafx { version = JavaVersion.VERSION_21 modules = ['javafx.controls', 'javafx.fxml'] // 显式传入检测到的平台,让插件自动关联对应变体 platform = getPlatform() }
方案2:为源码下载配置添加属性
直接针对所有downloadSources开头的配置设置属性,确保匹配对应平台的源码变体:
configurations.matching { it.name.startsWith('downloadSources') }.each { config -> config.attributes { attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_API)) attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named(OperatingSystemFamily, platform.osFamily)) attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named(MachineArchitecture, platform.arch)) } }
方案3:检查模块化插件冲突
新版本JavaFX插件可能已经内置了模块化支持,尝试移除org.javamodularity.moduleplugin,避免插件间的变体处理逻辑冲突。
内容的提问来源于stack exchange,提问作者Vitaly Chura
相关产品推荐
相关产品推荐

