Class not found error in SDK 6.6.0 : com.microsoft.kiota.authentication.ObservabilityOptions
I am testing the latest version (6.6.0) of Graph SDK with a small program, but I am encountering a compile error due to a dependency issue.
Expected behavior
The program should compile and run properly.
Actual behavior
The following error occurs and prevents the program from compiling:
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.806 s
[INFO] Finished at: 2024-04-19T13:37:58+09:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project graph-sample: Compilation failure
[ERROR] /home/moris/w/graph-sample/src/main/java/org/example/App.java:[21,38] cannot access com.microsoft.kiota.authentication.ObservabilityOptions
[ERROR] class file for com.microsoft.kiota.authentication.ObservabilityOptions not found
[ERROR]
In vscode message:
The project was not built since its build path is incomplete. Cannot find the class file for com.microsoft.kiota.authentication.ObservabilityOptions. Fix the build path then try
Steps to reproduce the behavior
The Maven dependencies are as follows. I have set it up according to the README.md
<dependencies>
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph</artifactId>
<version>6.6.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.11.0</version>
</dependency>
</dependencies>
The program is as follows:
package org.example;
import com.azure.identity.ClientSecretCredential;
import com.azure.identity.ClientSecretCredentialBuilder;
import com.microsoft.graph.core.authentication.AzureIdentityAuthenticationProvider;
import com.microsoft.graph.serviceclient.GraphServiceClient;
public class App {
public static void main(String[] args) {
String clientId = System.getenv("CLIENT_ID");
String clientSecret = System.getenv("CLIENT_SECRET");
String tenantId = System.getenv("TENANT_ID");
ClientSecretCredential creds = new ClientSecretCredentialBuilder()
.clientId(clientId)
.clientSecret(clientSecret)
.tenantId(tenantId)
.build();
var authenticationProvider = new AzureIdentityAuthenticationProvider(creds, null,
"https://graph.microsoft.com/.default");
GraphServiceClient graphClient = new GraphServiceClient(authenticationProvider);
var result = graphClient.users().byUserId("your user id").get();
System.out.println(result.getDisplayName());
System.out.println(result.getUserPrincipalName());
}
}
If the following dependency is added manually, it can compile and run correctly:
<dependency>
<groupId>com.microsoft.kiota</groupId>
<artifactId>microsoft-kiota-authentication-azure</artifactId>
<version>1.1.4</version>
</dependency>
Thanks for reporting this @m-moris.
In the interim, for your scenario you can initialise your Graph client using:
GraphServiceClient client = new GraphServiceClient(credential, "https://graph.microsoft.com/.default");
Thanks for reporting this @m-moris.
In the interim, for your scenario you can initialise your Graph client using:
GraphServiceClient client = new GraphServiceClient(credential, "https://graph.microsoft.com/.default");
Hi @Ndiritu , I just encountered the same compiling error. I'm using the constructor with proxy okHttpClient to initialize the GraphServiceClient, which also including AzureIdentityAuthenticationProvider as param. It seems like can not be handled using the solution you mentioned to initialize the client, so I added the dependancy manually as workaround too.
InetSocketAddress proxyAddress = new InetSocketAddress(proxyHost, proxyPort);
OkHttpClient httpClient = GraphClientFactory.create().proxy(new Proxy(Proxy.Type.HTTP, proxyAddress)).build();
AzureIdentityAuthenticationProvider authenticationProvider = new AzureIdentityAuthenticationProvider(credential, null, graphScope);
GraphServiceClient graphClient = new GraphServiceClient(authenticationProvider, httpClient);
Facing the same issue using SDK 6.13.0
Seems the <scope>runtime</scope> tag is causing it. If you add it to the explicit kiota dependency given above, the error suddenly appears with that one too, and vanishes once you remove it again.