1

I have a project A which creates 10 artifacts with same group id . For example generated artifacts from the project A will be -

<groupId>com.example.abc</groupId>
<artifactId>A1</artifactId>
<version>v1</version>

<groupId>com.example.abc</groupId>
<artifactId>A2</artifactId>
<version>v2</version>

Likewise from A1 to A10 and v1 to v10 . Group Id remains same.

The generated artifacts needs to be used in another project B but I need to exclude two dependencies which are common to all the ten artifacts generated by Project A.

I know I can add dependency management tag in Project B's pom.xml with explicit exclusions tag.

What I am looking for is a less verbose way of excluding those two dependencies ? I tried with

<dependencyManagement>
    <dependency>
            <groupId>com.example.abc</groupId>
            <artifactId>*</artifactId>
            <version>*</version>
            <exclusions>
                <exclusion>
                    <groupId>org.mockito</groupId>
                    <artifactId>mockito-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>  
 </dependencyManagement>

which is not working .

Is there any less verbose way ?

Akshay
  • 1,735
  • 6
  • 21
  • 29
  • First I would suggest to clean up the original artifacts cause adding a mockito-core is simply wrong ..only as a transitive dependency – khmarbaise Mar 03 '20 at 11:47

1 Answers1

1

could you declare the mockito dependency as a one provide.

   <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>YOUR VERSION</version>
        <scope>provided</scope>
    </dependency>  

Note: The dependency won't end up inside the build artifact but it's still available during tests

Take a look at here too. Regards.

Vishwa Ratna
  • 5,567
  • 5
  • 33
  • 55
Michel Foucault
  • 1,724
  • 3
  • 25
  • 48
  • 2
    you can specify version interval as well , like [2.0.0,] – Samir Mar 03 '20 at 10:25
  • 1
    The scope of the dependency made it to work. Now my pom is pretty clean – Akshay Mar 03 '20 at 10:26
  • If you really using mockito you should define it with `test` cause that usually belong only to test which in the end will not being packaged into the resulting war. – khmarbaise Mar 03 '20 at 11:46