Maven-shade-plugin,uber-jar和重叠类 [英] Maven-shade-plugin, uber-jar and overlapping classes

查看:2817
本文介绍了Maven-shade-plugin,uber-jar和重叠类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Maven-shade-plugin创建uber-jar。但是当我调用 mvn package 命令Maven报告有一些重叠的类。我附加了所有有问题的重叠,其中一些是由于图书馆的旧版和新版本(Log4J)引起的,但其中一些似乎有相同的类 - 例如javax.mail和mailapi / smtp / imap等等。

I would like to use Maven-shade-plugin to create uber-jar. But when I call mvn package command Maven reports that there are some overlapping classes. I am attaching all problematic overlapps, some of them are caused because older and new verion of a library (Log4J), but some of them seems to have the same classes - e.g. javax.mail and mailapi/smtp/imap et cetera.

在这种情况下最好的做法是什么?是否有一些关键如何决定哪些重叠是安全的,以忽略哪些需要正确的?

What is the best to do in this situation? Is there some key how to decide which overlapping is safe to ignore a which needs to be correct?

 - mailapi-1.4.3.jar, javax.mail-1.5.0.jar define 166 overlappping classes
 - spring-2.5.6.SEC03.jar, spring-tx-3.1.4.RELEASE.jar define 176 overlappping classes:
 - spring-beans-3.1.4.RELEASE.jar, spring-2.5.6.SEC03.jar define 283 overlappping classes:
 - slf4j-log4j12-1.7.5.jar, slf4j-impl-2.0-beta2.jar define 3 overlappping classes:
 - spring-2.5.6.SEC03.jar, spring-context-support-3.1.4.RELEASE.jar define 55 overlappping classes:
 - aopalliance-1.0.jar, spring-2.5.6.SEC03.jar define 9 overlappping classes:
 - imap-1.5.0.jar, javax.mail-1.5.0.jar define 87 overlappping classes:
 - commons-logging-api-1.1.jar, commons-logging-1.1.3.jar define 19 overlappping classes:
 - spring-2.5.6.SEC03.jar, spring-core-3.1.4.RELEASE.jar define 161 overlappping classes:
 - spring-2.5.6.SEC03.jar, spring-context-3.1.4.RELEASE.jar define 326 overlappping classes: 
 - log4j12-api-2.0-beta3.jar, log4j-1.2.17.jar define 23 overlappping classes: 
 - spring-aop-3.1.4.RELEASE.jar, spring-2.5.6.SEC03.jar define 237 overlappping classes:
 - spring-jdbc-3.1.4.RELEASE.jar, spring-2.5.6.SEC03.jar define 239 overlappping classes:
 - quartz-1.8.6.jar, quartz-jobs-2.2.1.jar define 15 overlappping classes:
 - smtp-1.5.0.jar, javax.mail-1.5.0.jar define 17 overlappping classes: 
 - spring-asm-3.1.4.RELEASE.jar, spring-2.5.6.SEC03.jar define 31 overlappping classes: 

编辑:此应用程序A用作另一个Java应用程序的Maven依赖关系 - 我将此应用程序称为B。此B应用程序使用javax.mail ver 1.5.1。该库也使用第一个应用程序。但是当我调用mvn package命令时,Maven会注意到 javax.mail-api-1.5.1.jar,javax.mail-1.5.1.jar定义135覆盖类

this application "A" uses as a Maven dependency my another Java application - I'll call this app "B". This B application uses javax.mail ver 1.5.1. This library uses the first application too. But when I call mvn package command, Maven notices that javax.mail-api-1.5.1.jar, javax.mail-1.5.1.jar define 135 overlappping classes.

这个问题是否如此,如何解决呢,还是忽略呢?

Is this problem and if so, how to solve it or can I ignore it?

推荐答案

首先要做的就是尽可能多地删除重叠类的明显原因。例如:

The first thing to do is remove as many of the obvious causes of overlapping classes as you can. For instance:


  • 您有弹簧2.5.6和弹簧3.1.4的依赖关系,这将给您更多的问题阴影插件。设置你的模块依赖关系,所以你只有一个版本的spring。使用依赖关系排除,如果你必须(说你有传递依赖,你不能控制)。

  • 一旦依赖版本冲突是固定的,你也可以配置哪些jar进入uber-具有阴影插件配置的jar,如 http:/ /maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html

  • 某些jar可能包含所有类的重叠罐子。

    • 我怀疑commons-logging-1.1.3.jar有一个在commons-logging-api-1.1.jar中声明的类的超集。如果是这种情况,您可以排除api jar。

    • 为了回应编辑过的问题,javax.mail-1.5.1.jar包含超集的javax.mail-api-1.5.1.jar中的类。由于这些显然是相同的版本,并且重叠的类应该是相同的,所以使用重叠的类来构建带阴影的jar不会有任何损害(它将从最后处理的jar获取类)。但是,如果您排除api jar,则构建将更加细腻,稍快一些。

    • You have dependencies on both spring 2.5.6 and spring 3.1.4, which will give you more problems than just in the shade plugin. Set up your module dependencies so you have just one version of spring. Use dependency exclusions if you have to (say you have transitive dependencies that you do not control).
    • Once the dependency version clashes are fixed, you can also configure which jars go into the uber-jar with the shade plugin configuration, as described at http://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html
    • Some of the jars probably contain all of the classes from their overlapping jars.
      • I suspect that commons-logging-1.1.3.jar has a superset of the classes declared in commons-logging-api-1.1.jar. If this is the case, you can exclude the api jar.
      • In response to the edited question, javax.mail-1.5.1.jar contains a superset of the classes in javax.mail-api-1.5.1.jar. Since these are clearly the same version and the overlapping classes should be identical, it will do no harm to build the shaded jar with the overlapping classes (it will take the classes from whichever jar it processes last). However, the build will be tidier and slightly faster if you exclude the api jar.

      您不太可能需要保留类中的冲突版本阴影罐子如果你这样做,阴影插件也允许重定位类,如 http://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html

      It's unlikely that you will need to retain conflicting versions of the classes in the shaded jar. If you do, the shade plugin also allows the relocation of classes, as described at http://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html

      这篇关于Maven-shade-plugin,uber-jar和重叠类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆