My gradle project structure is like so:
project
│ gradle.properties
│ build.gradle
│
└───common-config
│ common-buildscript.gradle
│ common-java.gradle
File contents:
gradle.properties
artifactory_user=username
artifactory_password=password
common-buildscript.gradle
def properties = new Properties()
file("../gradle.properties").withInputStream { properties.load(it) }
repositories {
maven {
url "someRepo1.com"
credentials {
username = properties.get("artifactory_user")
password = properties.get("artifactory_password")
}
name = "Some Repo 1"
}
maven {
url "someRepo2.com"
credentials {
username = properties.get("artifactory_user")
password = properties.get("artifactory_password")
}
name = "Some Repo 2"
}
}
common-java.gradle
apply plugin: "java"
repositories {
add buildscript.repositories.getByName("Some Repo 1")
add buildscript.repositories.getByName("Some Repo 2")
}
Upon running gradle clean build, I've got the following error:
A problem occurred evaluating script.
> Repository with name 'Some Repo 1' not found.
It seems that, in common-java.gradle, gradle is not able to detect "Some Repo 1" name in common-buildscript.gradle. However this will work if I put the contents of both files in the same build.gradle
The reason I want to do this is I want to apply the common build script to many other build scripts in my repos.
Please kindly advice how I can resolve this. Thank you
Update
build.gradle content:
buildscript {
ext {
commonConfig = rootProject.projectDir.absolutePath
}
apply from: "${commonConfig}/common-config/common-buildscript.gradle", to: buildscript
}
apply from: "${commonConfig}/common-config/common-java.gradle"