-
Notifications
You must be signed in to change notification settings - Fork 941
Add module system support #484
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
Conversation
I think this could be made in more clean manner, e.g. putting I've tried doing this, but compiler was complaining that jackson is not in module path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compiler warns about 0 in module component (auth0), module name components can't end with digits. Not sure how to deal with this.
I assume you were also the author of the related JDK discuss thread where you already referred to the relevant JLS section:
The name of a module should correspond to the name of its principal exported package. If a module does not have such a package, or if for legacy reasons it must have a name that does not correspond to one of its exported packages, then its name should still start with the reversed form of an Internet domain with which its author is associated.
(Though this is only a convention and not required)
Since both the principal exported package is com.auth0.jwt
, and the domain of the author is auth0.com
, using com.auth0.jwt
as module name seems (in my opinion) to be the right choice.
The javac
warning is apparently created to prevent users from encoding version information in module names (see JDK-8176802 and JDK-8216185), however the warning message is pretty imprecise / irritating.
Since here the intention is not to encode version information, and this restriction is not part of the JLS, using auth0
should probably be fine.
Your changes currently put the module-info.class
in the top level directory of the JAR. This can cause issues for tools processing the content since the module-info.class
was compiled with Java 9 (see for example Gson issue where this is causing issues). It might be good to either create a Multi Release JAR (and put the class file in the Java 9 folder) or maybe create a separate artifact variant using Gradle.
There is a Gradle blog post about this, but I don't know if Gradle supports 'variants' as described in that post yet (and I am not very familiar with Gradle).
lib/src/main/java/module-info.java
Outdated
exports com.auth0.jwt; | ||
exports com.auth0.jwt.algorithms; | ||
exports com.auth0.jwt.exceptions; | ||
exports com.auth0.jwt.impl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe for the next major release the export for impl
should be removed? See #487
What do you maintainers think about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing it from opens will completely hide it from library users, it will break code if somebody depends on it
If it's for major release, then this could be changed right before major release, but i want to use this library with module system as soon as possible.
3c5dbe1
to
67a35bc
Compare
I have made it multi-release jar, so |
971f80c
to
63a08b7
Compare
Ready to merge if you are ok with how it's achieved |
We will be looking at this change this week. If it's something we want to add, we'll need to make sure the CI failures are addressed. Thanks, we'll follow up later this week. |
At first it failed because docker hub gave HTTP 50x error, now it failed because gradle download speed was very low, maybe it will work on third re-run. 🤷♂️ |
Change looks good - I don't love creating a multi-release jar, but as @Marcono1234 points out, without it there could be issues with tooling. I'm not sure how likely that is with this library, as it is not intended for Android use, and I see other libraries like Jackson include the |
@XakepSDK can you rebase your changes on the latest master, so we can get this change in to the next release? If not, we can plan to do it, though it may not make it into the next release. Thanks again for the contribution! |
I've tried and gradle refuses to work properly: java.lang.IllegalArgumentException: Unsupported class file major version 60 Looks like i have to use gradle 7.0, but some plugin uses deprecated features...
I think, i can make it work, but with Java 11, not Java 16 |
@XakepSDK, are you using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@XakepSDK do you need some help getting this rebased with the latest changes?
Should i hide |
ad239f9
to
67f3214
Compare
To the maintainers: It might be good to explicitly mention this in the changelog since it can be a breaking change for users of the module system which previously accessed classes from that package. |
Why not keep the |
Then jackson will become transitive dependency, because impl classes expose jackson classes This change shouldn't affect non-modularized projects. |
I understand it would be best to not export the impl package, and only impacts modularized projects, but we still do not want to introduce a breaking change. If someone were using this library in a modularized project, what would be the specific breaking change, and how would they address it? If this change cannot be done in a non-breaking way to provide value, then it's something we would consider for the next major version, but not in v3. |
Package
|
Thanks for those details. Given the change to not export the |
I would very much like the latter option (update PR instead of further delays): For 2.x, add jackson as a transitive requirement and export |
67f3214
to
3dd4925
Compare
Done. Exported impl and made jackson transitive. |
@XakepSDK I'm looking at this PR alongside @jimmyjames. Java Modules are fairly new to us and we've tried a few different combinations of parameters to test this PR with an app that was making use of "internal" classes. Here are our findings: JDK 8Targetting JDK 8 and thus not using modules, didn't cause any issues with our code. // build.gradle
sourceCompatibility = 8
targetCompatibility = 8 JDK 9With Java 9 we should have access to java modules. We declare a // src/java/module-info.java
module org.example {
requires com.auth0.jwt;
} Changing the source+target JDK to 9 caused the app to not compile but throw an "error: module not found: com.auth0.jwt". // build.gradle
sourceCompatibility = 9
targetCompatibility = 9 @jimmyjames pointed out there was a line needed in the configuration to make it not throw that error. We added the following lines to our // build.gradle
java {
// without it, the module com.auth0.jwt is not found
modularity.inferModulePath = true
} But that caused the Jackson module (transitive, as declared in this PR's module-info file) to not be found: "error: module not found: com.fasterxml.jackson.databind". Of course, adding the databind dependency in the We also found that we could use the "java.toolchain" DSL to specify the version. We did that instead of using the 2 lines we used before. java {
toolchain {
languageVersion = JavaLanguageVersion.of(9)
}
modularity.inferModulePath = true
} Unfortunately, the result was the same. The Jackson dependency would still be required as an explicit dependency added in the "dependencies" block. Targetting JDK 11We tested changing the java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
modularity.inferModulePath = true
} Our open questions:
We think it would be interesting if you can provide a sample app that you typically use to test module-enabled java apps. Attached you will find a zip with the one we crafted, with the characteristics detailed previously in the last scenario (JDK 11). It requires the changes on this branch exported to the local maven repository. You could do that by running To be clear, the PR diff looks OK, but we still want to perform some manual testing as this is completely new and out of our knowledge. Thanks! |
3dd4925
to
6e23944
Compare
I pushed change from |
Wouldn't this increase future incompatibilities? Usage of Jackson appears to be an internal implementation detail, if you now make it
I am not that familiar with the module system, but that is what I would expect for all Java versions. Maybe Gradle infers this information somehow, but the module system itself only defines the relationships between modules; it neither defines where the modules can be found, that is the job of the build tool (e.g. Maven, Gradle, or manually adding the JAR files), nor which version of a module is used, see also this StackOverflow question (actually it does encode the version, but you cannot directly specify versions of dependencies, see that StackOverflow question). |
It has to be |
If downstream projects use jackson themselves, they should depend on it directly. Relying on never-changing transitive dependencies is a configuration error. |
@XakepSDK Thanks for the pointers there! I've upgraded my test project's Gradle wrapper version to 7.1 and was able to remove the
Devs shouldn't be using that class directly. Hopefully, a follow-up major can improve a bit the package structure and prevent these implementation details to be exposed. But that's a change that we cannot include in this next minor. Earlier when we talked about exposing the "impl" package as part of the module, we agreed to keep it in case someone was using these classes today. Because, while them using it today is not our intention, it's still possible. If that's the case and there are devs out there using these classes directly, they must already be requiring the Jackson dependency on their own projects. Otherwise, they would be facing a "class not found" exception. If we change the scope of the Jackson dependency from |
6e23944
to
71593ff
Compare
71593ff
to
3bc2968
Compare
Can you share your test project for jdk9 and error you are getting?
Just install java-jwt in local repo and add it as a dependency, should work. Since it's decided to not switch from |
@XakepSDK @overheadhunter @Marcono1234 @jimmyjames thanks for the good conversation! We will include this PR in the next minor release. |
|
Changes
Compiler warns about 0 in module component (auth0), module name components can't end with digits. Not sure how to deal with this.
References
#483
Testing
Checklist