gpt4 book ai didi

java - 在gradle应用中找不到ant-javafx

转载 作者:行者123 更新时间:2023-12-03 05:51:31 24 4
gpt4 key购买 nike

在使用JavaFX编写我的第一个应用程序时,我确保正确设置了JAVA_HOME,并将javafx-gradle-plugin包含到我的应用程序中,但是遇到了缺少ant-javafx-library的错误,该错误实际上可以在我的JDK中使用:(

我的build.gradle和错误消息味精如下:

// set up the kotlin-gradle plugin
buildscript {
ext.kotlin_version = '1.1.60'
repositories {
mavenLocal() // mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "de.dynamicfiles.projects.gradle.plugins:javafx-gradle-plugin:8.8.2"
}
}

// apply the kotlin-gradle plugin
apply plugin: "kotlin"
apply plugin: 'javafx-gradle-plugin'

// add kotlin-stdlib dependencies.
repositories {
mavenLocal() // mavenCentral()
}

dependencies {
//dependencies from a remote repositor
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "no.tornado:tornadofx:1.7.12"
compile "de.dynamicfiles.projects.gradle.plugins:javafx-gradle-plugin:8.8.2"
}

jar {
manifest {
//Define mainClassName as: '[your_namespace].[your_arctifact]Kt'
attributes ('Main-Class': 'MyAppKt', "Implementation-Title": "Gradle",
"Implementation-Version": 1)
}
// NEW LINE HERE !!!
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

sourceSets {
main.kotlin.srcDirs += 'src/kotlin'
main.resources.srcDirs += 'src/resources'
}

kotlin {
experimental.coroutines 'enable'
}

compileKotlin {
kotlinOptions.jvmTarget= 1.8 // optional, Minimum jvmTarget of 1.8 needed since Kotlin 1.1
kotlinOptions.suppressWarnings = true
}

enter image description here

最佳答案

通过从here下载javafx.plugin,我能够解决它。

然后创建一个“插件”文件夹,并在其中复制该文件。

最后,我将此插件安装为gradle.build:

apply from: "plugins/javafx.plugin"

所以,我最后的 gradle.build是:
// set up the kotlin-gradle plugin
buildscript {
ext.kotlin_version = '1.1.60'
repositories {
mavenLocal() // mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// classpath files('plugins/javafx.plugin')
}
}

// apply the kotlin-gradle plugin
apply plugin: "kotlin"
apply from: "plugins/javafx.plugin" // apply from: "http://dl.bintray.com/content/shemnon/javafx-gradle/8.1.1/javafx.plugin"

// add kotlin-stdlib dependencies.
repositories {
mavenLocal() // mavenCentral()
}

dependencies {
//dependencies from a remote repositor
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "no.tornado:tornadofx:1.7.12"
}


jar {
manifest {
//Define mainClassName as: '[your_namespace].[your_arctifact]Kt'
attributes ('Main-Class': 'MainKt', "Implementation-Title": "Gradle",
"Implementation-Version": 1)
}
// NEW LINE HERE !!!
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}


sourceSets {
main.kotlin.srcDirs += 'src/kotlin'
main.resources.srcDirs += 'src/resources'
}

kotlin {
experimental.coroutines 'enable'
}

compileKotlin {
kotlinOptions.jvmTarget= 1.8 // optional, Minimum jvmTarget of 1.8 needed since Kotlin 1.1
kotlinOptions.suppressWarnings = true
}

我的应用程序结构是:

enter image description here

更新
选项2

通过以下方式安装新的插件 here:
buildscript {
repositories {
mavenCentral() // or mavenLocal()
}
dependencies {
compile "de.dynamicfiles.projects.gradle.plugins:javafx-gradle-plugin:8.8.2"
}
}

如果对使用 mavenLocal()感兴趣,则可以使用以下命令下载:
mvn dependency:get -DrepoUrl=https://mvnrepository.com/artifact/de.dynamicfiles.projects.gradle.plugins/javafx-gradle-plugin/8.8.2 -Dartifact=de.dynamicfiles.projects.gradle.plugins:javafx-gradle-plugin:8.8.2

要获取 mvn命令行,您可以从 here下载它,将其添加到 path中,然后从任何地方调用它。

关于java - 在gradle应用中找不到ant-javafx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47484181/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com