javaazuregradleazure-identitysas-token

Netty versions conflict with azure-identity、azure-storage-file-datalake java sdk


I am trying to implement ADLS token credential vending in my project with the following dependencies:

// 1.13.1
implementation(libs.azure.identity)
// 12.20.0
implementation(libs.azure.storage.file.datalake)

However, when I run the project, it throws an initializationError, which is caused by a Netty conflict:

{"az.sdk.message":"The following Netty versions were found on the classpath and have a mismatch with the versions used by azure-core-http-netty. If your application runs without issue this message can be ignored, otherwise please align the Netty versions used in your application. For more information, see https://aka.ms/azsdk/java/dependency/troubleshoot.","azure-netty-version":"4.1.110.Final","azure-netty-native-version":"2.0.65.Final","classpath-netty-version-io.netty:netty-common":"4.1.112.Final","classpath-netty-version-io.netty:netty-handler":"4.1.112.Final","classpath-netty-version-io.netty:netty-handler-proxy":"4.1.110.Final","classpath-netty-version-io.netty:netty-buffer":"4.1.112.Final","classpath-netty-version-io.netty:netty-codec":"4.1.112.Final","classpath-netty-version-io.netty:netty-codec-http":"4.1.112.Final","classpath-netty-version-io.netty:netty-codec-http2":"4.1.112.Final","classpath-netty-version-io.netty:netty-transport-native-unix-common":"4.1.112.Final","classpath-netty-version-io.netty:netty-transport-native-epoll":"4.1.110.Final","classpath-netty-version-io.netty:netty-transport-native-kqueue":"4.1.110.Final","classpath-native-netty-version-io.netty:netty-tcnative-boringssl-static":"2.0.65.Final"}

Previously, I tried excluding azure-core-http-netty with the following configuration:

implementation(libs.azure.identity) {
  exclude(group = "com.azure", module = "azure-core-http-netty")
}
implementation(libs.azure.storage.file.datalake) {
  exclude(group = "com.azure", module = "azure-core-http-netty")
}

But this didn’t resolve the issue and caused additional bugs.

How can I correctly import these dependencies and resolve the conflict?

And I really want to know, how to debug this and find the solution.

My project classpath dependencies https://gist.github.com/orenccl/0c4ef46e22b0fb1f80bb16d3979d381b

Seems like azure sdk must use netty 4.1.110, but my other module also must use 4.1.112

Can I require them use different version and not conflict?

P.S. My project use java 8, so I can not upgrade azure sdk version


Solution

  • Netty versions conflict with azure-identity、azure-storage-file-datalake java sdk.

    According to this Document(1.14.2)

    Seems like azure sdk must use netty 4.1.110, but my other module also must use 4.1.112 Can I require them use different version and not conflict?

    You can use Shadow to handle multiple versions of Netty in your project by either relocating conflicting versions or forcing a single version across all dependencies. This approach will help resolve the version conflicts and allow your project to run smoothly.

    If azure-sdk requires Netty 4.1.110, you can shade Netty 4.1.112 used by another library.

    plugins {
        id 'java'
        id 'com.github.xxxx.shadow' version '8.1.1'
    }
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation 'com.azure:azure-storage-file-datalake:12.20.0'
        implementation 'com.azure:azure-identity:1.13.1'
        // Other dependencies
    }
    
    configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'io.netty') {
                details.useVersion '4.1.112.Final'  // Force the desired Netty version
            }
        }
    }
    
    shadowJar {
        relocate 'io.netty', 'com.yourcompany.shadow.netty'  // Relocate Netty to avoid conflicts
        mergeServiceFiles()
    }
    

    Check the below reference like same as your error.

    References: