无法在项目中找到属性

时间:2014-05-31 15:31:22

标签: android gradle android-studio

我试图使用Grgit插件,我想从单独的Grgit文件中引用gradle

当我这样尝试时,Gradle能够找到Grgit

./的build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.10.+'
        classpath 'org.ajoberstar:gradle-git:0.8.+'
    }
}

import org.ajoberstar.grgit.*

def repo = Grgit.open(".")

但是,当我将最后两行移到单独的file.gradle时,如下所示,它不起作用:

./的build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.10.+'
        classpath 'org.ajoberstar:gradle-git:0.8.+'
    }
}

apply from: 'file.gradle'

./ file.gradle:

import org.ajoberstar.grgit.*

def repo = Grgit.open(".")

显示错误:

Could not find property 'Grgit' on root project 'MyProject'.

如何在单独的文件中使用Grgit

1 个答案:

答案 0 :(得分:6)

您需要将buildscript块移至file.gradle