简体   繁体   中英

How to use different version dependencies for each JAR

I have a maven project A that uses some Java library B , which is dependency stated in POM. That library uses some other library C that uses library D . The problem arises in compiling where both A and C are using that library D but different versions. It looks like this:

A ----- B
|       |
D(v1)   C
        |
        D(v2)

A can not change its dependency to D(v2) , but also if I exclude D(v2) in A 's POM:

<dependency>
    <groupId>...</groupId>
    <artifactId> C </artifactId>
    <exclusions>
        <exclusion>
            <groupId>...</groupId>
            <artifactId> D </artifactId>
            <version> v2 </version>
        </exclusion>
    </exclusions>
</dependency>

I will get compilation error that some class MissingClass is not resolved in class C . The most annoying thing is that only D(v2) has that Missing Class .

I am not somewhat skilled with Maven so is there some way to make Maven is using D(v1) dependency in A 's case, and D(v2) in B 's case?

This is more a problem of Java classpath. Could your scenario work if you run things via cmd line, without Maven? (ie run your app, and manually specify your classpath).

If the answer is yes, then you probably can do it in Maven; but my understanding from your description is that no, you couldn't run via cmd line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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