Exclusions in dependency management using wildcard

Akshay :

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 ?

Michel Foucault :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=20820&siteId=1