-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Describe the issue
I am currently experimenting with JPMS on Java 21 and GraalVM.
I discovered using services defined in a different module than the main one aren't picked up.
Steps to reproduce the issue
Clone the reproducer: git clone --depth 1 https://github.com/codepitbull/graalvm-bug-java21.git
There is an app module with a dependency on the dependency module defined:
module javatest.app.main {
requires javatest.dependency.main;
uses MyService;
}
The dependency defines the interface and the service implementation:
module javatest.dependency.main {
exports de.codepitbull.module.example;
provides MyService with de.codepitbull.module.example.MyServiceImpl;
}
The expctation would be that the app sees the defined service when a native image is built.
Build java only
- Run
./gradlew :app:build
- Run the application: `java --module-path ./app/build/libs/app.jar:./dependency/build/libs/dependency.jar -m javatest.app.main/java21.App``
Output:
Found a service: MyService!
Called Dependency.hello()
This shows the service is discovered running regular Java.
Build with native-image
- Run
./gradlew :app:nativeBuild
- Run the app
app/build/native/nativeBuild/app
Output:
Called Dependency.hello()
This shows that the service is not discovered when using the native build.
Build image natively (to avoid possible Gradle-plugin issues)
- Run `native-image --module-path ./app/build/libs/app.jar:./dependency/build/libs/dependency.jar --module javatest.dependency.main -m javatest.app.main/java21.App``
- Run app `java21.app``
Output:
Called Dependency.hello()
Again, service not resolved.
Describe GraalVM and your environment:
- GraalVM version:
native-image 21 2023-09-19
GraalVM Runtime Environment GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15)
Substrate VM GraalVM CE 21+35.1 (build 21+35, serial gc)
- JDK major version:
openjdk version "21" 2023-09-19
OpenJDK Runtime Environment GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15)
OpenJDK 64-Bit Server VM GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15, mixed mode, sharing)
- OS: 13.5.1 (22G90)
- Architecture: Applie Silicon M2