2017-05-15 55 views
0

我有兩個命令來初始化和更新git子模塊,我該如何在一起運行它。這是任務。我該如何運行在單個gradle任務中執行兩個git命令

task gitSubModuleInit(type: Exec) { 
    description 'Initialize the git submodule' 
    commandLine "git", "submodule", "init" 
} 

task gitSubModuleUpdate(type: Exec) { 
    description 'Update the git submodule' 
    commandLine "git", "submodule", "update" 
} 

兩個問題

1)如何運行在單任務git的子模塊初始化和更新任務? 2)是否有可能將這些任務作爲構建任務的一部分進行鏈接?所以,當我有史以來建造它會自動更新子模塊

回答

0

肯定的:

task gitSubModuleInit(type: Exec) { 
    description 'Initialize the git submodule' 
    commandLine "git", "submodule", "init" 
} 

task gitSubModuleUpdate(type: Exec, dependsOn: gitSubModuleInit) { 
    description 'Update the git submodule' 
    commandLine "git", "submodule", "update" 
} 

<taskThatNeeds the files, probably compileJava>.dependsOn gitSubModuleUpdate 
+0

是有可能把init和更新任務成一個單一的任務嗎? – Peekay

+0

當然,您可以使用'exec {...}'方法而不是類型爲'Exec'的任務。但是我通常更喜歡把事情放在不同的任務中,所以如果我願意,可以單獨調用它們。順便說一句。請閱讀並遵守http://stackoverflow.com/help/someone-answers ;-) – Vampire