0

E.g. If I have a project that depends on a library: "org.apache.hive:hive-common:jar:2.1.1-cdh6.3.4", with a provided scope. Now if I want to declare all its transitive dependencies as "provided", is it possible?

Not doing so will cause maven to fundamentally fail on resolving some of their scope properly:

[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

The last line in the output of dependency:tree:

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

Is clearly wrong: it cannot be found anywhere else, thus due to the rule in https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html. It's scope should be provided.

Is it possible to do it in maven? Or I'll have to switch to gradle?

tribbloid
  • 4,026
  • 14
  • 64
  • 103

2 Answers2

0

Please check answers to the following question: Maven transitive dependency has scope compile while when dependency has provided scope

In short, it appears that you might be using <dependencyManagement> with some of org.apache.hive:hive-common dependencies which in the end is causing them to change their scope.

Piotr Michalczyk
  • 249
  • 1
  • 13
  • This entry doesn't exist in my , it is also not imported or defined in any other part of the pom. – tribbloid Jan 11 '22 at 02:11
  • @tribbloid what about the parent pom? It would be good if you could post your whole pom file otherwise it is hard to determine what could be the other reason for such behavior. – Piotr Michalczyk Jan 11 '22 at 09:35
  • It is already the parent pom. I've searched for log4j-slf4j-impl in the whole project and it is undefined – tribbloid Jan 12 '22 at 18:51
0

It's possible that the transitive dependency is also pulled in by other dependencies and they are declared before hive. According to maven's dependency mediation mechanism, the closet dependency to the root project is selected. So the dependency you wish to be pulled in by hive is already resolved by maven. The dependency's scope is resolved then and not resolved by hive which is what you mean to be.

If you want them to be scope provided,maybe you can try to declare them in the dependencyManagement block, dependency declared in dependencyManagement block takes effect before the transitive dependency.

chaicho
  • 1
  • 1