简体   繁体   English

Maven - 如何使用多个版本的依赖项?

[英]Maven - how to work with multiple versions of dependencies?

I have project which used JIRA REST Java Client. 我有使用JIRA REST Java Client的项目。 It worked fine until I tried to integrate it with Spring Boot. 它工作正常,直到我尝试将其与Spring Boot集成。 Since that I am not able to invoke createWithBasicHttpAuthentication from AsynchronousJiraRestClientFactory without error. 因为我无法从AsynchronousJiraRestClientFactory调用createWithBasicHttpAuthentication而没有错误。 I get: 我明白了:

ClassNotFoundException: org.apache.http.util.Args

So I added HttpComponents Core blocking I/O(httpcore) dependency to my pom.xml , but I after that I got 所以我添加了HttpComponents Core blocking I/O(httpcore)依赖到我的pom.xml ,但是之后我得到了

ClassNotFoundException: org.apache.http.nio.NHttpMessageParserFactory

Which I resolved with adding HttpComponents Core non-blocking I/O(httpcore-nio) to pom.xml . 我通过向pom.xml添加HttpComponents Core non-blocking I/O(httpcore-nio)解决了这个问题。 Now I have 我现在有

NoSuchMethodError: org.apache.http.nio.client.HttpAsyncClient.start()V

I've compared dependency:tree when project has spring boot parent and when it's commented out. 我已经比较了dependency:tree当项目具有spring boot parent时以及当它被注释掉时的dependency:tree It shown me that adding spring boot parent changes versions of my dependencies. 它告诉我,添加spring boot parent会更改我的依赖项的版本。 You can check diff here ( on left without spring boot, on right with spring boot) 你可以在这里检查差异(左边没有弹簧靴,右边是弹簧靴)

It seems that JIRA REST Java Client need older versions of some dependencies. 似乎JIRA REST Java Client需要某些依赖项的旧版本。 How can I solve this problem? 我怎么解决这个问题?

pom.xml 的pom.xml

...

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.0.0.RELEASE</version>
</parent>

...

<dependencies>

    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client-core</artifactId>
        <version>RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.3.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore-nio</artifactId>
        <version>4.3</version>
    </dependency>

</dependencies>

...

I was able to fix runtime in my Spring Boot application by overriding these properties in my pom.xml 通过覆盖我的pom.xml中的这些属性,我能够在Spring Boot应用程序中修复运行时

<properties>
    <httpasyncclient.version>4.0-beta3-atlassian-1</httpasyncclient.version>
    <httpclient.version>4.2.1-atlassian-2</httpclient.version>
</properties>

Note that there can be other problems if you decide to use http-client and/or httpassync client in your project (eg. using RestTemplate). 请注意,如果您决定在项目中使用http-client和/或httpassync客户端,则可能存在其他问题(例如,使用RestTemplate)。

Atlassian should definitely upgrade the dependencies. Atlassian肯定应该升级依赖项。

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

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