Closed reini2150 closed 3 years ago
There is not actually a reason. It's a mistake
This should be complete in 3.11.04
3.11.04 standalone appears to have still a problem. Just found that the class kong.unirest.JsonObjectMapper imports com.google.gson.* META-INF\maven contains folders and pom.xml of the unshaded dependencies. So Maven still thinks that unirest has these external dependencies when e.g. viewed in eclipse's dependency hierachy panel.
I think thats the problem with Eclipse maybe. If you crack open the jar you will see that the google classes (and the apache classes) are not in the normal packages but in shaded directories. The point is not to not have the dependency but to avoid classloader issues. I'm not fully aware of what magic takes place in the classloader to make it look in the moved directory rather than in com/google.
If you can suggest where our setup is wrong I'm open to change
If your goal is to NOT have gson at all, you should not use the shaded jar and should instead exclude gson in your pom. However this will result in you not being able to use any of the JSON functionality
Ok, I did not know about that. So you can still reference in your source the com.google.gson.Gson class but at runtime the classloader eventually takes the unirest.shaded.com.googlegson.Gson version? That's really magic.
That's always been the way I've done it. The compiler isn't aware of the moved dependency AFAIK and google's own code of course continues to reference itself in the expected com/google packages. The shader just moved stuff it doesn't recompile everything
OK, so I was wrong about how the plugin works, apparently it DOES rewrite the bytecode: https://medium.com/@akhaku/java-class-shadowing-and-shading-9439b0eacb13
I also noticed something weird about the way it was configured. The namespaces were being jammed together because we didn't have a .
on the end of the relocation. I fixed that in 3.11.05 which will be in maven central in the next hour or so
Just tried the new standalone jar with the hope to get rid of the dependenyManagement of gson 2.8.6 and commons-codec 1.11
in my projects pom.xml. But only the org.apache.http dep is shaded. Obviously there must be a reason but maybe you could also provide a "full" shaded with another classifier?