如何使用 Gradle DSL(领域特定语言)上的文档?
How to use the documentation on the Gradle DSL (domain specific language)?
我目前正在设置我的混合 java/cpp 多模块 gradle 项目几天。虽然我承认我是 groovy &Co 的新手,但似乎每一步我都需要找到我正在尝试做的事情的确切示例,否则我无法进步。
问:谁能告诉我这个Gradle DSL page怎么读?我正在尝试将我的库编译为仅静态(不共享),即使我使用了 baseName
并查看了页面上记录的 static
和 shared
属性,我也可以'我一辈子都不知道如何使用它们。我的代码是:
components {
api(NativeLibrarySpec) {
sources {
cpp {
source {
srcDir "src/main/stuff"
include "**/*.cpp"
}
}
}
baseName "mylibrary"
static "true" <-- what to write here??
shared "false" <-- ??
}
}
我环顾四周,看来你应该试试看:
components {
api(NativeLibrarySpec) {
sources {
cpp {
source {
srcDir "src/main/stuff"
include "**/*.cpp"
}
}
}
binaries {
all {
lib library: "mylibrary", linkage: "static"
}
}
}
}
编辑:
all
is a method from the ModelMap
interface, returned by the getBinaries
方法。它说:将给定的操作应用于集合中的每个项目
ModelMap
使用 BinarySpec
作为参数,所以 all
的参数是一个 Action<BinarySpec>
对象。
所以Action
class(函数式接口)定义了一个方法execute(BinarySpec spec)
。方法 lib
来自 NativeBinarySpec
void lib(Object library)
Adds a library as input to this binary.
This method accepts the following types:
A NativeLibrarySpec
A NativeDependencySet
A Map containing the library selector.
The Map notation supports the following String attributes:
project: the path to the project containing the library (optional, defaults to current project)
library: the name of the library (required)
linkage: the library linkage required ['shared'/'static'] (optional, defaults to 'shared')
所以,总而言之,mylibrary
被添加为所有二进制文件的输入。
我目前正在设置我的混合 java/cpp 多模块 gradle 项目几天。虽然我承认我是 groovy &Co 的新手,但似乎每一步我都需要找到我正在尝试做的事情的确切示例,否则我无法进步。
问:谁能告诉我这个Gradle DSL page怎么读?我正在尝试将我的库编译为仅静态(不共享),即使我使用了 baseName
并查看了页面上记录的 static
和 shared
属性,我也可以'我一辈子都不知道如何使用它们。我的代码是:
components {
api(NativeLibrarySpec) {
sources {
cpp {
source {
srcDir "src/main/stuff"
include "**/*.cpp"
}
}
}
baseName "mylibrary"
static "true" <-- what to write here??
shared "false" <-- ??
}
}
我环顾四周,看来你应该试试看:
components {
api(NativeLibrarySpec) {
sources {
cpp {
source {
srcDir "src/main/stuff"
include "**/*.cpp"
}
}
}
binaries {
all {
lib library: "mylibrary", linkage: "static"
}
}
}
}
编辑:
all
is a method from the ModelMap
interface, returned by the getBinaries
方法。它说:将给定的操作应用于集合中的每个项目
ModelMap
使用 BinarySpec
作为参数,所以 all
的参数是一个 Action<BinarySpec>
对象。
所以Action
class(函数式接口)定义了一个方法execute(BinarySpec spec)
。方法 lib
来自 NativeBinarySpec
void lib(Object library)
Adds a library as input to this binary.
This method accepts the following types:
A NativeLibrarySpec A NativeDependencySet A Map containing the library selector.
The Map notation supports the following String attributes:
project: the path to the project containing the library (optional, defaults to current project) library: the name of the library (required) linkage: the library linkage required ['shared'/'static'] (optional, defaults to 'shared')
所以,总而言之,mylibrary
被添加为所有二进制文件的输入。