Gradle transitive = true
完全做了什么? Gradle documentation并不清楚。这是compile
内的build.gradle
内容。在我的情况下,我依赖于Android的崩解。
compile('com.crashlytics.sdk.android:crashlytics:2.2.2@aar') {
transitive = true;
}
几个Gradle文档(here和here)暗示"传递"默认为true。然而,删除transitive = true
会导致传递依赖性(特别是KitGroup
)。
class file for io.fabric.sdk.android.KitGroup not found
文档说它默认为true,但实际行为似乎正好相反。
我正在运行Gradle 2.2.1。也许这种行为在2.2和2.4之间发生了变化?
修改:相关Transitive dependencies not resolved for aar library using gradle
答案 0 :(得分:122)
You are using the @aar
notation.
It means that you want to download only the aar artifact, and no dependencies.
You can check this part of documentation:
Check the 1.4.1.2. Artifact only notation
section:
An artifact only notation creates a module dependency which downloads only the artifact file with the specified extension. Existing module descriptors are ignored.
Using the @aar
notation if you want to download the dependencies, you should add transitive=true
.
I'd expect that omitting @aar it should work without adding the transitive attribute.
答案 1 :(得分:5)
我的猜测是你手动引用的Crashlytics工件将依赖关系指定为 not transitive(transitive=false
),这样你就不会被迫默认带来这些依赖关系。这就是为什么你会看到相反的行为。例如,一些开发者可能不想提供所有Google Play服务或Crashlytics可能使用的任何其他内容。
因此,通过删除它,Gradle不再引入依赖项,并且无法构建。如果需要,可以手动指定该依赖项。
这就是说 - 我认为手头上更大的问题是你不应该直接引用Crashlytics工件 - 你应该使用Fabric,并因此拉入Crashlytics:{{ 3}}
答案 2 :(得分:4)
更一般地说:
在transitive = false
库上设置crashlytics
会导致gradle忽略crashlytics
(=“transient libraries”)所需的所有库,而不会下载并链接它们。
您必须手动将所需的库添加到项目中,或者依赖其他依赖项添加的其他临时库。
gradle的默认值为transitive = true
。
此处的示例和完整说明:http://www.devsbedevin.com/android-understanding-gradle-dependencies-and-resolving-conflicts/
答案 3 :(得分:1)
设置是否应解析此依赖项,包括或排除其传递依赖项。属于此依赖项的工件可能会依赖于其他工件。后者称为传递依赖。
答案 4 :(得分:1)
Gradle默认遵循传递依赖。如果要为特定库关闭它,请使用传递标记。
将传递标志的值更改为false可防止下载传递依赖项,因此您必须自己添加所需的任何内容。 如果您只需要一个模块jar,而不需要任何其他依赖项,那么您也可以指定它。
答案 5 :(得分:-18)
transitive
控制传递性。 Gradle通常默认为可传递,除非它没有。传递性和分类器存在缺陷,请参阅https://issues.gradle.org/browse/GRADLE-3188。