Jaraws
Jaraws

Reputation: 681

How to exclude tests maven dependency coming transitively

I got following scenario: Project A has dependency on Project B (and its test classes, test classes are provided to A via classifier tag - tests in maven dependency) Project A pom is as follows:

          <dependency>
            <groupId>sample.project</groupId>
            <artifactId>project-B</artifactId>
            <version>1.0</version>
          </dependency>
          <dependency>
            <groupId>sample.project</groupId>
            <artifactId>project-B</artifactId>
            <version>1.0</version>
            <classifier>tests</classifier>
          </dependency>

Now, I have got another project C, which depends on A. The problem is when I add dependency of Project A to C, I got Project B s tests jar transitively in Project C. Project C pom is as follows:

      <dependency>
        <groupId>sample.project</groupId>
        <artifactId>A</artifactId>
        <version>1.0</version>
      </dependency>

How can I avoid just tests jar of Project B in C (not the normal jar of Project B in Project C)?

It is that I want to exclude tests jar of Project B from Project C.

Thanks

Upvotes: 1

Views: 87

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35785

If a dependency is for tests only it should have the scope test:

          <dependency>
            <groupId>sample.project</groupId>
            <artifactId>project-B</artifactId>
            <version>1.0</version>
            <classifier>tests</classifier>
            <scope>test</scope>
          </dependency>

Then it will not be transitively included into other projects.

Upvotes: 1

Related Questions