본문 바로가기
Programming/JAVA

hadoop guava 버전 충돌

by 유주원 2018. 5. 28.

maven guava 버전을 20.0으로 올리고 map reduce 작업을 돌리는데 자꾸 이전 버전을 타는 문제가 발생했다. 

문제는 정확히 아래와 같다.


목표는 입력 url에서 top Domain을 뽑아내기 위함임.

top Domain을 뽑기 위해서 guava의 아래의 함수를 사용함.


InternetDomainName.from(host_url).topPrivateDomain().toString();


하지만 위의 함수를 map reduce를 통해 돌릴 경우 InternetDomainName{name="domain"} 이런 식으로 객체가 리턴이 됨.


아무래도 hadoop의 lib와 dependency lib가 서로 충돌이 일어나서 dependency lib를 못 타는 것 같았다.


이를 해결 하기 위해 maven-shade를 써서 dependency-jar를 새롭게 만들기로 했다. (기존에는 maven-assembly)


<build>

<plugins>

<plugin>

<groupId>org.apache.,maven.plugins</groupId>

<artifactId>maven-shade-plugin</artifactId>

<version>3.0.0</version>

<executions>

<execution>

<phase>package</phase>

<goals>

<goal>shade</goal>

</goals>

<configuration>

<finalName>${project.artifactId}-${project.version}-jar-with-dependencies</finalName>

<relocations>

<relocation>

<pattern>com.google.common</pattern>

<shadedPattern>shaded.com.google.common</shadedPattern>

</relocation>

</relocations>

<artifactSet>

<includes>

<include>*:*</include>

</includes>

</artifactSet>

</configuration>

</execution>

</executions>

</plugin>

</plugins>

</build>


relocations 태그가 기존 maven-assembly와의 큰 차이점이라고 볼 수가 있는데, 해당 태크는 기존의 패키지 명을 shadedPattern 형태로 바꿔주는 것을 의미한다. 결국 해당 jar 파일 내에서는 com.google.common이 shaded.com.google.common으로 쓰이게 되고, hadoop lib와 충돌이 발생하지 않게 되는 것이다. (hadoop lib는 com.google.common이라고 되어 있을 테니깐..)


해당 build 태그를 추가한 후 maven-build를 하고 결과를 살펴보니 정상적으로 top domain 결과가 리턴되는 것을 확인했다.