我正在尝试设置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'
}
这产生了类似的错误结果:
如您所见,它实际上尝试拉下以下URL:
http://repo-url/org/glassfish/ha/ha-api@jar/3.1.8@jar.pom
有谁知道我如何正确提取正确的二进制文件并排除不正确的依赖关系?
谢谢!
编辑
只是想补充一下,我遇到的原始问题是当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
最佳答案
出于某种原因,这似乎在使用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中完成,则可能值得检查。
关于gradle - 如何让Gradle使用不正确的元数据正确下拉传递依赖关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47914169/