google/gson

The module declaration in version 2.11.0 is not visible

eitan-rosenberg opened this issue · 11 comments

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,

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:

  • which exact build command you using
  • JDK version
  • Maven / Gradle version
  • operating system

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.

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.

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.

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

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

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.

"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

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)

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)