Skip to content
Advertisement

Multiple dependency versions with Gradle 5

I need to support 2 different versions of the same library (to support a legacy version), es4hadoop for Apache Spark.

Both versions have same dependencies (scala-lang and Spark).

Not sure at all about the naming of that, but I would like something like:

JavaScript

so I can use both new and old elasticsearch library, in the same project / JVM.

I know already it’s possible to relocate lib with the shadowJar plugin, but is it possible to relocate a specific version?

Advertisement

Answer

Put one of the elasticsearch-spark dependencies into a subproject aa2 and relocate it. Then the other subproject aa1 can depend on aa2‘s shadow configuration.

JavaScript
JavaScript

You can now declare the same class in this way:

JavaScript

However, you should pay more attention to their transitive dependencies. You might also need to relocate them to make the direct dependencies work normally. Sometimes I will decompress the output JAR file and investigate these .class files to ensure the resolution correctness.

References

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement