-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add module descriptor #535
Comments
Until Gradle 7.0, the build system wasn't compatible and external plugins like bnd were not either. That blocked prior attempts to add the descriptor. The current blocker is that adding it in breaks Eclipse, which is where I do development. I don't know if this is a Gradle Buildship issue or Eclipse's. It is unable to handle a split project (main, test, jmh). I believe that the library's module com.github.benmanes.caffeine {
exports com.github.benmanes.caffeine.cache.stats;
exports com.github.benmanes.caffeine.cache;
requires transitive org.checkerframework.checker.qual;
requires transitive com.google.errorprone.annotations;
} However until there is proper support in the toolchain I don't know how to include it. One approach would be package into the jar as a generated resource, which is what I've seen Maven users do, but that seems error prone. |
If anyone wants to try and make this work a PR is welcome. |
Should annotations with runtime retention be transitive? Wouldn't be better to hide as much as possible? |
|
* Fixes ben-manes#535 * Uses Gradle Eclipse plugin to define add-reads options which satisfy Eclipse and make the project buildable through it in Eclipse 2021-03 Only the core caffeine module was eligible for a full module descriptor considering the circumstances: * A descriptor was not added to caffeine-guava because some of its tests rely on split packages in order to acccess Guava's package-private types. Ensuring a smooth experience in Eclipse IDE requires resolving these split packages. * The other modules still have some dependencies on filename-based modules, so it would be unwise to add module descriptors for them.
* Fixes ben-manes#535 * Uses Gradle Eclipse plugin to exclude module-info from compilation in Eclipse. Prevents hordes of issues.
* Fixes ben-manes#535 * Uses Gradle Eclipse plugin to exclude module-info from compilation in Eclipse. Prevents hordes of issues.
* Fixes #535 * Uses Gradle Eclipse plugin to exclude module-info from compilation in Eclipse. Prevents hordes of issues.
Released in 3.0.2 (thanks @A248!) |
I'm seeing build failures caused by this, as we explicitly exclude these dependencies in Maven:
@ben-manes suggested using Could this be fixed? |
Can you provide a reproduction? The static is in the descriptor. I’m not sure if this is a Maven bug or our misunderstanding. caffeine/caffeine/src/main/java/module-info.java Lines 1 to 7 in b498408
|
This explains that it is needed during application compilation, but not runtime. That’s unlike Maven’s provided scope where the dependency needed it at compile time only but consumers did not. It seems there is no equivalent. Maybe you can change scoping rather than exclude? |
@ben-manes Oh, apologies, I scanned over the module-info incorrectly, the Well, I guess then that approach of avoiding the leak of those annotation packages into the project/IDE auto-import won't work naymore. :-( |
@ben-manes I'll give it a try, but I fear this doesn't provide the desired semantics ... we pretty much depend on annotation declarations being optional in the JVMS and not providing the jar file at all, but I think this is not something that is conceptually supported by Java modules. |
I think you might need to have the exclusions and then also add the provided / optional dependencies explicitly with that scope setting. I don't think Maven's |
The problem is not at the level of Maven dependencies, but at the level of Java modules. Both |
Sorry, I kept thinking that this was a compilation failure due to excluding the dependency, rather than a runtime validation by the Java module system. If it is at runtime then there is no workaround. |
Yes, it's a compilation failure, but one based on the module system rules.
Yes, I think this too. Thanks for your thoughts and sorry for the noise, @ben-manes! |
My naive expectation is that if you could scope the dependencies at |
I think the problem here is that |
Btw, what's the reason for the I just realized that not even the modularized parts of my code would be safe from these dependencies due to |
I think it shouldn't have any influence on reflection, it only adds an invisible "requires com.google.errorprone.annotations..." to all modules that use caffeine. |
I've been following this conversation loosely, however I haven't been able to come up with any stellar solutions. I know IDEs have the ability to filter imports, but I am guessing that you want this handled by the build system? There are tools which can check your build for usage of certain classes. I think ArchUnit can do this for you, though I've never used it. PMD also has this feature. To the best of my knowledge, using I will ask for clarification on the jigsaw-dev mailing list to see if there's a more appropriate solution. |
I don't get this ... with that logic, wouldn't all dependencies be declared The only effect (I would argue that |
This may help for explanation: https://nipafx.dev/java-modules-implied-readability/ Ignoring annotations for a moment, suppose you have the following method in an exported package. If public Bar foo(); |
It really isn't – either the consumer refers to type I see nothing wrong with being explicit. If some module isn't required in the consumer's module-info file, I know it's not being used. That's a huge plus over Maven dependencies, where everything is transitive by default. Having modularized around 400 modules, I never felt the need to use |
Just FYI, use of Regardless, we'll receive helpful clarification from the jigsaw-dev mailing list with respect to handling annotation dependencies as used here. I've already sent them a message. Hopefully that will clear up any issue here. |
@A248 I don't think your message went through. You have to subscribe to the mailing list to post. |
@soc You are right that we don't need to use The jigsaw-dev members (Alex Buckley and Remi Forax specifically) confirmed that So, the caffeine module can be updated to remove the transitive declaration. |
Thanks @A248. Let's make the change then. You're welcome to send a PR or I'll make the changes at some point soon. |
@ben-manes Does #563 look as desired? |
@soc lgtm |
All's good from what I see, for what it's worth. |
fyi, there is a warning in the build that I am suppressing using
|
Should we ask jigsaw-dev about this? |
Sure, you are welcome to. They explicitly said annotations in the api don’t need to be transitive, so they might view this as ignorable or a bug. It’s certainly confusing and contradictory advice. |
I've mentioned this on jigaw-dev, so we'll find out what's happening here: |
This just bit me. A note for folks coming across the issue. The quickest fix is to downgrade from caffeine 3.0.2 to 3.0.1. Also, @ben-manes caffeine is awesome! Thanks for your continued work on it. |
Released in 3.0.3 |
Also, it seems that |
It might be valuable to briefly mention this in the 3.0.3 release notes. |
Switch to module descriptor from automatic module name, so this library will have full support of java module system
The text was updated successfully, but these errors were encountered: