【问题标题】:how do I add JavaFX to a gradle build file using Kotlin DSL?如何使用 Kotlin DSL 将 JavaFX 添加到 gradle 构建文件?
【发布时间】:2020-02-18 04:25:39
【问题描述】:

如何通过gradle添加javafx依赖?

thufir@dur:~/NetBeansProjects/helloWorldJavaFX$ 
thufir@dur:~/NetBeansProjects/helloWorldJavaFX$ gradle clean

> Configure project :
e: /home/thufir/NetBeansProjects/helloWorldJavaFX/build.gradle.kts:13:7: Unresolved reference: openjfx

FAILURE: Build failed with an exception.

* Where:
Build file '/home/thufir/NetBeansProjects/helloWorldJavaFX/build.gradle.kts' line: 13

* What went wrong:
Script compilation error:

  Line 13:   org.openjfx.javafxplugin
                 ^ Unresolved reference: openjfx

1 error

* 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

BUILD FAILED in 1s
thufir@dur:~/NetBeansProjects/helloWorldJavaFX$ 

manual 说:

plugins {
  id 'application'
  id 'org.openjfx.javafxplugin' version '0.0.7'
}

我的构建文件有:

plugins {
    // Apply the java plugin to add support for Java
    java

  org.openjfx.javafxplugin

    // Apply the application plugin to add support for building an application
    application
}

产生上述错误。

【问题讨论】:

  • 你检查插件的repository了吗?还有 Kotlin DSL。
  • 我会更新问题(DSL语法让我感到困惑)

标签: gradle javafx dependencies build.gradle gradle-kotlin-dsl


【解决方案1】:

plugins-部分你必须放

id("org.openjfx.javafxplugin") version "0.0.8"

而不仅仅是org.openjfx.javafxplugin

之后你可以放一个javafx-section 之类的

javafx {
    modules("javafx.controls", "javafx.fxml")
}

某处(我更喜欢把它放在dependency-部分旁边)。在这里你可以放入你需要的任何模块。

有关更多配置选项,请查看JavaFX Gradle Plugin

【讨论】:

  • 你真的让我头疼了好几个小时,非常感谢!
猜你喜欢
  • 1970-01-01
  • 2019-03-06
  • 2019-04-29
  • 2018-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多