【问题标题】:could not find ant-javafx in gradle app在 gradle 应用程序中找不到 ant-javafx
【发布时间】:2017-11-25 08:54:20
【问题描述】:

在使用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
}

【问题讨论】:

    标签: java gradle javafx


    【解决方案1】:

    我可以通过从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
    }
    

    我的应用结构是:

    更新 选项 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,然后从任何地方调用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-19
      • 2013-11-02
      • 1970-01-01
      • 2015-11-12
      • 2015-10-02
      • 1970-01-01
      • 1970-01-01
      • 2015-10-23
      相关资源
      最近更新 更多