Maven 依赖冲突

div*_*ivz 5 maven-3 maven

我正在尝试在使用以下依赖项时解决依赖项版本冲突。

我面临的最糟糕的情况是项目支持从 1.4 到最新版本的zucchiniapache版本。commons-io不支持1.4以下版本,同时pagerduty-client支持commons-io1.4以下版本。因此,不可能指定支持 zucchini 和 pager-duty 客户端(两者都是第三方库)的此依赖项(依赖项管理)的通用版本。

在此输入图像描述

在这种特殊情况下,我找不到解决此问题的可能方法。任何帮助将不胜感激。

        <dependency>
            <groupId>com.comcast.zucchini</groupId>
            <artifactId>zucchini</artifactId>
            <version>[2.2.5,)</version>

        </dependency>

        <dependency>
            <groupId>com.github.dikhan</groupId>
            <artifactId>pagerduty-client</artifactId>
            <version>3.0.2</version>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

Pau*_*ime 1

Possibility 1

If the old and new commons-io package/class names are a close enough match, excluding the old dependency from pagerduty-client could possibly work.

https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

    <dependency>
        <groupId>com.github.dikhan</groupId>
        <artifactId>pagerduty-client</artifactId>
        <version>3.0.2</version>
        <exclusions>
           <exclusion>
               <groupId>org.apache.commons</groupId>
               <artifactId>commons-io</artifactId>
           </exclusion>
       </exclusions> 
    </dependency>
Run Code Online (Sandbox Code Playgroud)

This relies on the binary API of commons-io between versions 1.3.2 and 2.x being similar enough.

There does seem to be lots of overlap, looking at the code of each version:

Possibility 2

Split up your application so that the commons-io dependency is not shared and does not conflict.

It could be that the pagerduty-client and zucchini parts of your application do not need to be 'bundled' together, so split them up.

If they do need work together then you could still have two apps/processes and send messages between them.

Note

I cloned the pagerduty-client repo and changed the commons-io dependency from org.apache.commons:commons-io:1.3.2 to commons-io:commons-io:2.5 and the tests worked, so maybe you can suggest to the project owner that they upgrade commons-io.

And looking at the code it seems commons-io is hardly used (one place, HttpApiServiceImpl.java):

\pagerduty-client>findstr /s /c:"commons" *.java
src\main\java\com\github\dikhan\pagerduty\client\events\domain\AcknowledgeIncident.java:import org.apache.commons.lang3.StringUtils;
src\main\java\com\github\dikhan\pagerduty\client\events\domain\Incident.java:import org.apache.commons.lang3.StringUtils;
src\main\java\com\github\dikhan\pagerduty\client\events\domain\Incident.java:import org.apache.commons.lang3.builder.Builder;
src\main\java\com\github\dikhan\pagerduty\client\events\domain\Payload.java:import org.apache.commons.lang3.StringUtils;
src\main\java\com\github\dikhan\pagerduty\client\events\domain\ResolveIncident.java:import org.apache.commons.lang3.StringUtils;
src\main\java\com\github\dikhan\pagerduty\client\events\HttpApiServiceImpl.java:import org.apache.commons.io.IOUtils;
src\main\java\com\github\dikhan\pagerduty\client\events\PagerDutyEventsClient.java:import org.apache.commons.lang3.StringUtils;
src\main\java\com\github\dikhan\pagerduty\client\events\utils\FakePagerDutyEventsClient.java:import org.apache.commons.lang3.StringUtils;
Run Code Online (Sandbox Code Playgroud)