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

后端 未结 5 1566
自闭症患者
自闭症患者 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: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
    }
    

提交回复
热议问题