Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java FX projekt add dependency failed #864

Open
andteki opened this issue Nov 7, 2024 · 6 comments
Open

Java FX projekt add dependency failed #864

andteki opened this issue Nov 7, 2024 · 6 comments
Labels
bug Something isn't working upstream

Comments

@andteki
Copy link

andteki commented Nov 7, 2024

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.

@jdneo
Copy link
Member

jdneo commented Nov 10, 2024

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

@andteki
Copy link
Author

andteki commented Nov 10, 2024

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
Copy link
Member

jdneo commented Nov 11, 2024

Would you mind sharing a sample project for this issue?

@andteki
Copy link
Author

andteki commented Nov 11, 2024

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
Copy link
Member

jdneo commented Nov 12, 2024

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.

@jdneo jdneo added bug Something isn't working upstream labels Nov 12, 2024
@andteki
Copy link
Author

andteki commented Nov 13, 2024

Thank you for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream
Projects
None yet
Development

No branches or pull requests

2 participants