azpublic
azpublic

Reputation: 1404

Maven : excluding the main artifact itself from a dependency

When adding a dependency to a POM.xml, Is it possible to exclude the main artifact itself. In other words I want to add a dependency to my pom and I want to download only its dependencies, not the main jar.

Here's what I want to do :

 <dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
    <version>2.12</version>
    <exclusions>
        <exclusion>
            <groupId>net.sourceforge.htmlunit</groupId>
            <artifactId>htmlunit</artifactId>
        </exclusion>
     </exclusions> 
</dependency>

I know this might seem strange but I actually have a modified version of the htmlunit project in my source folder and what I actually want is only the libraries it depends on without having to add them all to my pom.

I tried the above and it seems the htmlunit-2.12.jar is added to my project, which is exactly what I want to avoid.

Anything I could do to work around this?

Upvotes: 1

Views: 1405

Answers (2)

DB5
DB5

Reputation: 13978

You can simply define a dependency to htmlunit's pom instead of the jar. So you would define the dependency as follows:

<dependencies>
    <dependency>
        <groupId>net.sourceforge.htmlunit</groupId>
        <artifactId>htmlunit</artifactId>
        <version>2.12</version>
        <type>pom</type>
    </dependency>
    <!-- other project dependencies go here -->
</dependencies>

You will then get all dependencies defined in the pom included in your project transitively, but the htmlunit jar would not be included.

Upvotes: 2

Satyam Koyani
Satyam Koyani

Reputation: 4274

By reading your question I can say that you wants to add dependencies mentioned in pom file of the other project jar excluding that jar.

You can achieve this by this way ,Here i show code in general Change respective attribute value as per your requirement

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>other.pom.group.id</groupId>
            <artifactId>other-pom-artifact-id</artifactId>
            <version>SNAPSHOT</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>   
    </dependencies>
</dependencyManagement>

On maven website there is a far better description on this dependency management see this Importing dependency and Dependency Management

Upvotes: 0

Related Questions