我有一个 Java 项目的 Gradle 构建脚本。我已经设置了一个内部 Artifactory 存储库作为项目依赖项的远程。
项目编译的时候,我想让Gradle先去Artifactory请求;如果它在那里失败,它应该接下来尝试 JCenter 作为备份。
我在 Gradle 2.8 中使用 Gradle Artifactory 插件 v3.1.1。该插件在闭包中定义了它的contextUrl
、publish
repo 和repo :resolve
artifactory {
contextUrl = "${artifactoryContextUrl}"
publish {
repository {
repoKey = 'Release'
username = "${artifactoryUser}"
password = "${artifactoryPassword}"
maven = true
}
}
resolve {
repository {
repoKey = 'repo'
username = "${artifactoryUser}"
password = "${artifactoryPassword}"
maven = true
}
}
}
buildscript 和项目都定义了它们的存储库:
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
在构建脚本中放置闭包,以便 Gradleresolve
在尝试 JCenter 之前引用这个定义的存储库。
最好,该解决方案会在 thebuildscript
和闭包中解决这个重复的定义,但在安装 Gradle-Artifactory 插件之前repositories
,我似乎不太可能引用闭包内的属性。artifactory