I am getting a NoClassDefFoundError while using Azure ClientSecretCredential
Caused by: java.lang.NoClassDefFoundError: com/azure/core/util/serializer/JacksonAdapter
at com.azure.identity.implementation.IdentityClient.
at com.azure.identity.implementation.IdentityClientBuilder.build(IdentityClientBuilder.java:50)
at com.azure.identity.ManagedIdentityCredential.
at com.azure.identity.DefaultAzureCredential.
at com.azure.identity.DefaultAzureCredentialBuilder.build(DefaultAzureCredentialBuilder.java:18)
at com.via.Function.run(Function.java:72)
I see the following dependencies
[INFO] --- maven-dependency-plugin:3.1.1:tree (default-cli) @ via-azure-function ---
[INFO] com.via:via-azure-function:jar:1.0-SNAPSHOT
[INFO] +- com.microsoft.sqlserver:mssql-jdbc:jar:7.0.0.jre8:compile
[INFO] +- com.microsoft.azure.functions:azure-functions-java-library:jar:1.3.1:compile
[INFO] +- org.json:json:jar:20190722:compile
[INFO] +- org.junit.jupiter:junit-jupiter:jar:5.4.2:test
[INFO] | +- org.junit.jupiter:junit-jupiter-api:jar:5.4.2:test
[INFO] | | +- org.apiguardian:apiguardian-api:jar:1.0.0:test
[INFO] | | +- org.opentest4j:opentest4j:jar:1.1.1:test
[INFO] | | - org.junit.platform:junit-platform-commons:jar:1.4.2:test
[INFO] | +- org.junit.jupiter:junit-jupiter-params:jar:5.4.2:test
[INFO] | - org.junit.jupiter:junit-jupiter-engine:jar:5.4.2:test
[INFO] | - org.junit.platform:junit-platform-engine:jar:1.4.2:test
[INFO] +- org.mockito:mockito-core:jar:2.23.4:test
[INFO] | +- net.bytebuddy:byte-buddy:jar:1.9.3:test
[INFO] | +- net.bytebuddy:byte-buddy-agent:jar:1.9.3:test
[INFO] | - org.objenesis:objenesis:jar:2.6:test
[INFO] +- com.azure:azure-security-keyvault-secrets:jar:4.0.0:compile
[INFO] | +- com.azure:azure-core:jar:1.0.0:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.10.0:compile
[INFO] | | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.10.0:compile
[INFO] | | | +- com.fasterxml.jackson.core:jackson-core:jar:2.10.0:compile
[INFO] | | | - com.fasterxml.jackson.core:jackson-databind:jar:2.10.0:compile
[INFO] | | +- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.10.0:compile
[INFO] | | | +- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.10.0:compile
[INFO] | | | | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.2:compile
[INFO] | | | | - jakarta.activation:jakarta.activation-api:jar:1.2.1:compile
[INFO] | | | +- org.codehaus.woodstox:stax2-api:jar:4.2:compile
[INFO] | | | - com.fasterxml.woodstox:woodstox-core:jar:6.0.1:compile
[INFO] | | - io.projectreactor:reactor-core:jar:3.3.0.RELEASE:compile
[INFO] | | - org.reactivestreams:reactive-streams:jar:1.0.3:compile
[INFO] | +- com.azure:azure-core-http-netty:jar:1.0.0:compile
[INFO] | | +- io.netty:netty-handler:jar:4.1.42.Final:compile
[INFO] | | | +- io.netty:netty-common:jar:4.1.42.Final:compile
[INFO] | | | +- io.netty:netty-transport:jar:4.1.42.Final:compile
[INFO] | | | | - io.netty:netty-resolver:jar:4.1.42.Final:compile
[INFO] | | | - io.netty:netty-codec:jar:4.1.42.Final:compile
[INFO] | | +- io.netty:netty-handler-proxy:jar:4.1.42.Final:compile
[INFO] | | | - io.netty:netty-codec-socks:jar:4.1.42.Final:compile
[INFO] | | +- io.netty:netty-buffer:jar:4.1.42.Final:compile
[INFO] | | +- io.netty:netty-codec-http:jar:4.1.42.Final:compile
[INFO] | | +- io.projectreactor.netty:reactor-netty:jar:0.9.0.RELEASE:compile
[INFO] | | | +- io.netty:netty-codec-http2:jar:4.1.39.Final:compile
[INFO] | | | +- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.39.Final:compile
[INFO] | | | | - io.netty:netty-transport-native-unix-common:jar:4.1.39.Final:compile
[INFO] | | | - io.projectreactor.addons:reactor-pool:jar:0.1.0.RELEASE:compile
[INFO] | | - com.azure:azure-core-test:jar:1.0.0:compile
[INFO] | | +- io.projectreactor:reactor-test:jar:3.3.0.RELEASE:compile
[INFO] | | - junit:junit:jar:4.13-beta-3:compile
[INFO] | | - org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] | - commons-codec:commons-codec:jar:1.13:compile
[INFO] - com.azure:azure-identity:jar:1.0.3:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.28:compile
[INFO] +- com.microsoft.azure:msal4j:jar:0.5.0-preview:compile
[INFO] | +- com.google.code.gson:gson:jar:2.8.5:compile
[INFO] | +- org.apache.commons:commons-lang3:jar:3.9:compile
[INFO] | +- org.projectlombok:lombok:jar:1.18.6:compile
[INFO] | - org.apache.httpcomponents:httpclient:jar:4.5:compile
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.4.1:compile
[INFO] | - commons-logging:commons-logging:jar:1.2:compile
[INFO] +- com.nimbusds:oauth2-oidc-sdk:jar:6.14:compile
[INFO] | +- com.sun.mail:javax.mail:jar:1.6.1:compile
[INFO] | | - javax.activation:activation:jar:1.1:compile
[INFO] | +- com.github.stephenc.jcip:jcip-annotations:jar:1.0-1:compile
[INFO] | +- net.minidev:json-smart:jar:2.3:compile (version selected from constraint [1.3.1,2.3])
[INFO] | | - net.minidev:accessors-smart:jar:1.2:compile
[INFO] | | - org.ow2.asm:asm:jar:5.0.4:compile
[INFO] | +- com.nimbusds:lang-tag:jar:1.5:compile (version selected from constraint [1.4.3,))
[INFO] | - com.nimbusds:nimbus-jose-jwt:jar:8.19:compile (version selected from constraint [6.0.1,))
[INFO] +- org.nanohttpd:nanohttpd:jar:2.3.1:compile
[INFO] - net.java.dev.jna:jna-platform:jar:5.4.0:compile
[INFO] - net.java.dev.jna:jna:jar:5.4.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.108 s
[INFO] Finished at: 2020-06-27T12:49:05+05:30
[INF
Code Snippet
The client secret related code is like this
String keyVaultName = System.getenv("KEY_VAULT_NAME");
String kvUri = "https://" + keyVaultName + ".vault.azure.net";
SecretClient secretClient = new SecretClientBuilder().vaultUrl(kvUri).credential(new DefaultAzureCredentialBuilder().build()).buildClient();
KeyVaultSecret retrievedSecret = secretClient.getSecret("xyz");
hostName = retrievedSecret.getValue();
Setup (please complete the following information):
Thank you for reporting this issue @kallolborah.
Reviewing the dependency tree provided I believe the issue is the versions of azure-security-keyvault-secrets and azure-identity being used. It appears the KeyVault dependency is listed first in your project, this leads to Maven resolving the KeyVault dependency versions over the Identity versions when they are shared. So, this results in azure-core 1.0.0 is being used, the version of Identity (1.0.3) depends on azure-core 1.2.0.
Depending on your requirements for which version of KeyVault Secrets is required one of the following should resolve this issue:
4.1.0.1.0.0.If dependency versions aren't a concern I'd recommend option 1.
Thank you, @alzimmermsft - that fixed it ! Thanks very much.