[英]Gradle - import GitHub repository and make it a subproject dependency?
我試圖通過部署JAR文件依賴來避免多項目構建,但它確實破壞了我靈活的工作流程,我需要一種更快的方法來使我的GIT存儲庫動態地相互添加為依賴項。 我確信我可以使用JAR文件編寫一些創造性的部署過程,但我喜歡對一個項目進行更改,以便在沒有中間部署的情況下立即轉向其他依賴項目。
我正在查看grgit文檔,我發現它允許分支克隆操作。 但是,如何在克隆之后提取工作樹並將其作為依賴項包含,假設repo本身有自己的gradle.build
腳本?
repositories {
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
dependencies {
compile group: 'com.google.guava', name: 'guava', version: '18.0'
compile 'org.xerial:sqlite-jdbc:3.8.7'
compile 'net.jcip:jcip-annotations:1.0'
compile 'joda-time:joda-time:2.7'
compile files('path/to/my/repo') //not quite sure what to do here???
}
task downloadGitDependency {
def grgit = Grgit.clone(dir: 'path/to/my/repo', uri: 'git@github.com:ajoberstar/grgit.git')
}
build.dependsOn downloadGitDependency
sourceSets {
main.java.srcDir "src/main/java"
}
jar {
from configurations.compile.collect { entry -> zipTree(entry) }
}
如果子項目列表是(相當)靜態的,並且每個子項目都有自己的build.gradle
,則可以將它們添加為git子模塊。 在您的項目目錄中,執行:
git submodule add git@github.com:ajoberstar/grgit.git path/to/my/repo
cd path/to/my/repo
git fetch
# then either (to switch to a different branch):
git checkout -b mybranch origin/mybranch
# or (to check out a particular ref on the current branch):
git checkout deadc0de
# or both of the above (to check out a particular ref on a different branch)
(注意:您在示例中使用的git URL會將grgit添加為子項目 - 除非這是您想要的,您可以在此處使用遠程倉庫的URL作為子項目.path path/tp/my/repo
是一個任意路徑在您的項目樹中,將克隆子項目。)
然后,將子項目添加到主項目的構建配置中: import
其import
settings.gradle
並將其定義為build.gradle
的依賴build.gradle
。
Git會將主要模塊的提交鏈接到子模塊的特定提交。
但是,請注意,在git中使用子模塊並非沒有缺陷:不要提交子模塊(總是提交上游),並確保每次HEAD更改時都運行git submodule update
(拉,合並,檢出等)。 )。 一篇關於git子模塊陷阱的好文章: https : //codingkilledthecat.wordpress.com/2012/04/28/why-your-company-shouldnt-use-git-submodules/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.