Gradle永远不会在JCenter存储库之前解决Artifactory的依赖关系 [英] Gradle never resolves Artifactory before JCenter repository for dependencies
问题描述
我有一个Java项目的Gradle构建脚本.我已经将内部Artifactory存储库设置为该项目依赖项的远程存储.
I have a Gradle build script for a Java project. I have set up an internal Artifactory repository as a remote for the project's dependencies.
在编译项目时,我希望Gradle首先去Artifactory并请求;如果它在那里失败,则接下来应尝试使用JCenter作为备份.
我正在Gradle 2.8中使用Gradle Artifactory插件v3.1.1.该插件在闭包中定义其contextUrl
,publish
存储库和resolve
存储库:
I am using the Gradle Artifactory plugin, v3.1.1, in Gradle 2.8. The plugin defines its contextUrl
, publish
repo, and resolve
repo in a closure:
artifactory {
contextUrl = "${artifactoryContextUrl}"
publish {
repository {
repoKey = 'Release'
username = "${artifactoryUser}"
password = "${artifactoryPassword}"
maven = true
}
}
resolve {
repository {
repoKey = 'repo'
username = "${artifactoryUser}"
password = "${artifactoryPassword}"
maven = true
}
}
}
buildscript和项目都定义了它们的存储库:
Both the buildscript and the project define their repositories:
buildscript {
repositories {
maven {
name 'Artifactory'
url "${artifactoryContextUrl}repo"
credentials {
username = "${artifactoryUser}"
password = "${artifactoryPassword}"
}
}
jcenter()
}
}
repositories {
maven {
name 'Artifactory'
url "${artifactoryContextUrl}repo"
credentials {
username = "${artifactoryUser}"
password = "${artifactoryPassword}"
}
}
jcenter()
}
我不得不求助于这些重复定义Artifactory仓库的重复语句,因为我似乎无法找到一种方法来定义artifactory
闭包并将其放置在构建脚本中,以便Gradle引用此已定义的resolve
在尝试JCenter之前回购.
I have had to resort to these duplicate statements that repeatedly define the Artifactory repo, as I can't seem to find a way to define and place the artifactory
closure in the build script so that Gradle refers to this defined resolve
repo before trying JCenter.
最好,该解决方案将解决buildscript
和repositories
闭包中的重复定义,但是在安装Gradle-Artifactory插件之前,我不太可能在artifactory
闭包中引用属性.
Preferably, the solution would address this duplicate definition in both the buildscript
and repositories
closures, but it's seems unlikely that I could refer to the properties inside the artifactory
closure before the Gradle-Artifactory plugin is installed.
推荐答案
- 在脚本的主要部分中不需要
artifactory {}
配置和repositories
配置.使用repositories
指向buildscript
中的Artifactory实例,然后指向主要部分中的artifactory{}
DSL. - 您无需在脚本中配置
jcenter
,默认情况下Artifactory会代理它.您不需要使用JCenter备份" Artifactory,因为JCenter中存在的任何内容都可以从Artifactory中解决.
- You don't need both
artifactory {}
config andrepositories
config in the main part of your script. userepositories
to point to your Artifactory instance in thebuildscript
and thenartifactory{}
DSL in the main part. - You don't need to configure
jcenter
in your script, Artifactory proxies it by default. You don't need to "back up" Artifactory with JCenter, because whatever exists in JCenter will always be resolvable from Artifactory.
这篇关于Gradle永远不会在JCenter存储库之前解决Artifactory的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!