Gradle多项目构建: how to specify different build files?

标签 gradle multi-project build-script

Gradle 多项目构建:如何设置不同的构建文件?例如

/foo/bar/build-hello.gradle
/foo/bar/build-world.gradle

settings.gradle

include 'hello'
project(':hello').projectDir = new File('/foo/bar')
project(':hello').buildFile = new File('/foo/bar/build-hello.gradle')

include 'world'
project(':world').projectDir = new File('/foo/bar')
project(':world').buildFile = new File('/foo/bar/build-world.gradle')

错误:无法设置 readOnly 属性 buildFile。

如何指定默认 build.gradle 之外的不同构建文件?

编辑:

https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#org.gradle.api.Project:projectDir

File projectDir (read-only)
The directory containing the project build file.

projectDir 也是只读的。但设置其值时没有错误。为什么?

最佳答案

settings.gradle 文件在 Settings 上运行对象,其 project() 方法返回 ProjectDescriptor实例,因为在 Gradle 构建的此时尚未创建 Project 实例。

ProjectDescriptor 实例的只读 buildFile 属性是根据两个可写属性 projectDirbuildFileName 创建的>:

include 'hello'
project(':hello').projectDir = new File('/foo/bar')
project(':hello').buildFileName = 'build-hello.gradle'

include 'world'
project(':world').projectDir = new File('/foo/bar')
project(':world').buildFileName = 'build-world.gradle'

关于Gradle多项目构建: how to specify different build files?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48911504/

相关文章:

testing - 如何在 Gradle 中为单个测试创建快捷任务?

android - 更新android studio后出现错误 "Minimum supported Gradle version is 5.1.1. Current version is 4.4.1"

android-studio - 在Android Studio中使用Gradle的早期版本创建项目

build-script - Sublime Text 2和HTML5 Boilerplate构建脚本

rust - 如何将我的库中的源文件导入 build.rs?

ide - Nant 构建脚本 IDE

Gradle 将 zip 分解为 buildDir

java - 使用 Gradle 的 Eclipse 多个项目中的访问限制

build - Gradle Multiproject构建依赖项:软件包不存在

gradle - 为什么 "jar.enabled = false"会影响 Gradle 中的依赖项?