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
属性是根据两个可写属性 projectDir
和 buildFileName
创建的>:
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/