Gradle永远不会在JCenter存储库之前解决Artifactory的依赖关系 [英] Gradle never resolves Artifactory before JCenter repository for dependencies

查看:183
本文介绍了Gradle永远不会在JCenter存储库之前解决Artifactory的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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.该插件在闭包中定义其contextUrlpublish存储库和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.

最好,该解决方案将解决buildscriptrepositories闭包中的重复定义,但是在安装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.

推荐答案

  1. 在脚本的主要部分中不需要artifactory {}配置和repositories配置.使用repositories指向buildscript中的Artifactory实例,然后指向主要部分中的artifactory{} DSL.
  2. 您无需在脚本中配置jcenter,默认情况下Artifactory会代理它.您不需要使用JCenter备份" Artifactory,因为JCenter中存在的任何内容都可以从Artifactory中解决.
  1. You don't need both artifactory {} config and repositories config in the main part of your script. use repositories to point to your Artifactory instance in the buildscript and then artifactory{} DSL in the main part.
  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆