Reputation: 43
For example, there is a project my-common which contains a my.properties file in src/main/resources and another version src/test/resources, which is used for tests.
Then there are other projects, for example my-service, which uses my-common and the src/main/resources/my.properties values.
How can I make the src/test/resources/my.properties available to unit tests in my-services/src/test/java?
Upvotes: 0
Views: 885
Reputation: 11958
The standard Maven way to to this is to create a test jar. The maven plugin maven-jar-plugin is used with the goal test-jar:
<project>
...
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
...
</project>
You would then need to depend on the test jar in the modules where you need to:
<project>
...
<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<type>test-jar</type>
<version>version</version>
<scope>test</scope>
</dependency>
</dependencies>
...
</project>
Upvotes: 1