Skip to content
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

ability to generate META-INF/services/* from module-info #136

Open
hohwille opened this issue Jan 9, 2021 · 3 comments
Open

ability to generate META-INF/services/* from module-info #136

hohwille opened this issue Jan 9, 2021 · 3 comments

Comments

@hohwille
Copy link

hohwille commented Jan 9, 2021

I have alredy migrated my entire OSS project (https://github.com/m-m-m) to JPMS/jigsaw and it works great.
I am using service-loader for dynamic and flexible plugin/extensions mechanism and declare the implementations in my module-info.java files (see e.g. https://github.com/m-m-m/property/blob/master/core/src/main/java/module-info.java#L23).
However, when my modules are not loaded via module-path but via legacy classpath the module-info is not loaded and therefore services are not discovered.
To workaround this problem, one can manually add legacy META-INF/servicess/«api-fqn» files and list the implemenations there (see e.g. https://github.com/m-m-m/ui-tvm/blob/master/core/src/main/resources/META-INF/services/io.github.mmm.property.factory.PropertyFactory).
However, maintaining this manually as redundant files is kind of tedious. It would therefore be awesome to have some maven-plugin that could generate this automatically during the build from module-info.java. I searched if such solution is already available and stumbled over your plugin.

So with this issue I want to kindly ask if you would consider this as a suitable and valuable feature for your project (since you were asking for YOUR ideas :)).
If so please get in touch. If you want I could even contribute via PR.

@aalmiray
Copy link
Contributor

IMHO a feature like this requires parsing the module information and determine the services exposed. As an alternative you may use an annotation processor to generate the required service files, albeit there will be some sort of duplication as you need both the module definition and the annotated service.

There are handful of annotation processors that can do the job:

Personally I chose Jipsy (I'm the maintainer so I'm biased). Here's how I put it to work on the Ikonli build

https://github.com/kordamp/ikonli/blob/master/icon-packs/ikonli-fontawesome-pack/src/main/java/module-info.java
https://github.com/kordamp/ikonli/blob/master/icon-packs/ikonli-fontawesome-pack/src/main/java/org/kordamp/ikonli/fontawesome/FontAwesomeIkonProvider.java#L26

@hohwille
Copy link
Author

hohwille commented Jan 10, 2021

Thanks for your hint. That is interesting. As I still have to maintain services in the module-info, I would like to generate the services file from that. I would like to avoid adding silly annotations to my code and therefore requiring further third-party dependencies to all my modules.
However, if this is not the right place, feel free to close this issue.
I might create a new maven plugin at mojohaus or somewhere else if I do not find anything else.

@gunnarmorling
Copy link
Member

gunnarmorling commented Jan 10, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants