英文:
azure-storage-blob dependency defined in custom java library is not pulled into consuming grails application
问题
我已经构建了一个自定义的Java库,它包装了一些常见的Azure存储功能,称为"lib-azure-blob-storage"。库的build.gradle文件具有以下依赖项:
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'
}
而发布的库具有以下POM内容:
<?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>
然而,当我将这个库导入我的Grails Web应用程序时,如下所示:
implementation "com.basesStudio:lib-azure-blob-storage:1.0.0-jre8"
它无法解析一个类,出现以下错误:
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
我必须再次在消费应用程序中添加"azure-storage-blob"以避免此错误:
implementation "com.azure:azure-storage-blob:12.22.2"
implementation "com.basesStudio:lib-azure-blob-storage:1.0.0-jre8"
我本来认为只要实现"com.basesStudio:lib-azure-blob-storage:1.0.0-jre8"应该就足够了,因为它应该已经包含了"com.azure:azure-storage-blob:12.22.2"的依赖关系。
当我在Gradle中运行依赖关系报告时,我看到以下内容:
+--- 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
在构建我的库时,我可以做什么,以使消费的Grails应用程序不必重新导入已在库中定义的依赖项?
英文:
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?
答案1
得分: 0
>app/services/com/basesStudio/jet/RunRService.groovy: 12: unable to resolve class com.azure.storage.blob.specialized.BlockBlobClient.
将azure-storage-blob
依赖项添加到您的Grails应用程序的build.gradle
文件中,如下所示:
dependencies{
implementation 'com.azure:azure-storage-blob:12.22.2'
implementation group: 'com.azure', name: 'azure-storage-blob', version: '12.22.2'
}
这是为了确保Grails应用程序中可用BlockBlobClient
类。
- 确保
azure-storage-blob
包或其依赖项没有冲突的版本。 - 运行命令
gradle clean build
来刷新/清理依赖项并构建应用程序。
在pom.xml中,将azure-storage-blob
的version
添加到dependencies部分。
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.22.2</version>
<scope>runtime</scope>
</dependency>
我在我的应用程序中使用以下依赖项。
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'
}
我可以导入com.azure.storage.blob.specialized.BlockBlobClient
类。
英文:
>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.
- Make sure there are no conflicting versions of the
azure-storage-blob
package or its dependencies. - 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论