问题
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:
- You don't need both
artifactory {}
config andrepositories
config in the main part of your script. userepositories
to point to your Artifactory instance in thebuildscript
and thenartifactory{}
DSL in the main part. - 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