SBT not resolving transitive dependencies in the <Profile> section of POM

為{幸葍}努か 提交于 2019-12-07 11:39:42

问题


If the POM.xml of a dependency has transitive dependencies inside "Profile" section of pom.xml then those dependencies are not resolved by SBT whereas they are resolved by Maven. Eg: when the following dependency is included in a project.....

   <dependency>
        <groupId>org.apache.hbase</groupId>
        <artifactId>hbase-client</artifactId>
        <version>0.98.0-hadoop2</version>
    </dependency>

...then the following dependencies are not resolved by SBT but are resolved by maven :

hadoop-annotations , hadoop-mapreduce-client-core , hadoop-auth , hadoop-common 

Can someone help me understand why this difference in resolution and how can I make SBT include these transient dependencies.

Following is test build.sbt used :

name := "StreamMaker"

version := "1.0"

scalaVersion := "2.10.4"

resolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"

libraryDependencies += "org.apache.hbase" % "hbase-client" % "0.98.0-hadoop2" 

net.virtualvoid.sbt.graph.Plugin.graphSettings

Following is the entry in hbase-client's pom.xml :

    <profile>
  <id>hadoop-2.0</id>
  <activation>
    <property>
        <name>!hadoop.profile</name>
    </property>
  </activation>
  <dependencies>
    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-common</artifactId>
      <exclusions>
        <exclusion>
          <groupId>javax.servlet.jsp</groupId>
          <artifactId>jsp-api</artifactId>
        </exclusion>
        <exclusion>
          <groupId>com.sun.jersey</groupId>
          <artifactId>jersey-server</artifactId>
        </exclusion>
        <exclusion>
          <groupId>javax.servlet</groupId>
          <artifactId>servlet-api</artifactId>
        </exclusion>
        <exclusion>
          <groupId>tomcat</groupId>
          <artifactId>jasper-compiler</artifactId>
        </exclusion>
        <exclusion>
          <groupId>tomcat</groupId>
          <artifactId>jasper-runtime</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-auth</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-mapreduce-client-core</artifactId>
      <exclusions>
      <exclusion>
        <groupId>com.sun.jersey.jersey-test-framework</groupId>
        <artifactId>jersey-test-framework-grizzly2</artifactId>
      </exclusion>
    </exclusions>
    </dependency>
    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-annotations</artifactId>
    </dependency>
  </dependencies>
</profile>

Depedencies resolved by SBT 0.13.5 :

+-org.apache.hbase:hbase-client:0.98.0-hadoop2
  +-com.github.stephenc.findbugs:findbugs-annotations:1.3.9-1
  +-com.google.guava:guava:12.0.1
  | +-com.google.code.findbugs:jsr305:1.3.9
  | 
  +-com.google.protobuf:protobuf-java:2.5.0
  +-commons-codec:commons-codec:1.7
  +-commons-io:commons-io:2.4
  +-commons-lang:commons-lang:2.6
  +-commons-logging:commons-logging:1.1.1
  +-io.netty:netty:3.6.6.Final
  +-junit:junit:4.11
  | +-org.hamcrest:hamcrest-core:1.3
  | 
  +-log4j:log4j:1.2.17
  +-org.apache.hbase:hbase-protocol:0.98.0-hadoop2
  | +-com.github.stephenc.findbugs:findbugs-annotations:1.3.9-1
  | +-com.google.protobuf:protobuf-java:2.5.0
  | +-junit:junit:4.11
  | | +-org.hamcrest:hamcrest-core:1.3
  | | 
  | +-log4j:log4j:1.2.17
  | 
  +-org.apache.zookeeper:zookeeper:3.4.5
  | +-log4j:log4j:1.2.15 (evicted by: 1.2.17)
  | +-log4j:log4j:1.2.16 (evicted by: 1.2.17)
  | +-log4j:log4j:1.2.17
  | +-org.slf4j:slf4j-api:1.6.1
  | +-org.slf4j:slf4j-log4j12:1.6.1
  |   +-log4j:log4j:1.2.15 (evicted by: 1.2.17)
  |   +-log4j:log4j:1.2.16 (evicted by: 1.2.17)
  |   +-log4j:log4j:1.2.17
  |   +-org.slf4j:slf4j-api:1.6.1
  |   
  +-org.cloudera.htrace:htrace-core:2.04
  | +-com.google.guava:guava:12.0.1
  | | +-com.google.code.findbugs:jsr305:1.3.9
  | | 
  | +-commons-logging:commons-logging:1.1.1
  | +-org.mortbay.jetty:jetty-util:6.1.26
  | 
  +-org.codehaus.jackson:jackson-mapper-asl:1.8.8
    +-org.codehaus.jackson:jackson-core-asl:1.8.8

Dependencies resolved by Maven 3.0.4 :

- org.apache.hbase:hbase-client:jar:0.98.0-hadoop2:compile
  +- org.apache.hbase:hbase-common:jar:0.98.0-hadoop2:compile
  |  \- commons-collections:commons-collections:jar:3.2.1:compile
  +- org.apache.hbase:hbase-protocol:jar:0.98.0-hadoop2:compile
  +- commons-codec:commons-codec:jar:1.7:compile
  +- commons-io:commons-io:jar:2.4:compile
  +- commons-lang:commons-lang:jar:2.6:compile
  +- commons-logging:commons-logging:jar:1.1.1:compile
  +- com.google.guava:guava:jar:12.0.1:compile
  |  \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
  +- com.google.protobuf:protobuf-java:jar:2.5.0:compile
  +- io.netty:netty:jar:3.6.6.Final:compile
  +- org.apache.zookeeper:zookeeper:jar:3.4.5:compile
  +- org.cloudera.htrace:htrace-core:jar:2.04:compile
  |  \- org.mortbay.jetty:jetty-util:jar:6.1.26:compile
  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.8.8:compile
  |  \- org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile
  +- org.apache.hadoop:hadoop-common:jar:2.2.0:compile
  |  +- commons-cli:commons-cli:jar:1.2:compile
  |  +- org.apache.commons:commons-math:jar:2.1:compile
  |  +- xmlenc:xmlenc:jar:0.52:compile
  |  +- commons-httpclient:commons-httpclient:jar:3.1:compile
  |  +- commons-net:commons-net:jar:3.1:compile
  |  +- org.mortbay.jetty:jetty:jar:6.1.26:compile
  |  +- com.sun.jersey:jersey-core:jar:1.9:compile
  |  +- com.sun.jersey:jersey-json:jar:1.9:compile
  |  |  +- org.codehaus.jettison:jettison:jar:1.1:compile
  |  |  |  \- stax:stax-api:jar:1.0.1:compile
  |  |  +- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:compile
  |  |  |  \- javax.xml.bind:jaxb-api:jar:2.2.2:compile
  |  |  |     \- javax.activation:activation:jar:1.1:compile
  |  |  +- org.codehaus.jackson:jackson-jaxrs:jar:1.8.3:compile
  |  |  \- org.codehaus.jackson:jackson-xc:jar:1.8.3:compile
  |  +- commons-el:commons-el:jar:1.0:runtime
  |  +- net.java.dev.jets3t:jets3t:jar:0.6.1:compile
  |  +- commons-configuration:commons-configuration:jar:1.6:compile
  |  |  +- commons-digester:commons-digester:jar:1.8:compile
  |  |  |  \- commons-beanutils:commons-beanutils:jar:1.7.0:compile
  |  |  \- commons-beanutils:commons-beanutils-core:jar:1.8.0:compile
  |  +- org.apache.avro:avro:jar:1.7.4:compile
  |  |  +- com.thoughtworks.paranamer:paranamer:jar:2.3:compile
  |  |  \- org.xerial.snappy:snappy-java:jar:1.0.4.1:compile
  |  +- com.jcraft:jsch:jar:0.1.42:compile
  |  \- org.apache.commons:commons-compress:jar:1.4.1:compile
  |     \- org.tukaani:xz:jar:1.0:compile
  +- org.apache.hadoop:hadoop-auth:jar:2.2.0:compile
  +- org.apache.hadoop:hadoop-mapreduce-client-core:jar:2.2.0:compile
  |  +- org.apache.hadoop:hadoop-yarn-common:jar:2.2.0:compile
  |  |  +- org.apache.hadoop:hadoop-yarn-api:jar:2.2.0:compile
  |  |  +- com.google.inject:guice:jar:3.0:compile
  |  |  |  +- javax.inject:javax.inject:jar:1:compile
  |  |  |  \- aopalliance:aopalliance:jar:1.0:compile
  |  |  +- com.sun.jersey:jersey-server:jar:1.9:compile
  |  |  |  \- asm:asm:jar:3.1:compile
  |  |  \- com.sun.jersey.contribs:jersey-guice:jar:1.9:compile
  |  \- com.google.inject.extensions:guice-servlet:jar:3.0:compile
  +- org.apache.hadoop:hadoop-annotations:jar:2.2.0:compile
  |  \- jdk.tools:jdk.tools:jar:1.7:system
  +- com.github.stephenc.findbugs:findbugs-annotations:jar:1.3.9-1:compile
  \- junit:junit:jar:4.11:compile
     \- org.hamcrest:hamcrest-core:jar:1.3:compile

回答1:


sbt does not handle maven profiles. You should add the dependencies (mentioned in given profile) to your sbt file.

name := "StreamMaker"

version := "1.0"

scalaVersion := "2.10.4"

resolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"

libraryDependencies += "org.apache.hbase" % "hbase-client" % "0.98.0-hadoop2" 

// Add the dependencies from the active profile.
libraryDependencies ++= Seq("org.apache.hadoop" % "hadoop-mapreduce-client-core" % "2.2.0",
                            "org.apache.hadoop" % "hadoop-mapreduce-client-jobclient" % "2.2.0",
                            "org.apache.hadoop" % "hadoop-hdfs" % "2.2.0",
                            "org.apache.hadoop" % "hadoop-auth" % "2.2.0",
                            "org.apache.hadoop" % "hadoop-common" % "2.2.0",
                            "org.apache.hadoop" % "hadoop-client" % "2.2.0",
                            "org.apache.hadoop" % "hadoop-annotations" % "2.2.0")

net.virtualvoid.sbt.graph.Plugin.graphSettings

See this discussion.

Quoting Josh:

Maven does allow this, but it's kind of bad form. How do you know which profile was active for deployment? Changing dependencies based on active profiles is VERY evil to your users. I'd contact that authors of the project and ask them to find an alternative method.



来源:https://stackoverflow.com/questions/25961765/sbt-not-resolving-transitive-dependencies-in-the-profile-section-of-pom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!