Skip to content

Java FX projekt add dependency failed #864

Open
@andteki

Description

@andteki

Since yesterday's "Project Manager for Java" release, additional dependencies added to JavaFX do not work.

I am making a Java FX project. This is based on Maven. It works.

When I add an extra dependency like Gson.

com.google.code.gson gson 2.11.0

I write in the code:

Gson gson = new Gson();

I import as usual.

The dependency cannot be used. VSCode says Gson cannot be resolved. It is there in the pom.xml file, and the import is also there in the code.

I saw that other people had previously written that, due to modularization, the following must be entered in the module-info.java file:

requires com.google.gson;

But even this instruction gives me trouble, you can't even find the module here.

I used it 3 days ago and there were no problems with it.

Activity

jdneo

jdneo commented on Nov 10, 2024

@jdneo
Member

Have you tried right click on the pom file and select Reload Project?

andteki

andteki commented on Nov 10, 2024

@andteki
Author

Hello jdneo!

Not before your message, but I tried. Of course it doesn't help.
I also tried "mvn clean install", etc.

But I have since narrowed down the problem. The error only occurs with the latest version of Gson, which is: 2.11.0

The problem only occurs when I use JavaFX. I see that the point is not JavaFX, but the modular program (module-info.java). I'm writing a simple Maven project that works non-modularly on Gson 2.11.0.

Let's stick with the modular JavaFX program:
If I switch back to the previous version of Gson, 2.10.1 or earlier, it works.

I looked into the Gson source code. Earlier versions of Gson are also modular. So it's not a problem. I see they introduced a new thing: proguard. I just suspect that might be causing the problem. I didn't go through it in detail.

The concrete phenomenon:

If you have this in pom.xml:

<dependency>
 <groupId>com.google.code.gson</groupId>
 <artifactId>gson</artifactId>
 <version>2.11.0</version>
</dependency>

I have a line like this in the module-info.java file:

 //...
 requires com.google.gson;
 opens com.example to javafx.fxml, com.google.gson, hu.szit.resclient;

After the word requires, com.google.gson is underlined in red. If I move the mouse towards it, it says:
"com.google.gson cannot be resolved to a module"

(
Gson 2.11.0 also works in NetBeans for Maven-based and modular JavaFX projects.
)

jdneo

jdneo commented on Nov 11, 2024

@jdneo
Member

Would you mind sharing a sample project for this issue?

andteki

andteki commented on Nov 11, 2024

@andteki
Author

Here it is:
https://github.com/andteki/samplefx.git

Now, the Gson version is 2.11.0, so not working.
If you write the version 2.10.1, then works.

https://central.sonatype.com/artifact/com.google.code.gson/gson

jdneo

jdneo commented on Nov 12, 2024

@jdneo
Member

Looks like it's a bug from upstream:

Related issues:
google/gson#2721
eclipse-jdt/eclipse.jdt.core#2495

For now the workaround is to use gson@2.10.1

Sorry for the inconvenience.

andteki

andteki commented on Nov 13, 2024

@andteki
Author

Thank you for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingupstream

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jdneo@andteki

        Issue actions

          Java FX projekt add dependency failed · Issue #864 · microsoft/vscode-java-dependency