extra-java-module-info icon indicating copy to clipboard operation
extra-java-module-info copied to clipboard

Consider adding 'opens(...)' to module DSL

Open Wexalian opened this issue 2 years ago • 2 comments

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 avatar Apr 17 '22 01:04 Wexalian

@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

iherasymenko avatar Apr 17 '22 16:04 iherasymenko

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.

jjohannes avatar Apr 19 '22 06:04 jjohannes

The feature is now added with the following syntax:

  • opens("org.apache.commons.collections.buffer") open a package (automatically "closes" the module)
  • closeModule() (to turn open module into module without opening any package)

jjohannes avatar Apr 27 '23 14:04 jjohannes