Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven test dependencies of dependency

I have a parent project which has dependencies with scope test

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-firefox-driver</artifactId>
        <version>2.31.0</version>
        <scope>test</scope>
    </dependency>

Now I "mvn install"ed the parent project, when I include this parent project as dependency in my child project

    <dependency>
        <groupId>group</groupId>
        <artifactId>parentproject</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

selenium-firefox-driver is not available. The compile scoped dependencies are available.

How can I make it available? I won't change the scope neither in the parent project nor in the child project. Because I need some classes of the parent in at runtime

like image 555
wutzebaer Avatar asked Sep 02 '25 07:09

wutzebaer


2 Answers

As outlined by Charlee Chitsuk in his answer, your scope (compile in the child project) will omit the test dependencies of the included project.

A clean solution would be to separate the concerns of the parent project into two separate projects:

  • parent-test: This project includes your test dependencies (e.g. selenium-firefox-driver) with a compile scope. Additionally, this project contains all of your generic test resources, e.g. JUnit base classes, in src/main/java.
  • parent-business: This project contains only the business functionality of the parent project. Include parent-test here with test scope.

In your child project, you can now include parent-test with scope test as well, giving you access to its resources with the right scope.

This setup will provide a clear project structure with clean scoping, avoiding issues like you have mentioned. Yes, it's a bit more complex due to the additional project, but it's a lot cleaner as well.

like image 154
nwinkler Avatar answered Sep 05 '25 00:09

nwinkler


Instead of including the parent project as dependency in your child pom, you should make the parent project as the parent of your child pom.

<parent>
   <groupId>group</groupId>
   <artifactId>parentproject</artifactId>
   <version>0.0.1-SNAPSHOT</version>
</parent>

You cannot call it a parent project otherwise.

like image 25
Raghuram Avatar answered Sep 05 '25 01:09

Raghuram