google / gson

A Java serialization/deserialization library to convert Java Objects into JSON and back
Apache License 2.0
23.13k stars 4.27k forks source link

The module declaration in version 2.11.0 is not visible #2679

Closed eitan-rosenberg closed 1 month ago

eitan-rosenberg commented 1 month ago

The module declaration in version 2.11.0 is not visible, in contrast to version 2.10.1

Cannot use "requires com.google.gson;" in existing code like I used to.

Please help,

Marcono1234 commented 1 month ago

The module declaration is still under META-INF/versions/9/module-info.class inside the JAR, so nothing has changed regarding this between version 2.10.1 and 2.11.0.

Is only your IDE showing this error, or do you get this error also when you run the build tool (probably Maven or Gradle) from command line?

If this also occurs with Maven or Gradle, could you please try to create a small self-contained demo repository which showcases this issue? Please mention:

eitan-rosenberg commented 1 month ago

I am aware that you are using multi-release jar and I noticed META-INF/versions/9/module-info.class.(this is also the case in 2.10.1) My environment: Eclipse 2024-03 (4.31). M2E Maven Integration for Eclipse Core 2.6.0.20240220-1109 Java openjdk-22.0.1_windows-x64_bin.zip Maven 3.9.6.

I created a small Maven project. (included)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>ModuleTest</groupId>
    <artifactId>ModuleTest</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>22</maven.compiler.source>
        <maven.compiler.target>22</maven.compiler.target>
    </properties>

    <dependencies>

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

    </dependencies>

</project>

When using 2.10.1 every thing is ok.

2024-05-23_08-51-31

When using 2.11.0 it fails.

2024-05-23_08-59-56

ModuleTest.zip

Thanks in advance.

eitan-rosenberg commented 1 month ago

Update...

I checked both jars: the jar compression is not the same:

2024-05-23_15-35-17 2024-05-23_15-33-50

Repacking 2.11.0 make the jar usable.

Marcono1234 commented 1 month ago

But does this error only occur within Eclipse, or also when you run mvn clean test?

If I use the ModuleTest.zip you have attached, change the Gson dependency version to 2.11.0, and then run mvn clean test (with Docker image maven:3.9.6-eclipse-temurin-22-alpine), then it compiles without problems for me.

I think we are using standard Maven plugins for JAR creation. Since last Gson version we upgraded the maven-jar-plugin and moditect-maven-plugin, and made the build reproducible (#2543).

Maybe this should rather be reported as bug for Eclipse.

Just to be sure, did you run "Maven" > "Update Project..." in Eclipse after you changed the dependency? I think it should have done that automatically though.

Marcono1234 commented 1 month ago

And could you please check Eclipse's "Error Log" as well ("Window" > "Show View" > "Other..." > "General" > "Error Log") if it contains any related errors?

eitan-rosenberg commented 1 month ago

And could you please check Eclipse's "Error Log" as well ("Window" > "Show View" > "Other..." > "General" > "Error Log") if it contains any related errors? Nothing there. I even change the JDK: 2024-05-24_05-45-16

eitan-rosenberg commented 1 month ago

I can live with :

module moduleTest {

    exports myClasses;

    exports main;

//  requires com.google.gson;

    requires gson;

}

Have you considered using "Automatic-Module-Name" ? Even org.apache.commons.lang3 use it.

eitan-rosenberg commented 1 month ago

"But does this error only occur within Eclipse, or also when you run mvn clean test?"

Running "mvn clean test" from the command line works !!!!

I will report to the people in https://github.com/eclipse-m2e/m2e-core

eitan-rosenberg commented 1 month ago

Thanks

Marcono1234 commented 1 month ago

When you create the https://github.com/eclipse-m2e/m2e-core issue, can you please add a link there to this Gson issue here? It might help the m2e maintainers, and it will help anyone else who sees this Gson issue here to find the corresponding m2e issue.

Also, have you tried right-clicking the project in Eclipse and selecting "Maven" > "Update Project...", which I suggested above? (just to be sure)

eitan-rosenberg commented 1 month ago

Also, have you tried right-clicking the project in Eclipse and selecting "Maven" > "Update Project...", which I suggested above? (just to be sure) I do that every time I open a project (alt+f5)