Gradle never resolves Artifactory before JCenter r

2019-08-08 16:14发布

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条回答
仙女界的扛把子
2楼-- · 2019-08-08 16:38
  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.
查看更多
登录 后发表回答