Reputation: 1
I am trying to use Microsoft's azure-identity module) in a Gradle app.
However .\gradlew run fails with this stack trace:
> Task :run
java.lang.module.FindException: Module msal4j.persistence.extension not found
> Task :run FAILED
FAILURE: Build failed with an exception.
I tried adding msal4j.persistence.extension as a dependency in my build.gradle.kts and my module-info.java as recommended below, but then I get this error
> Task :compileJava FAILED
...\test\src\main\java\module-info.java:4: error: module not found: msal4j.persistence.extension
requires msal4j.persistence.extension;
^
1 error
It seems that msal4j.persistence.extension being an automatic module may have something to do with this?
build.gradle.kts
plugins {
id("java")
id("application")
}
group = "com.example"
version = "0.1"
repositories {
mavenCentral()
}
dependencies {
implementation(platform("com.azure:azure-sdk-bom:1.2.28"))
implementation("com.azure:azure-identity")
implementation("com.azure:azure-core")
implementation("com.microsoft.azure:msal4j-persistence-extension:1.3.0")
}
application {
mainClass = "com.example.Main"
mainModule = "com.example"
}
src/main/java/module-info.java
module com.example {
requires java.base;
requires com.azure.identity;
requires msal4j.persistence.extension; // *
exports com.example;
}
Relevant gradle dependencies
+--- com.azure:azure-identity -> 1.13.3
.
.
.
| +--- com.microsoft.azure:msal4j-persistence-extension:1.3.0
| | +--- com.microsoft.azure:msal4j:1.15.0 -> 1.17.1 (*)
| | +--- net.java.dev.jna:jna:5.13.0
| | +--- net.java.dev.jna:jna-platform:5.13.0
| | | \--- net.java.dev.jna:jna:5.13.0
| | \--- org.slf4j:slf4j-api:1.7.7 -> 1.7.36
| \--- net.java.dev.jna:jna-platform:5.6.0 -> 5.13.0 (*)
+--- com.azure:azure-core -> 1.52.0 (*)
\--- com.microsoft.azure:msal4j-persistence-extension:1.3.0 (*)
Upvotes: 0
Views: 102
Reputation: 3473
java.lang.module.FindException: Module msal4j.persistence.extension not found.
The msal4j.persistence.extension
library is not a true JPMS module, which means it can’t be directly included with a requires
statement in module-info.java
.
msal4j.persistence.extension
dependency is not strictly necessary at compile-time, try marking it as a requires static
dependency in module-info.java
.
module com.example {
requires java.base;
requires com.azure.identity;
requires static msal4j.persistence.extension;
exports com.example;
}
--add-reads
or --add-exports
JVM Options at Runtime./gradlew run --args="--add-reads com.example=msal4j.persistence.extension"
After above changes application successfully authenticates using Azure Identity via DefaultAzureCredential.
Build status:
> Task :compileJava
BUILD SUCCESSFUL in 5s
> Task :run
Starting authentication using DefaultAzureCredential...
2024-10-28 14:37:05 INFO DefaultAzureCredential - Using environment variables for authentication
2024-10-28 14:37:05 INFO ManagedIdentityCredential - Managed identity environment not detected
2024-10-28 14:37:06 INFO SharedTokenCacheCredential - No cached token available
2024-10-28 14:37:06 INFO VisualStudioCodeCredential - Skipping Visual Studio Code credentials
2024-10-28 14:37:06 INFO AzureCliCredential - Found Azure CLI token
2024-10-28 14:37:06 INFO AzureCliCredential - Successfully authenticated with Azure CLI
Authentication successful!
Executing main application logic...
[INFO] Application completed successfully.
> Task :run SUCCESS
Upvotes: 0