The simplest task is to create another project for packing classes for a test jar, and then set this up as a regular test-scoped dependency.
If you do not want / cannot do this, you can use the build plugin to create a flag in the process-test-classes phase (i.e., after the tests have been compiled, but before the tests are run). The configuration below will invoke the build plugin to create a jar named classloader-test-deps in this phase in the target directory. Then your tests can use this jar as needed.
The assembly plugin uses an assembly descriptor (in src / main / assembly, called test-assembly.xml), which packs the contents of the target / test classes. I set a filter to include the contents of the com.test package and its children. This assumes that you have a package name agreement that you can apply to the contents of the jar.
The build plugin will add the jar by default as an additional artifact, specifying attach as false, it will not be installed / deployed.
<plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.2-beta-2</version> <executions> <execution> <id>create-test-dependency</id> <phase>process-test-classes</phase> <goals> <goal>single</goal> </goals> <configuration> <finalName>classloader-test-deps</finalName> <attach>false</attach> <descriptors> <descriptor>src/main/assembly/test-assembly.xml</descriptor> </descriptors> </configuration> </execution> </executions> </plugin>
This is the contents of test-assembly.xml
<assembly> <id>test-classloader</id> <formats> <format>jar</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>${project.build.testOutputDirectory}</directory> <outputDirectory>/</outputDirectory> <includes> <include>com/test/**</include> </includes> </fileSet> </fileSets> </assembly>
source share