Gradle never resolves Artifactory before JCenter repository for dependencies

不羁岁月 提交于 2019-12-11 10:27:26

问题


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.

When the project is compiling, I want Gradle to first go to Artifactory and request; if it fails there, it should next try JCenter as a backup.

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
        }
    }
}

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()
}

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.

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:


  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.


来源:https://stackoverflow.com/questions/33488603/gradle-never-resolves-artifactory-before-jcenter-repository-for-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!