简体   繁体   中英

Gradle - Add JavaFX SDK to classpath

I am using gradle in Eclipse , and my gradle.build is pretty basic (adds java plugin, sets repos and not alot more) and I am building a JavaFX program. All my code compiles and run correctly with my build scripts with 0 errors.

I am just annoyed at the fact when I add the JavaFX SDK to my build path libraries, I can see my project has it listed. When I sync my project with Gradle, gradle removes this SDK from my classpath file.

What do I need to add to my build script to stop this from happening and gradle to normally inject it into my .classpath as it does with anything else I add?

Cheers,

PS I'm really new to gradle and groovy and this is my first 'project' working with it. Apart from this one annoyance, it's been smooth going.

Solved this issue: completely forgot classpath is todo witth eclipse and not java/gradle.

Adding:

apply plugin: 'eclipse'

eclipse {
    classpath.containers 'org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER'
}

to my gradle.build file solved this issue.

I actually found a solution for this via https://groups.google.com/forum/#!topic/javafxports/Fn92C5ysC60 'android forum' while looking up how I could automate the building of eclipse.

Cheers if anyone looked into this.


As a side note, as I was confused about this first: A JavaFX project is no different from a Java project and you don't need to specify the fact you're using JavaFX to your ide to be able to execute JavaFX code. So I was confused why my IDE had a 'Start a new JavaFX project' and 'Start a new Gradle Project' but no JavaFX/Gradle project.

You don't 'need' a JavaFX plugin like my project originally had either.

To solve your problem, you need JavaFX-Gradle-plugin , it's a plugin that enable JavaFX support on Gradle project.

This is the link of plugin: https://github.com/FibreFoX/javafx-gradle-plugin , where you can find all infos and example...

All of you need is to start a new Gradle project, then add to your file build.gradle this code:

buildscript {
    dependencies {
        classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.8.2'
    }
    repositories {
        mavenLocal()
        mavenCentral()
    }
}
apply plugin: 'java'

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies{
    // put here your project dependencies
}

apply plugin: 'javafx-gradle-plugin'

// these values are the examples and defaults
// you won't need them all

// configure javafx-gradle-plugin
jfx {

    // minimal requirement for jfxJar-task
    mainClass = 'YOUR.MAIN.CLASS'

    // minimal requirement for jfxNative-task
    vendor = 'YOUR NAME OR COMPANY'

    // some optional task
    jfxAppOutputDir = 'build'
    jfxMainAppJarName = 'YOUR APPLICATION NAME.jar'
    manifestAttributes = [
        "Specification-Version": 1.0,
        "Implementation-Version": 1,
        "Built-By": "YOUR NAME OR COMPANY",
    ]
    // for a full list of available settings, look the class "JavaFXGradlePluginExtension" on plugin project
}

This is the only plugin that I've found for use JavaFX with Gradle. I'm working with Eclipse on project with same problem, and I've solved it a few days ago.

Hope this help,

BoGnY

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM