I have a module as part of a framework that provides common features to other modules. I have created a class (UtilitiesForTesting) that provides some utils to be used only in my tests, so it's stored in test section of the module.
The module has the following structure:
project
-src
-main
-java
-com
-company
-product
+Foo
-test
-java
-com
-company
-product
+FooTest
-utility
+UtilitiesForTesting
UtilitiesForTesting class is visible inside the project but when I compile it the resulting jar does not contains any test class.
Now I want to use the modules in other modules, because I need this common functionality, but also I want to use testing utilities.
I don't want to place UtilitiesForTesting in the /main section, since I don't want to allow the use of this class in production code, only in test.
I want to have just a module that provides production classes to other module and test util to the same module, but restricting using the test utilities in the /main section.
Is there any way to use a class of the test scope of a module in other module?
In your pom.xml, under maven-jar-plugin, add below goal.
`<goal>test-jar</goal>`
All the files under src/test/java are compiled and bundled into artifact-test.jar.
In another module, if u want to use this artifact-test jar, use below configuration in dependency tag.
`<artifactId>artifactid</artifactId> <type>test-jar</type>'
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