自定义渐变任务失败-Can';我找不到GitPush

自定义渐变任务失败-Can';我找不到GitPush,git,groovy,push,task,gradle,Git,Groovy,Push,Task,Gradle,我正试图在Gradle任务中推动远程git回购。我发现的最好的方法是使用这里的Gradle Git插件: 我基本上只是尝试运行push任务,然后从那里开始配置它以便在我的项目中使用 下面是我的build.gradle脚本的样子 apply plugin: 'eclipse' apply plugin: 'groovy' apply plugin: 'maven' apply plugin: 'base' import org.ajoberstar.gradle.git.tasks.* rep

我正试图在Gradle任务中推动远程git回购。我发现的最好的方法是使用这里的Gradle Git插件:

我基本上只是尝试运行push任务,然后从那里开始配置它以便在我的项目中使用

下面是我的build.gradle脚本的样子

apply plugin: 'eclipse'
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'base'

import org.ajoberstar.gradle.git.tasks.*

repositories {
    mavenCentral()
    maven {
        url "[my custom repository repo]"
    }
}

dependencies {
    compile 'org.ajoberstar:gradle-git:0.4.0' 
}

task push(type: GitPush) {
    println "Test"
}
我的错误是

FAILURE: Build failed with an exception.

* Where:
Build file '[my_path]\build.gradle' line: 19

* What went wrong:
A problem occurred evaluating root project 'Name'.
> Could not find property 'GitPush' on root project 'Name'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

使用--stacktrace运行会在此处生成异常日志:

您没有遵循插件站点上的说明

要向构建本身添加内容,需要有一个
buildscript

buildscript {
  repositories { mavenCentral() }
  dependencies { classpath 'org.ajoberstar:gradle-git:0.4.0' }
}

谢谢,这个很好用!我假设,因为我已经有了存储库和依赖项块,所以我可以将这些行添加到这些部分,而不是创建一个单独的构建脚本块。