Writing gradle task to add a tag to git repo as a custom plugin

I have a gradle task where I can add a tag to my Bitbucket repository as below:
task createTag <<{
def grgit = clone(dir: ‘C:\Repo1’, uri: ‘https://bitbucket.org/…’)
grgit.tag.add(name: ‘tag-name’, message: ‘Some Message!’)
grgit.push(tags: true)
}

Now, I want to move it to my Custom Plugin project. I am writing it as CreateTagPluginTask.groovy:
class CreateTagPlugin extends DefaultTask{
@TaskAction
def AddTag(){
def grgit = clone(dir: ‘C:\Repo2’, uri: ‘https://bitbucket.org/smunjal12589/grgit_task’)
grgit.tag.add(name: ‘tag-name’, message: ‘Some Message!’)
grgit.push(tags: true)
}

This post is not related to Buildship. I moved it to the appropriate topic.

Please dont move it. This is related to Buildship. I am not getting any response.

You are probably looking for Grgit.clone. Have a look at the Grgit documentation.

I don’t know why this should be related to Buildship. Buildship is the Eclipse Integration for Gradle. Your questions is about the Grgit plugin.

Hey, Thanks. But thats not what I am looking for. I know how to use this operation and I am able to clone. But I want to use it in eclipse where I have installed gradle (through Buildship). I am not aware of the syntax to use in eclipse

What syntax? The syntax for task definitions in build.gradle is the same whether you run Gradle from the command line or via the Buildship plugin. As with the others, I don’t see how Buildship is relevant.

It would help if your original post had a question in it. What are you trying to achieve? Do you simply want to create a new task of type CreateTagPlugin? Could you please try again to explain what problem you are having.

1 Like

If your question is “How do I run tasks in Buildship”, then the answer would be:

  • make sure the project is imported as a Gradle project
  • open the ‘Gradle Tasks’ view
  • if your task is private, you might have to click ‘Show All Tasks’
  • double click your task to run it

No, that is not what I asked. See, I want to write task in my buildship project. I write it like specified above. Now, I want to run this in my android studio project.I run it the way u said from gradle tasks but then it doesnt reccognise the grgit plugin. It gives error on whatever operation I write like clone, open or anything.

You have to be more precise, sorry. What is a Buildship project? Buildship is just the Gradle integration for Eclipse. You then mention Android Studio, which is based on a different IDE: IntelliJ IDEA. In fact, I think your problem is unrelated to IDEs.

You also mention you get errors. What are those errors? What exact steps lead to those errors? We are completely in the dark at the moment.

Okay. I ll try to be more precise. Buildship project was to specify which project I am referring to. In this case(Buildship project), I mean the one in eclipse or the custom plugin project. Then, I am working on an Android studio project that again uses gradle. I simply want to call the tasks I write in my eclipse or custom plugin project inside that Android studio project. I am able to execute them. For ex, I am writing the task mentioned in my original post i.e to clone a repository from git. Android Studio is not recognizing the grgit plugin and hence says cannot recognize the clone() method.

Does the Android Studio project apply the grgit plugin in the build.gradle file? Does it have the correct classpath set up in the buildscript {} block? Are you doing an import static for the Grgit.clone() method?

What is the output from Gradle when you try to run a task? Is there an exception? If so, try ./gradlew --stacktrace <task> and post that.

Its working now, Thanks . There was a problem with the version of grgit plugin I was using in build.gradle. This worked ‘classpath ‘org.ajoberstar:grgit:1.5.0’’