我不认为gradle支持添加git repo作为依赖。我的解决方法是:
声明主项目依赖于文件系统中的另一个项目
提供一种在声明为依赖项的文件夹中自动克隆git repo的方法
我假设您希望库repo位于主项目仓库的文件夹之外,因此每个项目都将是独立的git repos,并且您可以独立地提交到库和主项目git repos。
假设您希望将库项目的文件夹放在与主项目文件夹相同的文件夹中,
你可以:
在顶级settings.gradle中,将库存储库声明为项目,并给出它在文件系统中的位置
// Reference: https://looksok.wordpress.com/2014/07/12/compile-gradle-project-with-another-project-as-a-dependency/
include ':lib_project'
project( ':lib_project' ).projectDir = new File(settingsDir, '../library' )
使用gradle-git插件从git存储库中克隆库
import org.ajoberstar.gradle.git.tasks.*
buildscript {
repositories { mavenCentral() }
dependencies { classpath 'org.ajoberstar:gradle-git:0.2.3' }
}
task cloneLibraryGitRepo(type: GitClone) {
def destination = file("../library")
uri = "https://github.com/blabla/library.git"
destinationPath = destination
bare = false
enabled = !destination.exists() //to clone only once
}
在项目的依赖项中,假设项目的代码取决于git项目的文件夹
dependencies {
compile project(':lib_project')
}