Let’s assume we have 3 projects A(plugin), B(api-lib) and C(client-app). A and B uploaded to the Ivy repo and accessed in C over SFTP:
buildscript {
def resolveUserName = {
if (project.hasProperty(“user”)) {
return project.user
}
return System.getenv(“USER”)
}
def resolveKeyFile = {
if (project.hasProperty(“keyFile”)) {
return project.keyFile
}
return “${System.getenv(“HOME”)}/.ssh/id_rsa”
}
def resolveKeyFilePassword = {
if (project.hasProperty(“keyFilePassword”)) {
return project.keyFilePassword
}
throw new GradleException("""
Cannot resolve password for your key at ${resolveKeyFile()}.
“”".trim())
}
repositories.add(new SFTPResolver()) {
name = “plugin-repo”
host = “example.com”
user = resolveUserName()
keyFile = project.file(resolveKeyFile())
keyFilePassword = resolveKeyFilePassword()
addIvyPattern “/apks/repos/libs/[organization]/[module]/[revision]/ivy-[revision].xml”
addArtifactPattern “/apks/repos/libs/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]”
}
}
So the question is:
-
A needs SFTP repo config to download B - repo config defined in separate Gradle build file and applied in the main build.gradle
-
C needs SFTP repo config to download A - repo defined inside buildscript section(see example code above)
-
C needs SFTP repo config to download B - repo configured by plugin A
So, how to unite those 3 places to reduce code duplication ? Basically, I need to configure repo for downloading normal dependencies, buildscript dependencies and ability to add configured repo to all projects when plugin A is applied