Shading a dependency in Maven

前端 未结 1 1168
一整个雨季
一整个雨季 2021-01-12 18:02

I have two dependencies imported via Maven that both import a common library, but at different versions but the versions are not compatible with each other. Essentially the

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-12 18:27

    As everyone has suggested you can use the maven-shade-plugin. Open source projects handle this by creating one maven sub project for each dependency that needs to be shaded. So in your case you would need 3 maven projects:

    1. One for shading dependency Y
    2. One for shading dependency G
    3. One for your original project. Your original project includes the artifacts created in 1. and 2. as dependencies.

    Your maven project hierarchy would look like this:

    • project
      • pom.xml
      • shade-Y
        • pom.xml
      • shade-G
        • pom.xml
      • application
        • pom.xml

    An example of a project which has a maven sub project for shading a dependency is here. Look at the shaded-ning19 folder to see how to create a dedicated maven project for shading a dependency.

    0 讨论(0)
提交回复
热议问题