2015-02-06 37 views
7

我在項目中的以下兩個依賴:使用多個番石榴版本

<dependency> 
    <groupId>com.google.javascript</groupId> 
    <artifactId>closure-compiler</artifactId> 
    <version>v20141215</version> 
    <exclusions> 
     <exclusion> 
      <groupId>com.google.protobuf</groupId> 
      <artifactId>protobuf-java</artifactId> 
     </exclusion> 
    </exclusions> 
</dependency> 

<dependency> 
    <groupId>org.apache.hadoop</groupId> 
    <artifactId>hadoop-common</artifactId> 
    <version>2.4.0</version> 
</dependency> 

正如你可以在依賴關係樹看,它們都包含不同版本的番石榴:

[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ extraction --- 

[INFO] +- com.google.javascript:closure-compiler:jar:v20141215:compile 
[INFO] | +- com.google.javascript:closure-compiler-externs:jar:v20141215:compile 
[INFO] | +- args4j:args4j:jar:2.0.26:compile 
[INFO] | +- com.google.guava:guava:jar:18.0:compile 
[INFO] | +- com.google.code.gson:gson:jar:2.2.4:compile 
[INFO] | \- com.google.code.findbugs:jsr305:jar:1.3.9:compile 
[INFO] +- org.apache.hadoop:hadoop-common:jar:2.4.0:compile 
[INFO] | +- org.apache.hadoop:hadoop-annotations:jar:2.4.0:compile 
[INFO] | | \- jdk.tools:jdk.tools:jar:1.7:system 
[INFO] | +- (com.google.guava:guava:jar:11.0.2:compile - omitted for conflict with 18.0) 
[INFO] | +- ... 

衆所周知的問題是番石榴不向後兼容。所以我需要兩種罐子。

錯誤 - 我得到 - 如下:

Error: tried to access method com.google.common.base.Stopwatch.<init>()V from class org.apache.hadoop.mapreduce.lib.input.FileInputFormat 

這已經在這裏報道:https://issues.apache.org/jira/browse/HADOOP-10961

此外,他們建議用遮光Maven插件來處理它: https://groups.google.com/a/cloudera.org/forum/#!topic/cdh-user/d5_HqUSvVl4

我試過這裏:

<build> 
<plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>3.1</version> 
     <configuration> 
      <source>1.6</source> <!-- If you want to use Java 8, change this to "1.8" --> 
      <target>1.6</target> <!-- If you want to use Java 8, change this to "1.8" --> 
     </configuration> 
    </plugin> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-shade-plugin</artifactId> 
     <version>2.3</version> 
     <executions> 
      <execution> 
       <phase>package</phase> 
       <goals> 
        <goal>shade</goal> 
       </goals> 
       <configuration> 
        <relocations> 
         <relocation> 
          <pattern>com.google</pattern> 
          <shadedPattern>project.shaded.com.google</shadedPattern> 
         </relocation> 
        </relocations> 
       </configuration> 
      </execution> 
     </executions> 
    </plugin> 
</plugins> 
</build> 

但我仍然得到相同的錯誤。

任何人都可以幫我解決這個Maven問題嗎?

謝謝 菲利克斯

+0

你解決了嗎? – MFARID 2015-10-08 21:48:17

回答

0

也許你應該考慮所產生的JAR,看它是否被正確的建造。清理本地maven回購可能會解決問題。

+0

我清理了當地的maven回購庫,並且我還可以在jar的相應文件夾中找到番石榴類^^ – Felix 2015-02-06 17:04:15

1

我會建議您找到最新版本的Guava,它可以與Hadoop 2.4一起使用,並將其作爲明確的依賴關係。然後排除Guava從閉包編譯器和Hadoop代碼短暫獲取。

我建議V16作爲仍對秒錶類的零參數的構造:看Guava 16

當然,這個解決方案取決於番石榴16與關閉編譯器的工作。

+0

這就是問題所在。封閉包需要番石榴18 – Felix 2015-02-06 15:43:57

+0

v20140303只需要番石榴16.即使指定了一個版本,它可能不一定是絕對的要求。 – Will 2015-02-06 15:57:03

+0

我真的想使用最新版本:( – Felix 2015-02-06 16:40:59