简体   繁体   English

清洁罐子冲突

[英]Clean jar conflicts

In our project I want to remove all the potential jar conflicts that might arise during runtime. 在我们的项目中,我想消除运行时可能发生的所有潜在的jar冲突。 Our stack is so big, we have same jar brought in by different dependencies. 我们的堆栈是如此之大,我们有由不同的依赖项带来的同一个jar。 Here is the problem, each dependency is bringing in different version of the same jar and causing issues, after fresh deployment. 这就是问题所在,在重新部署后,每个依赖项都带来了同一jar的不同版本,并导致了问题。

Where do I start from ? 我从哪里开始? Are there any maven plugins to resolve this ? 是否有Maven插件可以解决此问题? Any help or pointers on this is much appricieated. 关于此的任何帮助或指示都非常有用。

You can use the maven-enforcer-plugin as follows: 您可以按以下方式使用maven-enforcer-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>1.3.1</version>
    <configuration>
        <fail>true</fail>
        <rules>
            <dependencyConvergence/>
        </rules>
    </configuration>
    <executions>
        <execution>
            <id>enforce-dependencies</id>
            <goals>
                <goal>enforce</goal>
            </goals>
        </execution>
    </executions>
</plugin>

This will stop the build when there are conflicting dependencies. 存在依赖项冲突时,这将停止构建。

A handy tool: JHades . 方便的工具: JHades In a nutshell, it is a tool that helps with Jar dependency Hell. 简而言之,它是有助于解决Jar依赖关系地狱的工具。 In itself, it is a Jar with no dependencies, except for the JDK. 它本身是一个没有依赖关系的Jar,除了JDK。 It can be used to spot easy conflicts and to debug more severe issues. 它可用于发现简单的冲突并调试更严重的问题。 Example: 例:

new JHades()
  .printClassLoaders()
  .printClasspath()
  .overlappingJarsReport()
  .multipleClassVersionsReport()
  .findClassByName("org.jhades.SomeServiceImpl")

Prints the class loader chain, jars, duplicate classes, ... 打印类加载器链,罐子,重复类,...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM