在Apachemaven中,如何覆盖库的所有传递依赖项的作用域?

bkhjykvo  于 2023-08-03  发布在  Maven
关注(0)|答案(2)|浏览(80)

例如,如果我有一个依赖于库的项目:“org.apache.hive:hive-common:jar:2.1.1-cdh6.3.4”,并提供了作用域。现在,如果我想将它的所有传递依赖声明为“provided”,可能吗?
不这样做将导致maven从根本上无法正确解决它们的一些范围:

[INFO] |  +- org.apache.hive:hive-common:jar:2.1.1-cdh6.3.4:provided
[INFO] |  |  +- org.apache.hive:hive-classification:jar:2.1.1-cdh6.3.4:compile
[INFO] |  |  +- org.apache.hive:hive-storage-api:jar:2.1.1-cdh6.3.4:provided
[INFO] |  |  +- org.apache.hive:hive-orc:jar:2.1.1-cdh6.3.4:provided
[INFO] |  |  |  +- org.apache.hadoop:hadoop-hdfs:jar:3.0.0-cdh6.3.4:provided
[INFO] |  |  |  |  +- org.eclipse.jetty:jetty-util-ajax:jar:9.3.25.v20180904:runtime
[INFO] |  |  |  |  +- com.sun.jersey:jersey-core:jar:1.19:runtime
[INFO] |  |  |  |  |  \- javax.ws.rs:jsr311-api:jar:1.1.1:runtime
[INFO] |  |  |  |  +- com.sun.jersey:jersey-server:jar:1.19:runtime
[INFO] |  |  |  |  \- commons-daemon:commons-daemon:jar:1.0.13:provided
[INFO] |  |  |  \- org.iq80.snappy:snappy:jar:0.2:provided
[INFO] |  |  +- org.apache.commons:commons-lang3:jar:3.3:compile
[INFO] |  |  +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] |  |  +- org.eclipse.jetty:jetty-rewrite:jar:9.3.25.v20180904:provided
[INFO] |  |  |  \- org.eclipse.jetty:jetty-client:jar:9.3.25.v20180904:provided
[INFO] |  |  +- org.eclipse.jetty:jetty-server:jar:9.3.25.v20180904:compile
[INFO] |  |  |  +- org.eclipse.jetty:jetty-http:jar:9.3.25.v20180904:compile
[INFO] |  |  |  \- org.eclipse.jetty:jetty-io:jar:9.3.25.v20180904:compile
[INFO] |  |  +- org.eclipse.jetty:jetty-servlet:jar:9.3.25.v20180904:compile
[INFO] |  |  |  \- org.eclipse.jetty:jetty-security:jar:9.3.25.v20180904:compile
[INFO] |  |  +- org.eclipse.jetty:jetty-webapp:jar:9.3.25.v20180904:compile
[INFO] |  |  |  \- org.eclipse.jetty:jetty-xml:jar:9.3.25.v20180904:compile
[INFO] |  |  +- org.apache.logging.log4j:log4j-1.2-api:jar:2.8.2:provided
[INFO] |  |  |  +- org.apache.logging.log4j:log4j-api:jar:2.8.2:compile
[INFO] |  |  |  \- org.apache.logging.log4j:log4j-core:jar:2.8.2:provided
[INFO] |  |  +- org.apache.logging.log4j:log4j-web:jar:2.8.2:provided
[INFO] |  |  +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.8.2:compile

字符串
dependency:tree输出的最后一行:

org.apache.logging.log4j:log4j-slf4j-impl:jar:2.8.2:compile


显然是错误的:由于https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html中的规则,它在其他任何地方都找不到。它的范围应该提供。
可以在maven做吗?不然我就得换个格拉多了?

brgchamk

brgchamk1#

请检查以下问题的答案:Maven transitive dependency has scope compile while when dependency has provided scope
简而言之,看起来您可能正在使用<dependencyManagement>和org.apache.hive:hive-common依赖项,最终导致它们改变了作用域。

yduiuuwa

yduiuuwa2#

传递依赖也可能被其他依赖拉入,并且它们在hive之前被声明。根据maven的依赖中介机制,选择根项目最接近的依赖项。所以你希望被hive拉入的依赖关系已经被maven解决了。依赖关系的作用域在那时被解析,而不是由hive来解析,这正是你想要的。
如果你想让它们被提供作用域,也许你可以尝试在dependencyManagement块中声明它们,dependencyManagement块中声明的依赖在传递依赖之前生效。

相关问题