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?
you can do this by specifying the type to test-jarscope.
<dependency>
<groupId>com.myproject</groupId>
<artifactId>my-commons</artifactId>
<version>1.0.0</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With