问题
I'm playing with the idea of creating uber jars for my services but I'm worried about including jars that have conflicting dependencies. What happens when jar A depends on slf4j-1.0 and jar B depends on slf4j-2.0 and there were major changes between 1.0 and 2.0? When those jars both get included in the uber jar do I have to write specific filters by namespace or does something happen during the shadow process that namespaces the jars?
thanks for the help
回答1:
You are correct to worry. You end up with collisions (a colleague called it 'dll hell all over again') and sometimes you can have classes from both v1 and v2 in the same directory in the jarfile.
You can exclude one or the other version easily, but if your dependencies need them both, you are faced with the following options:
- find a new dependency that doesn't have the conflict
- upgrade or downgrade a current dependency to bring versions in line
- ship as a war file or some other type of file that handles this better, including a normal jarfile with a manifest that includes a classpath
- consider spring boot, which uses a different strategy than shading: http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#executable-jar
Whatever you do, gradle dependencies is helpful.
来源:https://stackoverflow.com/questions/24040813/gradle-shadow-jar-with-conflicting-dependencies