Issue with okhttp3 when using Microsoft Graph API

searchlumin70 0 Reputation points
2023-08-26T21:37:25.1466667+00:00
import com.microsoft.graph.authentication.TokenCredentialAuthProvider
import com.microsoft.graph.models.Request
import com.microsoft.graph.requests.GraphServiceClient
import com.azure.identity.ClientSecretCredential
import com.azure.identity.ClientSecretCredentialBuilder


def clientId = "*****"
def tenantId = "*****"
def clientSecret = "*****"
def scopes = Arrays.asList("https://graph.microsoft.com/.default")

ClientSecretCredential credential = new ClientSecretCredentialBuilder()
   .clientId(clientId)
   .tenantId(tenantId)
   .clientSecret(clientSecret)
   .build()

def authProvider = new TokenCredentialAuthProvider(scopes, credential)

GraphServiceClient<Request> graphClient = GraphServiceClient.builder()
   .authenticationProvider(authProvider)
   .buildClient()

Returns :

java.lang.NoSuchMethodError: okhttp3.OkHttpClient$Builder.connectTimeout(Ljava/time/Duration;)Lokhttp3/OkHttpClient$Builder;

Library versions:

  • azure-core-1.42.0
  • azure-identity-1.10.0
  • jackson-datatype-jsr310-2.15.2
  • microsoft-graph-5.68.0
  • microsoft-graph-core-2.0.19
  • okhttp-4.11.0
  • reactive-core-3.5.9
  • reactive-streams-1.04
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Syed Shah Hussain Bukhari 140 Reputation points
    2023-08-27T01:04:34.1366667+00:00

    The error message you're encountering, java.lang.NoSuchMethodError: okhttp3.OkHttpClient$Builder.connectTimeout(Ljava/time/Duration;)Lokhttp3/OkHttpClient$Builder;, suggests that there is a version compatibility issue between the version of okhttp3 that you are using and the version that the Microsoft Graph API client expects.

    This issue typically occurs when the method signatures of a library have changed between different versions. The method connectTimeout that's being called with a Duration argument is likely not present in the version of okhttp3 you have.

    To resolve this issue, you need to ensure that the version of okhttp3 you are using is compatible with the version expected by the Microsoft Graph API client or other dependencies you have. Here's what you can try:

    1. Check Dependencies: Review the dependencies of both the Microsoft Graph API client and okhttp3 in your project. Make sure they are compatible. You might need to adjust the versions of these dependencies.
    2. Update Dependencies: If you're using a version of okhttp3 that is older than the one expected by the Microsoft Graph API client, try updating the version of okhttp3 to a version that includes the necessary method.
    3. Check Documentation: Look at the documentation for the Microsoft Graph API client library you're using. It might specify the required version of okhttp3. Make sure you are using a version that is either explicitly recommended or known to work with the library.
    4. Manage Dependency Versions: Consider using a dependency management tool (if available for your language) that can help you manage and resolve version conflicts automatically. Tools like Maven, Gradle (for Java), or npm (for JavaScript) can be helpful in resolving such issues.
    5. Check Release Notes: Look at the release notes for both the Microsoft Graph API client library and okhttp3. This could provide insights into version compatibility and any changes to method signatures.
    6. Use Dependency Exclusion: If the conflicting version of okhttp3 is brought in by a transitive dependency, you might be able to exclude it from your project and explicitly specify the version you want to use.

    Remember that keeping your dependencies up-to-date and ensuring version compatibility is a common challenge in software development. It might require some trial and error to find the correct combination of dependency versions that work well together.

    Lastly, make sure you're following best practices for managing dependencies and versions to avoid such issues in the future.

    0 comments No comments

  2. searchlumin70 0 Reputation points
    2023-08-27T04:19:51.1966667+00:00

    We checked the dependencies:

    • microsoft-graph-core-2.0.19
    • okhttp-4.11.0

    and this is what we have installed.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.