gradle - Gradle C++ 依赖项可以针对不同的应用程序进行不同的设置吗?
问题描述
我在同一个项目中有一些应用程序具有相同的依赖项,这些依赖项也在构建中,其中一些需要它们作为静态的,而另一些需要它们共享。我根据https://github.com/gradle/gradle-native/issues/1017上的答案构建了一个非常基本的错误展示,它实际上得到了相同的错误。这是一个基本项目,包含 2 个库:1 和 :2,以及一个位于 :app 的 cpp 应用程序。这吐出以下错误:
Could not determine the dependencies of task ':app:installDebug'.
> Could not resolve all task dependencies for configuration ':app:nativeRuntimeDebug'.
> Could not resolve project :1.
Required by:
project :app
> Module 'gradletest:1' has been rejected:
Cannot select module with conflict on capability 'gradletest:1:unspecified' also provided by [gradletest:1:unspecified(debugSharedRuntimeElements), gradletest:1:unspecified(debugStaticRuntimeElements)]
> Could not resolve project :1.
Required by:
project :app > project :2
> Module 'gradletest:1' has been rejected:
Cannot select module with conflict on capability 'gradletest:1:unspecified' also provided by [gradletest:1:unspecified(debugSharedRuntimeElements), gradletest:1:unspecified(debugStaticRuntimeElements)]
这是我的样本,我必须打破它。我很确定我遵循了 github 中回答的所有内容,并仔细阅读了 gradle 文档以获取我能找到的所有相关内容。在我目前的非 MVP 情况下,我将有一个 :app2 将 :1 和 :2 链接为共享库,因此仅将 :1 和 :2 设置为静态并不能解决问题。
1/build.gradle.kts
plugins {
`cpp-library`
`cpp-unit-test`
}
library {
linkage.set(listOf(Linkage.STATIC, Linkage.SHARED))
}
2/build.gradle.kts
plugins {
`cpp-library`
`cpp-unit-test`
}
library {
linkage.set(listOf(Linkage.STATIC, Linkage.SHARED))
dependencies {
implementation(project(":1"))
}
}
应用程序/build.gradle.kts
plugins {
`cpp-application`
`cpp-unit-test`
}
dependencies {
implementation(project(":1")) {
attributes { attribute(Attribute.of("org.gradle.native.linkage", Linkage::class.java), Linkage.STATIC) }
}
implementation(project(":2")) {
attributes { attribute(Attribute.of("org.gradle.native.linkage", Linkage::class.java), Linkage.STATIC) }
}
}
application {
}
这是在 Gradle 5.4.1 上完成的,不幸的是,要获得更新非常困难,所以我无法测试是否是旧版本的问题。
解决方案
推荐阅读
- python - 如何为每日数据大小变化创建动态 INT 变量
- firebase - 是否有必要为 Firebase 身份验证清理数据?
- c# - Asp.net 控件在后面的代码中不可访问。出现错误'名称'txtUserEmail'在当前上下文中不存在'
- angular - Angular - 通过当前延迟加载的模块更改标题组件
- c++ - 如何分块读取进程内存并扫描值的确切地址?
- python - 无法导入pygame
- c# - WPF C# 应用程序不显示加载 gif
- linux - 2g 不能在 sed 中工作以跳过匹配项的第一次出现
- string - 合并重叠的字符串
- python - 使用 Dockerfile 安装最新版本的 GDAL 以在 gcloud 中部署 django 应用程序