[ https://jira.codehaus.org/browse/SUREFIRE-443?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Tibor Digana closed SUREFIRE-443. --------------------------------- Resolution: Won't Fix > Provide option to merge test classpath into one directory > --------------------------------------------------------- > > Key: SUREFIRE-443 > URL: https://jira.codehaus.org/browse/SUREFIRE-443 > Project: Maven Surefire > Issue Type: New Feature > Components: classloading > Affects Versions: 2.4 > Environment: Maven 2.0.8 > Reporter: Cory Prowse > Priority: Minor > Fix For: Backlog > > > Please provide an option for the test classpath to be merged into one > directory. > Maven sets up the class files as follows: > {noformat} > |-- target/test-classes > | `-- Unit Test classes > |-- target/classes > `-- Classes to be tested > {noformat} > When running unit tests, the desired outcome is for any file in the > "target/test-classes" tree to override those in the "target/classes". > Specifically that any file in classes is ignored and overridden by the file > in test-classes for the tests to work as expected. > (In a sense a union on these two file trees in the order specified) > The problem arises when using a container such as Embedded JBoss to test > which treats each directory as a separate scope for classloading. > Reading the ejb-3_0-fr-spec-persistence.pdf section "6.2.2 Persistence Unit > Scope" spells it out quite clearly (a very short one page read) that if the > "target/test-classes" and "target/classes" are each treated as a separate > ejb-jar, then the runtime environment is not going to work due to these > scoping rules. > I have an ugly hack in place as follows which has the desired effect, but it > would be more preferable if instead Maven Surefire provided an option to > merge the directories together and have just one directory in the test > classpath. > {noformat} > <build> > <plugins> > ... > <plugin> > <!-- This correctly merges the test-classes and classes > directories for an EE container --> > <artifactId>maven-antrun-plugin</artifactId> > <executions> > <execution> > <id>setupTestClasspath</id> > <phase>test-compile</phase> > <configuration> > <tasks> > <echo message="Setting up a single merged > test classpath directory" /> > <!-- move the originals --> > <mkdir dir="${basedir}/target/tmp" /> > <move file="${basedir}/target/classes" > todir="${basedir}/target/tmp" /> > <move file="${basedir}/target/test-classes" > todir="${basedir}/target/tmp" /> > <!-- Merge into new directory --> > <copy todir="${basedir}/target/test-classes" > overwrite="true"> > <fileset > dir="${basedir}/target/tmp/test-classes" /> > </copy> > <copy todir="${basedir}/target/test-classes" > overwrite="false"> > <fileset > dir="${basedir}/target/tmp/classes" /> > </copy> > <mkdir dir="${basedir}/target/classes" /> > </tasks> > </configuration> > <goals> > <goal>run</goal> > </goals> > </execution> > <execution> > <id>restoreTestClasspath</id> > <phase>test</phase> > <configuration> > <tasks> > <echo message="Restoring original classes > directories" /> > <delete dir="${basedir}/target/classes" /> > <move file="${basedir}/target/test-classes" > tofile="${basedir}/target/test-classes-MERGED" /> > <move file="${basedir}/target/tmp/classes" > todir="${basedir}/target" /> > <move > file="${basedir}/target/tmp/test-classes" todir="${basedir}/target" /> > </tasks> > </configuration> > <goals> > <goal>run</goal> > </goals> > </execution> > </executions> > </plugin> > ... > {noformat} -- This message was sent by Atlassian JIRA (v6.1.6#6162)