我目前正在建立混合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" <-- ??
}
}
答案 0 :(得分:1)
我环顾四周,看来您应该尝试:
components {
api(NativeLibrarySpec) {
sources {
cpp {
source {
srcDir "src/main/stuff"
include "**/*.cpp"
}
}
}
binaries {
all {
lib library: "mylibrary", linkage: "static"
}
}
}
}
编辑:
all
是ModelMap
接口中的方法,由getBinaries
方法返回。它说:将给定操作应用于集合中的每个项目
ModelMap
使用BinarySpec
作为参数,因此all
的参数是Action<BinarySpec>
对象。
因此Action
类(功能接口)定义了一种方法execute(BinarySpec spec)
。方法lib
来自NativeBinarySpec
void lib(对象库)
将库添加为该二进制文件的输入。
此方法接受以下类型:
A NativeLibrarySpec A NativeDependencySet A Map containing the library selector.
地图符号支持以下字符串属性:
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
被添加为所有二进制文件的输入。