openjfx / javafx-gradle-plugin

Gradle plugin that makes it easy to work with JavaFX 11+
https://openjfx.io/
BSD 3-Clause "New" or "Revised" License
361 stars 62 forks source link

Both Mac and Win dependenies are imported even though docs state otherwise #65

Open madmas opened 5 years ago

madmas commented 5 years ago

Hi, the documentation says: " The plugin only includes binaries for the platform running the build. "

But when importing the project into IntelliJ on Mac, Gradle provides the dependencies for both win and mac:

grafik

This leads to the error that 'javafx.base' is provided twice:

grafik

What can I do to only have the platform-specific dependencies on my classpath?

DJViking commented 5 years ago

I am also seeing this problem on Linux. Dependencies for both Linux and Mac are fetched with Gradle.

javafx-controls.11.0.2.jar javafx-controls-linux.11.0.2.jar javafx-controls-mac.11.0.2.jar

I have been running on JavaFX 11 for a while now, and this has not had any adverse affect.

jperedadnr commented 5 years ago

While it shouldn't have adverse effects, it shouldn't happen in the first place. The main reason to find artifacts from wrong platforms is having dependencies of third party libraries that have transitive dependencies on JavaFX and published their artifacts without removing the platform classifier.

It is easy to avoid using implementation (....) { exclude group:org.openjfx }.

But it should be better if the library removed the classifiers from the pom. See for instance the publishing task of this library.

DJViking commented 5 years ago

I just found out that the library eu.hansolo:Medusa:11.1 is the cause in my case for fetching the Mac dependencies for JavaFX. I happened with a test project of mine without the gradle javafxplugin.

tobiasdiez commented 4 years ago

I just run into the same issue (on Windows also Mac and Linux versions are present). In fact, this leads to problems if you want to compile using Intellj as the binaries from the wrong OS are loaded into the module path, leading to problems that certain OS-specific implementation (e.g. platform loader) are not present.

Is there a work-around (except to manually remove the corresponding dependencies)?

tobiasdiez commented 4 years ago

I think this might actually be not a problem with the plugin. In fact, adding

compile group: 'org.openjfx', name: 'javafx-base', version: '14', classifier: 'mac'

manually in the gradle file, still loads the linux version as a dependency too. Could it be a problem with the pom? (I found it strange that each module declares itself as dependency)

eugener commented 4 years ago

There should be no JavaFX dependencies added manually. They should only be described in the javafx section like:

javafx {
    version = '14'
    modules = [ 'javafx.controls', 'javafx.fxml' ]
}

You will will see 2 sets of dependencies:

image As you see, transitive dependencies are added automatically too.

tobiasdiez commented 4 years ago

Thanks @eugener. The problem is that your code also loads the jar files from other OS for me. I guess this issue only occurs if you don't have the sdk installed since the plugin then loads these local files by default. https://github.com/openjfx/javafx-gradle-plugin/blob/c1e816ebbae56c30232a7bff043113c868c66103/src/main/java/org/openjfx/gradle/JavaFXOptions.java#L120-L127 I think there is nothing wrong with this code since manually adding these dependencies had the same effect that the os classifier was ignored

yevhenii-nadtochii commented 4 years ago

The same problem. On Linux I have platform-specific and independent jars. But on Windows linux-specific dependencies are present too.

tarehart commented 3 years ago

For me this caused jlink to fail:

Error: Two versions of module javafx.base found in C:\Users\tareh\code\cleopetra\build\jlinkbase\jlinkjars (javafx-base-11.0.2-win.jar and javafx-base-11.0.2-linux.jar)

I had controlsfx as one of my dependencies and it seems that was the culprit. I changed it to this (taking a cue from jperedadnr):

dependencies {
    implementation('org.controlsfx:controlsfx:11.0.3') {
        exclude group: 'org.openjfx'
    }
}

which got me past the problem. Thanks José!

wkgcass commented 1 year ago

I've also came into this problem, and I am both a library user and writer, and I've solved this from either perspective.
Since this issue is not closed yet, so I write my solution here for future reference:

For library users:

Try to add this too each dependency until compilation passes (then you can find out which library is to blame):

implementation('...') {
    exclude group: 'org.openjfx'
}

For library writers:

Add this to root at build.gradle

tasks.withType(GenerateModuleMetadata) {
    enabled = false
}

This prevents the generation of module.json or xxx.module, which will be used by gradle to retrieve the dependencies regardless of the pom.xml.


Add this inside publishing.publications.maven(MavenPublication) (same level as the pom {} block)

            pom.withXml {
                def pomNode = asNode()
                pomNode.dependencies.'*'.findAll() {
                    it.groupId.text() == 'org.openjfx'
                }.each {
                    it.parent().remove(it)
                    // you may also use: it.remove(it.classifier)
                }
            }

This removes the jfx dependencies from pom.xml (or you may only remove the classifiers).