如何使用Gradle DSL(域特定语言)上的文档?

时间:2018-09-16 01:58:15

标签: c++ gradle native

我目前正在建立混合Java / cpp多模块gradle项目几天。尽管我承认对groovy&Co陌生,但似乎我需要在方法的每个步骤中找到我要尝试做的确切例子,否则我就无法前进。

问:请问有人可以告诉我如何阅读此Gradle DSL page吗?我正在尝试将我的库编译为仅静态(不共享),即使我使用了baseName并看到页面上记录的staticshared属性,我也可以在我的一生中,了解如何使用它们。我的代码是:

components {
    api(NativeLibrarySpec) {
        sources {
            cpp {
                source {
                    srcDir "src/main/stuff"
                    include "**/*.cpp"
                }
            }
        }

        baseName "mylibrary"
        static "true"    <-- what to write here??
        shared "false"    <-- ??
    }
}

1 个答案:

答案 0 :(得分:1)

我环顾四周,看来您应该尝试:

components {
    api(NativeLibrarySpec) {
        sources {
            cpp {
                source {
                    srcDir "src/main/stuff"
                    include "**/*.cpp"
                }
            }
        }

        binaries {
            all {
                lib library: "mylibrary", linkage: "static"
            }
        }
    }
}

编辑:

allModelMap接口中的方法,由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被添加为所有二进制文件的输入。