2

我有一个 Java 项目的 Gradle 构建脚本。我已经设置了一个内部 Artifactory 存储库作为项目依赖项的远程。

项目编译的时候,我想让Gradle先去Artifactory请求;如果它在那里失败,它应该接下来尝试 JCenter 作为备份。

我在 Gradle 2.8 中使用 Gradle Artifactory 插件 v3.1.1。该插件在闭包中定义了它的contextUrlpublishrepo 和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

4

1 回答 1

4
  1. 您不需要在脚本的主要部分同时artifactory {}配置和配置。repositories用于repositories指向您的 Artifactory 实例,buildscript然后artifactory{}在主要部分中指向 DSL。
  2. 您不需要jcenter在脚本中进行配置,Artifactory 默认代理它。您不需要使用 JCenter 来“备份”Artifactory,因为 JCenter 中存在的任何内容都可以从 Artifactory 中解析。
于 2015-11-02T23:38:43.353 回答