I've searched the forum to find the answer to my problem, but I was unable to find it. My problem is, that:
I have two projects: ProjectA and ProjectB. ProjectB uses ProjectA. In ProjectA i have two folders: /src/main/resources and /src/test/resources. In ProjectB i run: mvn clean install. I want, that in the test phase, classes in ProjectB use resources from /src/test/resources instead of /src/main/resources.
This is what I tried: http://www.waltercedric.com/java-j2ee-mainmenu-53/361-maven-build-system/1349-maven-reusing-test-classes-across-multi-modules-projects.html
It is similar to my problem, but after I configured the test-jar goal for ProjectA, ProjectB still runs the tests in the way, that classes in ProjectA use properties from /src/main/resources instead of /src/test/resources.
My pom.xml in ProjectA looks like:
<project ...>
<parent>
...
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ProjectA</artifactId>
<packaging>jar</packaging>
<dependencies>
...
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
In ProjectB my pom.xml looks like:
<project ...>
<parent>
...
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ProjectB</artifactId>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sensano</groupId>
<artifactId>ProjectA</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ProjectA</groupId>
<artifactId>ProjectA</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
</dependencies>
</project>
Is there a method Any help would be appreciated!
Sincerely,
Mateusz Moroz
Right click on maven project --->Click on Build Path ----->Click on New Source Folder. New source folder window will open, give the name to your folder example - src/test/source. click on Finish.
The src/main Directory As the name indicates, src/main is the most important directory of a Maven project. Anything that is supposed to be part of an artifact, be it a jar or war, should be present here. Its subdirectories are: src/main/java – Java source code for the artifact.
Via the resources area in the pom you can filter files from their way src/main/resources to the target/classes folder. The lifecycle of Maven is not influenced by this. I have added resources successfully in . Jar file.
The src/main/resources
are packed to the jar file named ProjectA.jar
as the following structure
ProjectA.jar
|`-com
| `-sensano
| `-foo
`-[the resource form src/main/resources]
Sadly the src/test/resources
are also packed to the jar file named ProjectA-tests.jar
as the following structure as well.
ProjectA-tests.jar
|`-com
| `-sensano
| `-foo
`-[the resource form src/test/resources]
If the resource name that you require are the same name for both from src/main/resources
and src/test/resources
. There may be some class loader trouble. IMHO, the nearest wins.
Since you put the ProjectA
before the ProjectA-tests
, then may be the root cause that the ProjectB
will use the src/main/resources
from ProjectA
since it is nearest.
Please try to swap by putting the ProjectA-tests
before the ProjectA
as the following: -
<dependencies>
<dependency>
<groupId>com.sensano</groupId>
<artifactId>ProjectA</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>com.sensano</groupId>
<artifactId>ProjectA</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
The nearest will be the ProjectA-tests
, and ProjectB
should use the src/test/resources
instead.
I hope this may help.
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