jeudi 4 janvier 2018

How to use classes from /src/test/java in different project?

I have a class in a commons library that I placed into /src/test/java. Then I want to reuse that class in any project having the commons library as dependency.

But the file cannot be imported.

Common custom library:

/src/test/java/com/myproject/utils/TestfileReader.java

Implementation project:

<dependencies>
    <dependency>
        <groupId>com.myproject</groupId>
        <artifactId>my-commons</artifactId>
        <version>1.0.0</version>
    </dependency>

usage:

/src/test/java/com/myproject/itest/SomeTest.java

import com.myproject.utils.TestfileReader;

Result: the import cannot be resolved.

But if I copy that file to /src/main/java/... it can be found correctly. So my commons library seems to be fine in general.

Question: how can I make this file visible only to my tests, while keeping it in /src/test/java folder?

Aucun commentaire:

Enregistrer un commentaire