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.