-
Notifications
You must be signed in to change notification settings - Fork 2k
Support JPMS for Spring Cloud Azure Libraries
JPMS is Java Platform Module System.
Until Java 9, Java's top-level code organization element had been the package. Starting with Java 9 that changed: above the package now is the module. The module collects related packages together.
The JPMS is a code-level structure, so it doesn't change the fact that we package Java into JAR files.
Modularity adds a higher level of aggregation above packages. The key new language element is the module - a uniquely named, reusable group of related packages, as well as resources (such as images and XML files) and a module descriptor specifying
- the module's name
- the module's dependencies (that is, other modules this module depends on)
- the package it explicitly makes available to other modules (all other packages in the modules are implicitly unavailable to other modules)
- the services it offers
- the services it consumes
- to what other modules it allows reflection
As mentioned, a module must provide a module descriptor. A mdodule descriptor is defined in a file named module-info.java
.
One can refer to the module-info.java
of azure-cosmos for example.
More syntax about module-info.java can see https://www.oracle.com/corporate/features/understanding-java-9-modules.html.
If a project, which is modular itself but has a dependency which is not a module yet, how will the JPMS handle that?
It automatically creates a module:
-
Name:
- If the JAR defines the
Automatic-Module-Name
header in the manifest file, it will be the module's name. - Otherwise the JAR name is the module's name.
- If the JAR defines the
-
Requires:
- An automatic module read all other modules.
-
Exports/Opens
- An automatic module exports all packages and also opens them for deep reflection.
To list the JDK's set of modules, which includes the standard modules that implement the Java Language SE Specification (names starting with java), JavaFX modules (names starting with JavaFX), JDK-specific modules (names starting with jdk).
A version string follows each module name - @9
indicates that the module belongs to Java 9.
java --list-modules
This command can be used to verify whether a module is valid.
java -p ~/.m2/repository/com/azure/azure-core/1.32.0/azure-core-1.32.0.jar --list-modules
Our current plan is the same as the Spring's team, they don't support full JPMS yet. https://github.com/spring-projects/spring-framework/issues/18079.
So we only need to provide Automatic Module Name
for a Spring Cloud Azure library.
Check this for example https://github.com/Azure/azure-sdk-for-java/blob/d96d0333112997b0ee5aa03aacfad2d0b0e7d1d4/sdk/spring/spring-cloud-azure-starter/pom.xml#L106-L115.
But if you are developing a SDK level library, we should add the module-info.java
module descriptor for it. For example azure-identity-providers-*
libraries.
Check this for example https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity/src/main/java/module-info.java.
If you want to make sure the module you created is correct, you can create an application, and add the module-info.java
for this application.
Run the application with Java version greater than 9, for example Java 11.
- https://www.oracle.com/corporate/features/understanding-java-9-modules.html
- https://stackoverflow.com/questions/46741907/what-is-an-automatic-module#:~:text=The%20module%20name%20of%20an,JAR%20file%20by%20the%20ModuleFinder%20.
- https://github.com/tfesenko/Java-Modules-JPMS-CheatSheet/blob/master/README.md
- Spring Credential
- Spring Cloud Azure 4.0 Design
- Spring Cloud Azure AutoConfigure Design
- Spring Cloud Azure Core Design
- Spring Cloud Azure Messaging Design
- Spring Cloud Azure Service Bus Spring Jms Support Design
- Design for directory, module name and package path for Spring Cloud Azure messaging
- Design for Remove warning logs of unknown configs for Kafka Passwordless
- Design for Enhance AAD token authentication converter to customized granted authorities converter
- Design for Enhance the ObjectMapper to support Spring Boot's pattern to enable autoconfiguration
- Passwordless connection support for Spring Cloud Azure
- Passwordless connection support for MySQL
- Passwordless connection support for Event Hubs Kafka
- Remove warning logs of unknown configs for Kafka Passwordless