2

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"
hydradon
  • 1,316
  • 1
  • 21
  • 52
  • How do you call your common-buildscript.gradle and common-java.gradle files, in which closure and in which order? – Oguz Ozcan Nov 20 '17 at 10:43
  • @M.OğuzÖzcan Updated build.gradle file content. I apply `common-buildscript.gradle` first in the `buildscript` block. Then outside, I apply `common-java.gradle` – hydradon Nov 21 '17 at 02:07

0 Answers0