【Azure Developer】com.azure:azure-identity jar包版本從1.2.0 升級到1.12.2 版本之後報錯

路边两盏灯發表於2024-10-15

問題描述

com.azure:azure-identity jar包版本從1.2.0 升級到1.12.2 版本之後報錯,錯誤資訊如下:

An attempt was made to call a method that does not exist. The attempt was made from the following location: com.azure.identity.implementation.IdentityClientBase.getConfidentialClient(IdentityClientBase.java:235)The following method did not exist: com.microsoft.aad.msal4j.ConfidentialClientApplication$Builder.logPii(Z)Lcom/microsoft/aad/msal4j/AbstractApplicationBase$Builder;The calling method's class, com.azure.identity.implementation.IdentityClientBase, was loaded from the following location: jar:file:/C:/java/soft/gradle-7.4.2-bin/gradle-7.4.2/caches/modules-2/files-2.1/com.azure/azure-identity/1.12.2/e12bc63202063589f68318bd5a1b4d1a8ae88fb6/azure-identity-1.12.2.jar!/com/azure/identity/implementation/IdentityClientBase.classThe called method's class, com.microsoft.aad.msal4j.ConfidentialClientApplication$Builder, is available from the following locations: jar:file:/C:/java/soft/gradle-7.4.2-bin/gradle-7.4.2/caches/modules-2/files-2.1/com.microsoft.azure/msal4j/1.11.0/38df9693f67ea1f01f35ebbe9411f0760c9ac77f/msal4j-1.11.0.jar!/com/microsoft/aad/msal4j/ConfidentialClientApplication$Builder.classThe called method's class hierarchy was loaded from the following locations: com.microsoft.aad.msal4j.ConfidentialClientApplication.Builder: file:/C:/java/soft/gradle-7.4.2-bin/gradle-7.4.2/caches/modules-2/files-2.1/com.microsoft.azure/msal4j/1.11.0/38df9693f67ea1f01f35ebbe9411f0760c9ac77f/msal4j-1.11.0.jar com.microsoft.aad.msal4j.AbstractClientApplicationBase.Builder: file:/C:/java/soft/gradle-7.4.2-bin/gradle-7.4.2/caches/modules-2/files-2.1/com.microsoft.azure/msal4j/1.11.0/38df9693f67ea1f01f35ebbe9411f0760c9ac77f/msal4j-1.11.0.jarAction:Correct the classpath of your application so that it contains compatible versions of the classes com.azure.identity.implementation.IdentityClientBase and com.microsoft.aad.msal4j.ConfidentialClientApplication$Builder

錯誤分析

應用日誌顯示存在依賴管理錯誤導致的method not found 報錯。

  • The following method did not exist: com.microsoft.aad.msal4j.ConfidentialClientApplication$Builder.logPii(Z)Lcom/microsoft/aad/msal4j/AbstractApplicationBase$Builder;
  • The called method's class hierarchy was loaded from the following locations: com.microsoft.aad.msal4j.ConfidentialClientApplication.Builder: file:/C:/java/soft/gradle-7.4.2-bin/gradle-7.4.2/caches/modules-2/files-2.1/com.microsoft.azure/msal4j/1.11.0/38df9693f67ea1f01f35ebbe9411f0760c9ac77f/msal4j-1.11.0.jar

需要調整class path以確保能讀取到正確的依賴包。

Correct the classpath of your application so that it contains compatible versions of the classes com.azure.identity.implementation.IdentityClientBase and com.microsoft.aad.msal4j.ConfidentialClientApplication$Builder

綜合以上,錯誤的原因是專案依賴中可能存在了多個版本的msal4j。當前解析出的msal4j-1.11.0.jar與升級後的azure-identity-1.12.2不相容。

相關文章