如何解决为什么 gradle 不能解析这个完全限定的依赖变体?
我发布的 Java 库中有一个“自定义变体”,称为“releaseElements”。老实说,我真的很困惑 gradle“配置”、“变体”和“分类器”,这完全是一团糟,但这是模块文件的样子,如包 repo 中发布的:
{
"formatVersion": "1.1","component": {
"group": "com.grp","module": "lib-java","version": "1.5.1-temp-SNAPSHOT","attributes": {
"org.gradle.status": "integration"
}
},"createdBy": {
"gradle": {
"version": "6.8.3","buildId": "aykb2f3zszg23fxd3kwybg7mfe"
}
},"variants": [
{
"name": "apiElements",....................
....................
....................
{
"name": "releaseElements","attributes": {
"org.gradle.category": "library","org.gradle.dependency.bundling": "embedded","org.gradle.jvm.version": 8,"org.gradle.libraryelements": "jar","org.gradle.usage": "java-runtime"
},"files": [
{
"name": "lib-java-1.5.1-temp-SNAPSHOT-release.jar","url": "lib-java-1.5.1-temp-SNAPSHOT-release.jar","size": 4512712,
我的消费者应用程序尝试明确使用该变体“发布”,使用:
implementation (group:"com.grp",name: "app-java",version: "1.5.1-temp-SNAPSHOT",configuration: "releaseElements")
我也尝试过使用“classifier”代替配置并使用“release”而不是“releaseElements”,但没有成功。
根据 gradle docs 我期望的是“每当消费者明确选择目标配置时”绕过变体感知选择(这就是文档的字面意思)。然而,消费者的 gradle 版本不断给我这个:
> Could not resolve all dependencies for configuration ':runtimeClasspath'.
> Could not resolve com.grp:lib-java:1.5.1-temp-SNAPSHOT.
Required by:
project :
> Project : declares a dependency from configuration 'implementation' to configuration 'releaseElements' which is not declared in the descriptor for com.grp:lib-java:1.5.1-temp-SNAPSHOT:20210322.000411-5.
或者这个:
> The consumer was configured to find a runtime of a library compatible with Java 11,packaged as a jar,and its dependencies declared externally. However we cannot choose between the following variants of com.grp:lib-java:1.5.1-temp-SNAPSHOT:2021032
2.000411-5:
- releaseElements
- runtimeElements
All of them match the consumer attributes:
- Variant 'releaseElements' capability com.grp:lib-java:1.5.1-temp-SNAPSHOT declares a runtime of a library compatible with Java 11,and its dependencies declared externally:
- Unmatched attribute:
- Provides integration status but the consumer didn't ask for it
- Variant 'runtimeElements' capability com.grp:lib-java:1.5.1-temp-SNAPSHOT declares a runtime of a library compatible with Java 11,and its dependencies declared externally:
- Unmatched attribute:
- Provides integration status but the consumer didn't ask for it
请注意,我还尝试使用不同的 dependency.bundling
值 - 外部、嵌入和阴影。没有成功。
问题:当给消费者一个特定的变体时,为什么 Gradle 不绕过变体感知解析??
总体目标是添加我的库的一个变体,该变体是胖且模糊的,我可以将其与其他工件一起发布。
编辑:更多实验后的更多信息
我现在相信我应该在我的消费者中使用它:
implementation (group:"com.grp",configuration: "releaseElements")
即configuration
,而不是 classifier
,虽然 classifier
显然让我更接近我想要的。原因是 configuration 是包含 deps 的(在 Gradle 元数据中不同的配置可能有不同的 deps),而指定分类器只是指定一个去除元数据信息的 jar 文件,这是最后的手段根据{{3}}此处的内容。
消费者项目的构建继续失败,并出现上面的 ... which is not declared in the descriptor for com.grp:lib ...
错误,这是一个错误,因为配置在模块文件中。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。