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
。
出什么问题了,我该怎么解决呢?
理想情况下,即使有一个不工作的gradle
文件,我也希望能够运行settings.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
发布于 2020-10-01 11:00:01
您需要在自定义设置文件中配置自定义构建文件,然后在调用gradle时只使用
alt-设置.等级:
rootProject.name = 'custom-name'
rootProject.buildFileName = 'alt-build.gradle'
alt-build.gradle:
task test { /* ... */ }
格莱德尔呼叫:
gradle --settings-file alt-settings.gradle tasks --all
这样,默认的生成和设置文件就根本不用了,不管它们是否工作。
https://stackoverflow.com/questions/61544790
复制相似问题