SBT 没有解决 <Profile> 中的传递依赖关系.POM 部分 [英] SBT not resolving transitive dependencies in the <Profile> section of POM

查看:20
本文介绍了SBT 没有解决 <Profile> 中的传递依赖关系.POM 部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果依赖项的 POM.xml 在 pom.xml 的Profile"部分中具有传递依赖项,那么这些依赖项不会由 SBT 解析,而由 Maven 解析.例如:当项目中包含以下依赖项时.....

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>

...那么以下依赖项不是由 SBT 解决的,而是由 maven 解决的:

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

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

有人能帮我理解为什么分辨率会有这种差异,以及我如何让 SBT 包含这些瞬态依赖.

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

以下是使用的测试 build.sbt :

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

以下是 hbase-client 的 pom.xml 中的条目:

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>

SBT 0.13.5 解决的依赖:

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

Maven 3.0.4 解决的依赖项:

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

推荐答案

sbt 不处理 maven 配置文件.您应该将依赖项(在给定配置文件中提到)添加到您的 sbt 文件中.

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

请参阅此讨论.

引用乔希的话:

Maven 确实允许这样做,但这是一种糟糕的形式.你怎么知道哪个配置文件可用于部署?基于更改依赖项对您的用户非常有害.我会联系那个项目的作者,并要求他们找到替代方法.

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.

这篇关于SBT 没有解决 &lt;Profile&gt; 中的传递依赖关系.POM 部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆