Java maven - override version of another dependency

I have two dependencies that I cannot change due to requirements. Both use the scala dependency in maven.

<dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-library</artifactId> <version>2.8.2</version> </dependency> 

One dependency is the jar file library added to the project, and the other dependency is the maven dependency.

The problem is that both require a scala dependency, one with version 2.8.2 and one with version 2.10.2. Both do not work with a different version number.

The bottom line is: how can I set the maven dependency to use 2.10.2, and the jar file 2.8.2?

+4
source share
1 answer

One crazy way to solve this problem would be to create two separate maven artifacts, one of which refers to the other:

 Scala version 1 Scala Version 2 | | \ / \ / Art1fact 1 --------> Artifact 2 

Now, in Artifact 1, use the Maven Shade Plugin to create jar-with-dependencies (see Maven-Assembly-Plugin ) using class transfer (for example, displaying all classes from scala. * To the old .scala. *). The important part is that Artifact 2 will only refer to the hatched version of Artifact 1, therefore overshadowing the Scala dependency.

( ProGuard will achieve similar results)

+1
source

Source: https://habr.com/ru/post/1487871/


All Articles