Search code examples
gradlegrailsazure-storage

azure-storage-blob dependency defined in custom java library is not pulled into consuming grails application


I have built a custom java library that wraps around some common functionality of azure storage called "lib-azure-blob-storage". The build.gradle file of the library has following dependencies:


dependencies {
    //@see https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/boms/azure-sdk-bom/README.md
    implementation(platform('com.azure:azure-sdk-bom:1.2.13'))
    implementation 'com.azure:azure-storage-blob'
    implementation 'commons-io:commons-io:2.12.0'
}

And the published library has following pom content:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <!-- This module was also published with a richer model, Gradle metadata,  -->
  <!-- which should be used instead. Do not delete the following line which  -->
  <!-- is to indicate to Gradle or any Gradle module metadata file consumer  -->
  <!-- that they should prefer consuming it instead. -->
  <!-- do_not_remove: published-with-gradle-metadata -->
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.basesStudio</groupId>
  <artifactId>lib-azure-blob-storage</artifactId>
  <version>1.0.0-jre8</version>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.azure</groupId>
        <artifactId>azure-sdk-bom</artifactId>
        <version>1.2.13</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.azure</groupId>
      <artifactId>azure-storage-blob</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.12.0</version>
      <scope>runtime</scope>
    </dependency>
  </dependencies>
</project>

However when I import this library to my consuming grails web application like:

implementation "com.basesStudio:lib-azure-blob-storage:1.0.0-jre8"

Its unable to resolve one of the class with following error:

startup failed:
app/services/com/basesStudio/jet/RunRService.groovy: 12: unable to resolve class com.azure.storage.blob.specialized.BlockBlobClient
 @ line 12, column 1.
   import com.azure.storage.blob.specialized.BlockBlobClient
   ^

1 error

I have to again add "azure-storage-blob" in the consuming app to avoid this error:

implementation "com.azure:azure-storage-blob:12.22.2"
implementation "com.basesStudio:lib-azure-blob-storage:1.0.0-jre8"

I would have though implementing com.basesStudio:lib-azure-blob-storage:1.0.0-jre8 should be enough since it should have pulled in the com.azure:azure-storage-blob:12.22.2 dependency along with it.

When I run dependency report in gradle I see following:

+--- com.basesStudio:lib-azure-blob-storage:1.0.0-jre8
|    +--- com.azure:azure-sdk-bom:1.2.13 (*)
|    +--- com.azure:azure-storage-blob -> 12.22.2
|    |    +--- com.azure:azure-core:1.39.0 (*)
|    |    +--- com.azure:azure-core-http-netty:1.13.3 (*)
|    |    +--- com.azure:azure-storage-common:12.21.1
|    |    |    +--- com.azure:azure-core:1.39.0 (*)
|    |    |    +--- com.azure:azure-core-http-netty:1.13.3 (*)
|    |    |    \--- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.5 -> 2.13.4 (*)
|    |    +--- com.azure:azure-storage-internal-avro:12.7.1
|    |    |    +--- com.azure:azure-core:1.39.0 (*)
|    |    |    +--- com.azure:azure-core-http-netty:1.13.3 (*)
|    |    |    +--- com.azure:azure-storage-common:12.21.1 (*)
|    |    |    \--- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.5 -> 2.13.4 (*)
|    |    \--- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.5 -> 2.13.4 (*)
|    \--- commons-io:commons-io:2.12.0

What can I do when building my library so that the consuming grails application doesn't have to re-import the dependency that is already defined in the library?


Solution

  • app/services/com/basesStudio/jet/RunRService.groovy: 12: unable to resolve class com.azure.storage.blob.specialized.BlockBlobClient.

    Add the azure-storage-blob dependency to your Grails application's build.gradle file as shown below:

    dependencies{
    
    implementation 'com.azure:azure-storage-blob:12.22.2'
    implementation group: 'com.azure', name: 'azure-storage-blob', version: '12.22.2'
    
    }
    

    This is to make sure BlockBlobClient class is available in the Grails application.

    1. Make sure there are no conflicting versions of the azure-storage-blob package or its dependencies.
    2. Run the command gradle clean build to refresh/clean the dependencies and build the application.

    And in pom.xml, add version of azure-storage-blob in dependencies section.

    <dependency>
          <groupId>com.azure</groupId>
          <artifactId>azure-storage-blob</artifactId>
          <version>12.22.2</version>
          <scope>runtime</scope>
    </dependency>
    

    I have the tried with below dependencies in my application.

    dependencies {
    
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'com.azure:azure-storage-blob:12.22.2'
    implementation group: 'com.azure', name: 'azure-storage-blob', version: '12.22.2'
    implementation group: 'com.microsoft.azure', name: 'azure-storage-spring-boot-starter', version: '2.2.5'
    implementation group: 'commons-fileupload', name: 'commons-fileupload', version: '1.4'
    
    }
    

    I could import the class com.azure.storage.blob.specialized.BlockBlobClient

    enter image description here