Grgit
的内容复制到git.gradle
,否则 Gradle(OSX上的v2.12)无法在以下示例中找到build.gradle
的定义。如何在不丢失git.gradle
的情况下修复此错误?
的build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.ajoberstar:gradle-git:1.4.2'
}
}
apply from: 'git.gradle'
git.gradle
import org.ajoberstar.grgit.*
task clone << {
Grgit.clone(dir: file('build/repo'), uri: 'git@github.com:user/repo.git')
}
这是输出:
$ gradle clone
...
Execution failed for task ':clone'.
> Could not find property 'Grgit' on task ':clone'.
答案 0 :(得分:2)
找到解决方法:将Grgit
添加为ExtraPropertiesExtension
project.ext
,以将其公开给导入的Gradle脚本。 (不确定是否有更简洁的方法......)
<强>的build.gradle 强>
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.ajoberstar:gradle-git:1.4.2'
}
}
// expose Grgit to `git.gradle`
project.ext.Grgit = org.ajoberstar.grgit.Grgit
apply from: 'git.gradle'
<强> git.gradle 强>
// no import needed here
task clone << {
Grgit.clone(dir: file('build/repo'), uri: 'git@github.com:user/repo.git')
}
旁白:自动应用gradle-git
插件
opens the Git directory of the project's root, and assigns
the result to project.ext.grgit
。如果您只需要使用当前项目的Git仓库,则无需公开Grgit
{/ 1}}和 git.gradle 可能看起来像这样:
build.gradle