雖然另一個答案涵蓋了所有建構的99.99%,但它并不完整.
完整指令是./gradlew [-b / –build-file< build.file>] [-c /-settings-file< settings.file>].當你運作它時,那些指定的< build.file>和< settings.file>将用于相應地配置建構及其設定.設定檔案很特殊:它在建構的早期階段配置你的Project對象,它實際上可以是override它的建構檔案.
以下是示例(對于已棄用的<
task hello << { println "Hello" }
結果:
$./gradlew hello
:hello
Hello
自定義build.gradle,沒有settings.gradle:
custom.gradle:
task hello << { println "Hi!" }
結果:
$./gradlew -b custom.gradle hello
:hello
Hi!
自定義build.gradle,在settings.gradle中配置:
custom.gradle:
task hello << { println "Konnichi wa" }
settings.gradle:
rootProject.buildFileName = 'custom.gradle'
結果:
./gradlew hello # note that we don't need any flags here as with a default build
:hello
Konnichi wa
自定義build.gradle,在自定義settings.gradle中配置:
custom.gradle:
task hello << { println "Aloha!" }
settings.custom:
rootProject.buildFileName = 'custom.gradle'
結果:
./gradlew -c settings.custom hello # note how we pass custom settings file which, in turn, specifies custom `build.gradle`
:hello
Aloha!
這些都非常花哨而且不實用,但是您可以将這些方法結合起來存儲,例如,您在一個單獨的目錄中建構檔案(覆寫buildFileName).或者你可以使用多個settings.gradle這樣的“建構配置檔案”,包含不同的包含(設定也用于包含你建構的項目,是以你可以擁有“完整版”,“ui”,“外部”等配置檔案客戶“等等.
你的想象力是唯一的限制.