如何使用多个build.gradle文件?

Xel*_*ian 2 structure build project intellij-idea gradle

我的项目结构是:

在此输入图像描述

我希望用户另外使用规范 dir中的一些构建脚本来配置构建,但是还要使用主构建脚本来配置项目.使用-b 选项 可以指定另一个与默认构建不同的构建scrpt,但我也想要执行此默认构建.我不想使用apply from:并添加所有脚本,因为用户必须决定他想要什么.

那么有没有办法告诉Gradle添加额外的构建脚本 - 用于配置额外项目的命令行?

Oli*_*rth 7

如果你需要这个,你可以这样做:

apply from: "config/specifications/${project.spec}.gradle"
Run Code Online (Sandbox Code Playgroud)

这将允许用户做例如

./gradlew -P spec=example
Run Code Online (Sandbox Code Playgroud)

有关从命令行设置项目属性的更多详细信息,请参阅https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_properties_and_system_properties.