Gradle构建脚本是否可以使用与父build.gradle文件相同的存储库?

时间:2019-08-09 18:01:09

标签: gradle build.gradle gradle-plugin

我有一个 self.driver.find_element(By.ID, "templateName").click() self.driver.find_element(By.ID, "templateName").send_keys("Test") self.driver.find_element(By.ID, "type").click() dropdown = self.driver.find_element(By.ID, "type") dropdown.find_element(By.XPATH, "//option[. = 'test']").click() self.driver.find_element(By.ID, "file-upload").send_keys(os.getcwd() + "/picture.png") 文件,其中包含一个build.gradle块中的存储库定义,如下所示:

buildscript

我想buildscript { repositories { // Several proprietary repositories are declared } dependencies { classpath "com.example:foo:1.0" } } apply from: "bar.gradle" bar.gradle依赖项导入一个类。根据{{​​3}},这样做的方法是在foo中复制buildscript块。

但是,我想减少代码重复,因为存储库列表很长并且可能会更改。可以让bar.gradle引用父bar.gradle中声明的存储库吗?

到目前为止,我在build.gradle中尝试过:

bar.gradle

但是不幸的是,我仍然收到一条错误消息,提示未定义存储库。

1 个答案:

答案 0 :(得分:0)

如果您未在buildscript中应用某些内容,则您的构建脚本将无法引用

尝试...

buildscript.gradle

project.buildscript {
    repositories  {
        someRepo()
    }   
    dependencies{
        classpath 'some:dependency:0.1.0'
    }
}

build.gradle

buildscript {
    apply from: "buildscript.gradle"
}