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

Gradle module inference for non-modular apps breaks service loader for modular service architecture #24270

Open
pedrolamarao opened this issue Mar 9, 2023 · 4 comments
Labels
a:bug has:reproducer Indicates the issue has a confirmed reproducer in:modular-java

Comments

@pedrolamarao
Copy link

This simple project should respond to ./gradlew run with Hello World!.
Instead, it raises NoSuchElementException.

https://github.com/pedrolamarao/gradle-module-path-decision

The cause is Gradle's decision to put api and impl in the class path instead of the module path.
Gradle seems to make this decision based on the fact that app is not a module.

This decision breaks the service loader mechanism.
impl declares it's provided services in its module definition.
It is meant to be put in the module path, not the class path.

One may be tempted to avoid this problem by redeclaring impl 's services in META-INF/services.
This way, when impl be put in the class path, the service loader is satisfied.

However, api module designers intended for the spi package to have restricted access to impl only.
Allowing api and impl in the class path makes this restriction meaningless.
To enforce this restriction, api and impl must require the module path.

This is just a contrived example.
In the real case I was working with, there should be a closed set of N providers for a certain service.
The user must not be able to insert providers in that set.

Currently, one cannot apply this kind of architecture with non-modular Gradle applications.

@ov7a
Copy link
Member

ov7a commented Mar 17, 2023

Why can't you make your java app modular? If you do this, inference from Gradle should work.

@pedrolamarao
Copy link
Author

Why can't you make your java app modular? If you do this, inference from Gradle should work.

I don`t develop applications, I develop components which my clients integrate into their applications.

@ljacomet
Copy link
Member

Thank you for providing a valid reproducer.

The issue is in the backlog of the relevant team but the existence of a workaround makes it non-critical so it might take a while before a fix is made.


You might be able to tell Gradle to infer module path by calling java.modularity.inferModulePath = true (call set for Kotlin DSL without assignment operator)

@pedrolamarao
Copy link
Author

I have updated the reproducer with 1) explicit inferModulePath = true, 2) Gradle 8.1-rc-1.
Doing this did not change the outcome.

@ov7a ov7a added to-triage has:reproducer Indicates the issue has a confirmed reproducer and removed to-triage labels Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug has:reproducer Indicates the issue has a confirmed reproducer in:modular-java
Projects
None yet
Development

No branches or pull requests

3 participants