gradle命令有很多标志可以自定义其环境[1]。其中包括
我希望以下内容能够奏效。
但是这会抛出一个异常。
如果我从上面的命令中省略
出了什么问题,我该怎么解决?
理想情况下,即使存在一个不起作用的settings.gradle文件,我也希望能够运行
--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
。例如在以下场景中。$ 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
[1] https://docs.gradle.org/current/userguide/command_line_interface.html#environment_options 的内容是关于 Gradle 命令行界面中的环境选项。
alt-settings.gradle
中包含它,它将使--build-file
与--settings-file
一起工作。 - MiniMe