extra-java-module-info
extra-java-module-info copied to clipboard
Consider adding 'opens(...)' to module DSL
Hi,
I've been looking around, and call me stupid, but I can't seem to find a way to add the "opens package;" to the module-info file.
Is this intentional and is there a proper replacement?
@Wexalian there's no functionality to explicitly declare a package as "open" for a friendly module; however, all generated module-info
descriptors have the open attribute set by default so that all the available classes in a patched JAR will be available for reflective access.
https://github.com/jjohannes/extra-java-module-info/blob/213be49eed8e53692fa38f0ad587794433499141/src/main/java/de/jjohannes/gradle/javamodules/ExtraModuleInfoTransform.java#L192
Thanks for pointing that out @iherasymenko.
IIRC I did it like that with the reasoning that if you patch a Jar that was never intended to be a Module in the first place, you probably need everything to be open for it being still workable.
However, if there is a use case for doing it differently, I think the plugin could be easily extended with something like this:
module("commons-cli-1.4.jar", "org.apache.commons.cli", "3.2.2") {
openModule.set(false) // The convention/default would be "true" here to keep the current behavior
opens("org.apache.commons.cli") // Same as 'opens org.apache.commons.cli' in module-info.java syntax
}
I am happy to accept contributions for this.
The feature is now added with the following syntax:
-
opens("org.apache.commons.collections.buffer")
open a package (automatically "closes" the module) -
closeModule()
(to turnopen module
intomodule
without opening any package)