# An unshaded joda-time classes in elasticsearch-2.1.1.jar

**URL:** <https://discuss.elastic.co/t/an-unshaded-joda-time-classes-in-elasticsearch-2-1-1-jar/38943>\
**Category:** Elasticsearch\
**Created:** [January 12, 2016, 7:05am UTC](https://discuss.elastic.co/t/an-unshaded-joda-time-classes-in-elasticsearch-2-1-1-jar/38943 "2016-01-12T07:05:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dynamicscope](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@dynamicscope](https://discuss.elastic.co/u/dynamicscope)\
**Post date:** [January 12, 2016, 7:05am UTC](https://discuss.elastic.co/t/an-unshaded-joda-time-classes-in-elasticsearch-2-1-1-jar/38943/1 "2016-01-12T07:05:52Z")

</div>

It looks like there is an unshaded joda-time classes in elasticsearch-2.1.1.jar.  
The following is my **build.sbt**.

```
name := "MyApp"
version := "1.0"
scalaVersion := "2.10.6"
val sparkVers = "1.5.1"

resolvers ++= Seq(
  "Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases/",
  "Akka Repository" at "http://repo.akka.io/releases/",
  "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots")

// Base Spark-provided dependencies
libraryDependencies += "org.apache.spark" %% "spark-core" % sparkVers % "provided"

// Elasticsearch integration
libraryDependencies ++= Seq(
  ("org.elasticsearch" % "elasticsearch-spark_2.10" % "2.1.2").
    exclude("org.apache.hadoop", "hadoop-yarn-api").
    exclude("org.eclipse.jetty.orbit", "javax.mail.glassfish").
    exclude("org.eclipse.jetty.orbit", "javax.servlet").
    exclude("org.slf4j", "slf4j-api").
    exclude("joda-time", "joda-time")
)

libraryDependencies += "org.elasticsearch" % "elasticsearch" % "2.1.1"

// Skip tests when assembling fat JAR
test in assembly := {}

// Exclude jars that conflict with Spark (see https://github.com/sbt/sbt-assembly)
libraryDependencies ~= { _ map {
  case m if Seq("org.elasticsearch").contains(m.organization) =>
    m.exclude("commons-logging", "commons-logging").
      exclude("commons-collections", "commons-collections").
      exclude("commons-beanutils", "commons-beanutils-core").
      exclude("com.esotericsoftware.minlog", "minlog").
      exclude("org.apache.commons", "commons-lang3").
      exclude("org.apache.spark", "spark-network-common_2.10") // This conflicts with guava
  case m => m
}}

dependencyOverrides += "org.scala-lang" % "scala-compiler" % scalaVersion.value
dependencyOverrides += "org.scala-lang" % "scala-library" % scalaVersion.value
dependencyOverrides += "commons-net" % "commons-net" % "3.1"

assemblyMergeStrategy in assembly := {
  case PathList("org", "apache", "spark", "unused", "UnusedStubClass.class") => MergeStrategy.discard
  case x =>
    val oldStrategy = (assemblyMergeStrategy in assembly).value
    oldStrategy(x)
}

```

And I am getting the following error by running **sbt clean assembly**

```
java.lang.RuntimeException: deduplicate: different file contents found in the following:
/Users/DynamicScope/.ivy2/cache/org.elasticsearch/elasticsearch/jars/elasticsearch-2.1.1.jar:org/joda/time/base/BaseDateTime.class
/Users/DynamicScope/.ivy2/cache/joda-time/joda-time/jars/joda-time-2.8.2.jar:org/joda/time/base/BaseDateTime.class

```

Does anyone know how to solve this duplicate conflict?  
I need to use **val dateTime = new DateTime()** for my application.

Thanks.

**Updates**

I solved the conflict issue by adding the following to **assemblyMergeStrategy**.

`case PathList("org", "joda", "time", "base", "BaseDateTime.class") => MergeStrategy.first`

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 12, 2016, 7:29am UTC](https://discuss.elastic.co/t/an-unshaded-joda-time-classes-in-elasticsearch-2-1-1-jar/38943/2 "2016-01-12T07:29:08Z")

</div>

You should read this: [https://www.elastic.co/blog/to-shade-or-not-to-shade](https://www.elastic.co/blog/to-shade-or-not-to-shade)

Edit: forget it. Wrong answer.

Well, indeed, elasticsearch provides its own version of this class. It needs to be loaded first and ignored by any jar hell checker.

---

<div class="post-metadata">

**Author:** ![dynamicscope](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@dynamicscope](https://discuss.elastic.co/u/dynamicscope)\
**Post date:** [January 12, 2016, 7:41am UTC](https://discuss.elastic.co/t/an-unshaded-joda-time-classes-in-elasticsearch-2-1-1-jar/38943/3 "2016-01-12T07:41:38Z")

</div>

Isn't it a bad practice to have an unshaded classes used in different jar because it is hard to track down?

---

<div class="post-metadata">

**Author:** ![PeteyPabPro](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@PeteyPabPro](https://discuss.elastic.co/u/PeteyPabPro)\
**Post date:** [February 9, 2016, 11:48pm UTC](https://discuss.elastic.co/t/an-unshaded-joda-time-classes-in-elasticsearch-2-1-1-jar/38943/4 "2016-02-09T23:48:41Z")

</div>

Do you know why Elasticsearch provides its own version? If that is removed, and we just rely on the external joda dependency, will this break something? Similar question for the Lucene classes that are packaged in the jar..

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [February 10, 2016, 8:51am UTC](https://discuss.elastic.co/t/an-unshaded-joda-time-classes-in-elasticsearch-2-1-1-jar/38943/5 "2016-02-10T08:51:28Z")

</div>

The original Joda `BaseDateTime` class gives a 6x worse performance because of `volatile`, see this discussion

[http://cs.oswego.edu/pipermail/concurrency-interest/2011-August/008112.html](http://cs.oswego.edu/pipermail/concurrency-interest/2011-August/008112.html)

---

<div class="post-metadata">

**Author:** ![PeteyPabPro](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@PeteyPabPro](https://discuss.elastic.co/u/PeteyPabPro)\
**Post date:** [February 10, 2016, 6:47pm UTC](https://discuss.elastic.co/t/an-unshaded-joda-time-classes-in-elasticsearch-2-1-1-jar/38943/6 "2016-02-10T18:47:22Z")

</div>

Thanks, that's helpful. Do you know if this will affect client performance in any way? Or is it really only important for server side operations? In other words, if I run the Java client with the standard joda time library, do you think this will have a substantial impact on performance?

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [February 10, 2016, 7:42pm UTC](https://discuss.elastic.co/t/an-unshaded-joda-time-classes-in-elasticsearch-2-1-1-jar/38943/7 "2016-02-10T19:42:25Z")

</div>

Joda date/time parsing is only relevant to field mapping processing at server side. Clients do not use Joda at all (unless you use custom Joda-dependent code for the client, of course).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:17pm UTC](https://discuss.elastic.co/t/an-unshaded-joda-time-classes-in-elasticsearch-2-1-1-jar/38943/8 "2017-07-05T23:17:28Z")

</div>


