gradle Maven依赖范围“编译”与“运行时”的含义

mgdq6dx1  于 2022-12-13  发布在  Maven
关注(0)|答案(1)|浏览(167)

From the viewpoint of a Gradle java library author, I understand that a dependency specified in the implementation configuration will be marked with the runtime scope in the resulting POM file that gets published (using the maven-publish Gradle plugin). This makes sense, as anyone consuming my published library doesn't need the dependency for compilation (it is an internal dependency), but instead only for runtime. If I specify a dependency in the api configuration, it will be marked with the compile scope in the resulting POM file, which again makes sense, as anyone consuming my library needs this for compilation (and runtime).
This makes me believe that the meaning of the Maven dependency scope is relative to anyone consuming the component, and not relative to the component itself. Consider a published Maven library (containing Java class files) a dependency marked with compile should mean:
If you compile against me, then use this dependency on the compilation classpath too!
However, according to the Maven docs, it seems that it means:
I was compiled with that dependency on my compilation classpath, and if you want to compile me again, do the same!
If this were true, then one could not distinguish between API-dependencies and implementation-dependencies like Gradle does. Also, it would only make sense if the published component actually contains the sources, not only the class files.
Did Gradle actually "misuse" the meaning of these scopes to make some improvements, or did I fundamentally misunderstand something?

n3h0vuf2

n3h0vuf21#

Gradle巧妙地“误用”了瞄准镜。
Maven有一个设计缺陷,即构建POM是以1:1的形式发布为使用者POM的(这将在即将到来的Maven 4.x中改变)。因此,Maven没有机会在项目中使用某些内容进行编译,而是在被另一个项目使用时用于运行时(至少在不使用技巧的情况下)。因此,Maven文档没有讨论“实现/API”的可能性。

相关问题