WeAreLegion
WeAreLegion

Reputation: 15

Third party jar depending on other third party jars

I want to use a third party jar, let's call it Third.jar. This Third.jar file is in a directory A/. In A/lib/ there are more jars (let's say from party X, and party Y). When I use maven-install-plugin, I only make available the Third.jar in the local Maven repository, but when I then try to run it it will fail, because it cannot find classes contained in those party X, and party Y jars.

Since I am not supposed to care about the internal dependencies of Third.jar, how is this supposed to be solved with Apache Maven 3.3.3?

Upvotes: 1

Views: 470

Answers (3)

kswaughs
kswaughs

Reputation: 3087

If you really sure that you don't want other jars and your application doesn't break then you can specify exclusions in your pom.xml dependencies like this.

<dependency>
    <groupId>YourGroup</groupId>
        <artifactId>Third</artifactId>
        <version>version</version> 
    <exclusions>
    <exclusion>
        <groupId>XGroup</groupId>
        <artifactId>X</artifactId>
    </exclusion>
    <exclusion>
        <groupId>YGroup</groupId>
        <artifactId>Y</artifactId>
    </exclusion>
  </exclusions>
</dependency>

If the other jars are not added in your local repository then remove those other dependencies in pom.xml of third maven repository.

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533442

Unless you know you don't need a dependency, you have to assume you need them all.

If you need to save space, you can drop a dependency you know you are not using, however in general this is time consuming and error prone and I would avoid doing this.

Upvotes: 1

Kalyan Chavali
Kalyan Chavali

Reputation: 1348

You need not care for internal dependencies for a jar if you can only find it in maven repository , because maven takes care of this for you. But if you are adding a third party jar to your local repository using maven-install-plugin , you are the only one who should take care of the internal dependencies of the added jar. Which means you would need to use maven-install-plugin and add party X and party Y jars in your local repo and add them in pom.xml along with Third.jar

Upvotes: 1

Related Questions