[英]How do I use a custom gradle build file and gradle settings file
gradle 命令有一堆標志來自定義其環境 [1]。 其中有--build-file
和--settings-file
。 但我似乎無法讓他們按照我期望的方式工作。
我希望以下工作
$ cat <<-EOF > alt-settings.gradle
rootProject.name = 'custom-name'
EOF
$ cat <<-EOF > alt-build.gradle
task test { /* ... */ }
EOF
$ gradle \
--settings-file alt-settings.gradle \
--build-file alt-build.gradle \
tasks --all
但這會引發異常
Build file './alt-build.gradle' is not part of the build defined by settings file './alt-settings.gradle'. If this is an unrelated build, it must have its own settings file.
如果我從上面的命令中省略--settings-file
事情確實有效,並且 gradle 拿起alt-build.gradle
。
出了什么問題,我該如何解決?
理想情況下,即使存在不起作用的 settings.gradle 文件,我也希望能夠運行gradle
。 例如在下面的 senario
$ cat <<-EOF > alt-build.gradle
task test { /* ... */ }
EOF
$ cat <<-EOF > alt-settings.gradle
rootProject.name = 'custom-name'
EOF
$ cat <<-EOF > settings.gradle
This will not compile
EOF
$ cat <<-EOF > build.gradle
This will not compile
EOF
$ gradle \
--settings-file alt-settings.gradle \
--build-file alt-build.gradle \
tasks --all
[1] https://docs.gradle.org/current/userguide/command_line_interface.html#environment_options
您需要在自定義設置文件中配置自定義構建文件,然后在調用 gradle 時僅使用 --settings-file 參數。
alt-settings.gradle:
rootProject.name = 'custom-name'
rootProject.buildFileName = 'alt-build.gradle'
alt-build.gradle:
task test { /* ... */ }
gradle 調用:
gradle --settings-file alt-settings.gradle tasks --all
這樣,根本不使用默認的構建和設置文件,它們是否工作都沒有關系。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.