Gson version
2.12.1
Java / Android version
JDK 21
Used tools
Description
In a downstream project we're trying to shade gson.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<artifactSet>
<includes>
<include>com.google.code.gson:gson</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>com.google.gson</pattern>
<shadedPattern>com.nimbusds.jose.shaded.gson</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>com.google.code.gson:gson</artifact>
<excludes>
<exclude>**/module-info.class</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
The class in question is correctly moved to com.nimbusds.jose.shaded.gson.internal.$Gson$Preconditions. However classes importing this are now broken and incorrectly do this:
import com.nimbusds.jose.shaded.gson.internal..Gson.Preconditions;
This leads to all kinds of follow-up bugs when trying to load these classes from the module path. Loading from class path is fine for some reason (I suspect the com.nimbusds.jose.shaded.gson.internal.. can't be matched by a corresponding exports statement in the module-info)
Expected behavior
relocated classes have a proper name
Actual behavior
the naming scheme breaks the shade plugin.
Reproduction steps
- Build https://bitbucket.org/connect2id/nimbus-jose-jwt/src/10.1/ (
mvn package -DskipTests)
- Unpack resulting jar
- Inspect
com.nimbusds.jose.shaded.gson.GsonBuilder
Exception stack trace
N/A
Clarification / Justification
I'm posting this in support of #1744. I am aware that you could argue this is an issue with the shade plugin. However, since other users reported this as a JLS violation I believe it is up to GSON to fix it.
According to 4efb133 the whole point of this naming scheme is to affect behaviour of some "IDE's auto import functionality". All modern IDEs have been respecting the module-info.java for several years now, so this rationale is obsolete, since com.nimbusds.jose.shaded.gson.internal is not exported.
Gson version
2.12.1
Java / Android version
JDK 21
Used tools
Description
In a downstream project we're trying to shade gson.
The class in question is correctly moved to
com.nimbusds.jose.shaded.gson.internal.$Gson$Preconditions. However classes importing this are now broken and incorrectly do this:This leads to all kinds of follow-up bugs when trying to load these classes from the module path. Loading from class path is fine for some reason (I suspect the
com.nimbusds.jose.shaded.gson.internal..can't be matched by a correspondingexportsstatement in the module-info)Expected behavior
relocated classes have a proper name
Actual behavior
the naming scheme breaks the shade plugin.
Reproduction steps
mvn package -DskipTests)com.nimbusds.jose.shaded.gson.GsonBuilderException stack trace
N/A
Clarification / Justification
I'm posting this in support of #1744. I am aware that you could argue this is an issue with the shade plugin. However, since other users reported this as a JLS violation I believe it is up to GSON to fix it.
According to 4efb133 the whole point of this naming scheme is to affect behaviour of some "IDE's auto import functionality". All modern IDEs have been respecting the
module-info.javafor several years now, so this rationale is obsolete, sincecom.nimbusds.jose.shaded.gson.internalis not exported.