如何让Gradle正确地下载具有错误元数据的传递依赖?

问题描述 投票:0回答:1

我正在尝试设置gradle.build文件,我遇到以下传递依赖项的问题:

org.glassfish.ha:ha-api:3.1.8

看来pom.xml指定二进制文件是“hk2-jar”格式,实际上是不正确的,因为二进制文件只是“jar”格式。经过一番研究后,我发现了以下几点:

How should gradle handle “hk2-jar” dependencies?

不幸的是,这似乎不起作用。通过我发现的文档阅读更多内容我应该能够简单地执行以下操作:

configurations.all {
    resolutionStrategy.force 'org.glassfish.ha:ha-api:3.1.8@jar'
}

这产生了类似的错误结果:

Attempts to pull from the wrong URL

如您所见,它试图实际下拉以下URL:

http://repo-url/org/glassfish/ha/ha-api@jar/[email protected]

有谁知道如何正确地拉出正确的二进制文件并排除不​​正确的依赖项?

谢谢!

编辑

我只是想补充一点,我遇到的原始问题是,当Gradle尝试从我们的内部Artifactory下载ha-api依赖项时,返回403,因为我们的存储库中不存在hk2-jar文件(只有jar可以) :

* What went wrong:
Could not resolve all dependencies for configuration ':compileClasspath'.
> Could not determine artifacts for org.glassfish.ha:ha-api:3.1.8
   > Could not get resource 'http://repo-url/artifactory/libs-release/org/glassfish/ha/ha-api/3.1.8/ha-api-3.1.8.hk2-jar'.
      > Could not HEAD 'http://repo-url/artifactory/libs-release/org/glassfish/ha/ha-api/3.1.8/ha-api-3.1.8.hk2-jar'. Received status code 403 from server: Forbidden
gradle
1个回答
1
投票

出于某种原因,这似乎是一个问题,主要是在使用Artifactory(不是maven central / jcenter)时。

解决方案在Gradle forums描述

在一个项目中使用依赖项:

configurations.all {
   resolutionStrategy.dependencySubstitution {
      all { DependencySubstitution dependency ->
        def requested = dependency.requested
        if (requested instanceof ModuleComponentSelector && requested.group == 'org.glassfish.ha' && requested.name == 'ha-api') {
          dependency.useTarget "org.glassfish.ha:ha-ap:${requested.version}@jar"
        }
      }
   }
}

用于更改库项目中的传递依赖性(因此,依赖于此的其他项目不必执行上述操作):

publications {
    foo(MavenPublication) {
        pom.withXml {
           def dependency = asNode().dependencies.dependency.find {
              it.groupId.text() == 'org.glassfish.ha' && it.artifactId.text() == 'ha-api')
           }
           dependency.appendNode('type', 'jar')       
        } 
    }
}

可能值得检查是否也可以在Artifactory中完成。

© www.soinside.com 2019 - 2024. All rights reserved.