CASE: I have two projects A and B, project A has lots of csv files in its src/test/resources folder which project B wants to use in its application. Though it is not an ideal case when a test resources becomes a liablity of some other projects source folder. But we have this case. However, we can use these files in our test classes as well.
SOLUTION:
In project A where the csv files are present you have to make those files compiled in a jar and shared them across in the project B. There are other apporaches as well but this one seems to be working for me till now. Others are usefull when you have to share the resources NOT from the test folder but from the source folder.
Anyway, you have to define the following in the project A pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The above code will make snapshot/jar with suffix -tests which will use as classifier afterwards.
In Project b pom.xml you can use the maven dependency-plugin to extract files from jar:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>yourSourceGroup</groupId>
<artifactId>yourSourceArtifact</artifactId>
<version>1.0.0</version>
<type>jar</type>
<includes>path/to/Files.whatsoever</includes>
<outputDirectory>${project.build.directory}/your/target/folder</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
SOLUTION:
In project A where the csv files are present you have to make those files compiled in a jar and shared them across in the project B. There are other apporaches as well but this one seems to be working for me till now. Others are usefull when you have to share the resources NOT from the test folder but from the source folder.
Anyway, you have to define the following in the project A pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The above code will make snapshot/jar with suffix -tests which will use as classifier afterwards.
In Project b pom.xml you can use the maven dependency-plugin to extract files from jar:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>yourSourceGroup</groupId>
<artifactId>yourSourceArtifact</artifactId>
<version>1.0.0</version>
<type>jar</type>
<includes>path/to/Files.whatsoever</includes>
<outputDirectory>${project.build.directory}/your/target/folder</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
No comments:
Post a Comment