Gradle: how to clone a git repo in a task?

后端 未结 5 1576
自闭症患者
自闭症患者 2020-12-08 15:08

Suppose I have a gradle build script and want to write a task to clone a remote git repository. How do I do that?

相关标签:
5条回答
  • 2020-12-08 15:41

    With newer versions of gradle-git (0.7.0 and up), you would create the task like this:

    import org.ajoberstar.grgit.*
    
    task clone << {
      Grgit.clone(dir: file('build/repo'), uri: 'git@github.com:user/repo.git')
    }
    
    0 讨论(0)
  • 2020-12-08 15:42

    The cloning can be done using the Gradle-git plugin. To use the plugin you should download it first:

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

    Then write a task like this one:

    import org.ajoberstar.gradle.git.tasks.*
    
    task cloneGitRepo(type: GitClone) {
            def destination = file("destination_folder")
            uri = "your_git_repo_uri"
            destinationPath = destination
            bare = false
            enabled = !destination.exists() //to clone only once
    }
    
    0 讨论(0)
  • 2020-12-08 15:45

    The Gradle-git plugin has a GitClone task that should help. I can't help you on how to use it since I don't know Gradle.

    0 讨论(0)
  • 2020-12-08 15:46

    The aforementioned Gradle-git plugin seems to have moved on from providing straightforward "clone this repo to that directory" functionality, so I wrote a simple task that does just this:

    https://github.com/palominolabs/gradle-git-clone-task

    0 讨论(0)
  • 2020-12-08 15:56

    There is a Git plugin - docs here: Gradle-git. The plugin has a clone method: GitClone

    Probably something along the lines of:

    GitClone clone = new GitClone();
    clone.setUri("http://remote.repository/");
    clone.setDestinationPath("//local/path");
    clone.setBare(false);
    clone.cloneRepo();
    
    0 讨论(0)
提交回复
热议问题