gpt4 book ai didi

gradle - 在 gradle 依赖中,为什么 API 配置会丢弃所有传递依赖?

转载 作者:行者123 更新时间:2023-12-03 04:54:51 29 4
gpt4 key购买 nike

我有一个包含 2 个子项目的 gradle 项目:common 和 demo。

公共(public)项目依赖于一个已发布的库:

dependencies {

implementation("eu.timepit:singleton-ops_${vs.scalaBinaryV}:0.5.0")
...

演示项目依赖于 common 作为其 API 的一部分:
dependencies {

api(project(":common")) {
isTransitive =true
}
}

当我编译两者时,我观察到共同的正确依赖关系:
compileClasspath - Compile classpath for source set 'main'.
+--- org.scala-lang:scala-compiler:2.12.11
| +--- org.scala-lang:scala-library:2.12.11
| +--- org.scala-lang:scala-reflect:2.12.11
| | \--- org.scala-lang:scala-library:2.12.11
| \--- org.scala-lang.modules:scala-xml_2.12:1.0.6
+--- org.scala-lang:scala-library:2.12.11
+--- org.scala-lang:scala-reflect:2.12.11 (*)
\--- eu.timepit:singleton-ops_2.12:0.5.0
+--- org.scala-lang:scala-compiler:2.12.8 -> 2.12.11 (*)
+--- org.scala-lang:scala-library:2.12.8 -> 2.12.11
\--- com.chuusai:shapeless_2.12:2.3.3
+--- org.scala-lang:scala-library:2.12.4 -> 2.12.11
\--- org.typelevel:macro-compat_2.12:1.1.1
\--- org.scala-lang:scala-library:2.12.0 -> 2.12.11

但是在demo中,common下的传递依赖是空的!
compileClasspath - Compile classpath for source set 'main'.
+--- project :common
+--- org.scala-lang:scala-compiler:2.12.11
...

这会导致非常常见的类路径丢失错误,例如:
[Error] /xxx/DoubleVectorDemo.scala:9: Symbol 'type shapeless.ProductArgs' is missing from the classpath.
This symbol is required by 'object edu.umontreal.kotlingrad.shapesafe.tensor.DoubleVector'.
Make sure that type ProductArgs is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'DoubleVector.class' was compiled against an incompatible version of shapeless.

那么为您的 API 的一部分删除库有什么意义呢?以及如何在所有项目中覆盖这种行为?

最佳答案

从毕业生java-plugin医生,

The api configuration should be used to declare dependencies which are exported by the library API, whereas the implementation configuration should be used to declare dependencies which are internal to the component. Dependencies appearing in the api configurations will be transitively exposed to consumers of the library, and as such will appear on the compile classpath of consumers. Dependencies found in the implementation configuration will, on the other hand, not be exposed to consumers, and therefore not leak into the consumers' compile classpath



假设您要公开 eu.timepit:singleton-ops_${vs.scalaBinaryV}:0.5.0到所有公共(public)库中,然后您需要将其添加为 api公共(public)模块 build.gradle.kts 中的依赖项。
dependencies {

api("eu.timepit:singleton-ops_${vs.scalaBinaryV}:0.5.0")

关于gradle - 在 gradle 依赖中,为什么 API 配置会丢弃所有传递依赖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62254490/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com