本文介绍了Gradle全局变量不在buildscript范围内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的顶级水平build.gradle
(2.2级)
I have something like this in my top level build.gradle
(Gradle 2.2)
ext.repo = "https://my-artifactory-repo"
buildscript {
repositories {
maven {
credentials {
username foo
password bar
}
url repo //doesn't work
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.1'
}
}
allprojects {
repositories {
maven {
credentials {
username foo
password bar
}
url repo //works
}
}
}
这是错误
Could not find property 'repo' on org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository_Decorated@718afa64.
因此它可以在allprojects
中工作,但不能在buildscript
中工作.
So it works in allprojects
but not buildscript
.
推荐答案
之所以发生这种情况,是因为总是首先评估buildscript {...}
配置闭包,因此该属性尚未定义.一种解决方法是通过将生成的属性放置在文件中或通过命令行将其定义在生成脚本之外.
This is happening because the buildscript {...}
configuration closure is always evaluated first, so the property is not yet defined. A workaround would be to define the property outside of the build script, either by placing it in a gradle.properties
file or via the command line.
这篇关于Gradle全局变量不在buildscript范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!