History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: MNG-3118
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Paul Gier
Votes: 0
Watchers: 6
Operations

If you were logged in you would be able to see more operations.
Maven 2

Test-classes should come before classes in the classpath

Created: 23/Jul/07 10:08 AM   Updated: 11/Jan/08 11:12 AM
Component/s: General
Affects Version/s: 2.0.7
Fix Version/s: 2.0.8, 2.1-alpha-1

Time Tracking:
Not Specified

File Attachments: 1. Text File MNG-3118-maven-project-r558713.patch (0.6 kb)

Issue Links:
Duplicate
 
Related
 

Patch Submitted: Yes


 Description  « Hide
Currently maven-project creates the test classpath in the order: classes, tests-classes, dependencies.
It would be better if test-classes came first because sometimes it is useful for a test class to replace a main class during testing. The opposite case is not normally true (i.e. one would not want to override a test class with one of the main classes).

 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Paul Gier - 23/Jul/07 10:10 AM
Simple patch that reverses the classpath ordering of classes and test-classes.

Brett Porter - 23/Jul/07 06:57 PM
Makes sense. One thing I want to review is how this is used - might be better to externalise this from maven-project into surefire.

Kenney Westerhof - 24/Jul/07 08:24 AM
fixed in trunk at r559042 and 2.0.x branch at 559045

Henri Tremblay - 05/Dec/07 08:00 AM
Hi, are you sure of the fix? Because I'm using maven 2.0.7 and test-classes was first in the classpath for almost a year now. I just tried with maven 2.0.8, doesn't work anymore. classes path seems to be first.

Is there a workaround?

Because this ordering is indeed extremely useful.


Andreas Bjärlestam - 05/Dec/07 08:54 AM
Hi, I have a similar problem. I need to mock a dependency library in my maven project, but maven puts the dependencies before the test-classes in the classpath. I see the same behaviour in both 2.0.7 and 2.0.8.

Benjamin Bentmann - 05/Dec/07 10:09 AM
Henri, Andreas, I think you are suffering from problems with Surefire 2.3. The MavenProject.getTestClasspathElements() in Maven 2.0.8 now properly puts test-classes before classes (see code in svn or Maven's debug output when using -X). However, Surefire 2.3 itself causes a reordering of the class path in its SurefireBooter as reported in SUREFIRE-61. This issue has been marked as fixed and I just noticed a svn tag for Surefire 2.3.1 has been created. So, it might be just a few days until a working Surefire version is released and this problem is entirely solved.

KlaasJan Elzinga - 07/Dec/07 04:48 AM
I am seeing the following:

in mvn 2.0.7 the test resources are put before the main-resources (src/main/resources) as expected.
in mvn 2.0.8 the main resources are put before the test-resources (src/test/resources).

Is this correct? I wouldnt expect it to happen. This caused my build to fail (connections made to a real environment ie stubs).

Is this related to this 'feature'?


Henri Tremblay - 07/Dec/07 05:02 AM
KlassJan, read the other comments. It seems the problem is coming from Surefire. So you can wait for the fix to be released or build the plugin yourself (if you do so, I would be interested in knowing if it worked)

KlaasJan Elzinga - 07/Dec/07 06:06 AM
Henri,

Thanks, I was wondering if it were just the classes or the classes and the resources. So its both, I'll just revert to 2.0.7 and wait for the surefire.


KlaasJan Elzinga - 19/Dec/07 02:06 AM
The surefire plugin was release today, but now all my tests fail on the 2.0.7. Isnt this a very serious regression?

In 2.0.7 my builds fail cause the surefire plugin is to new, 2.0.8 is not yet feasable ..... This mirroring of bugs in plugins is really really a very good idea. And than to solve it in a patch version.

I quit with maven.


Benjamin Bentmann - 19/Dec/07 03:09 AM
Well, how should Maven have kept backward compatibility here? There can only be one class path order.

If Surefire 2.3.1 is not usable for you (I feel happy with it and Maven 2.0.8), you can lock your POM to Surefire 2.3 by explicitly specifying <version>2.3</version> in the corresponding <plugin> element.


KlaasJan Elzinga - 19/Dec/07 02:50 PM
It just didn't feel like a patch version change. The fact that my build failed first with 2.0.8 and a week later with 2.0.7 doesn't feel right.

Backwards compatibility could be accomplished by mvn querying the surefire plugin version and construct the path with respect to that version. FYI, I was using mvn in an environment where upgrades are not allways possible/easy (...and all the dvl'ers had to upgrade), I know how to work around it, which meant a code change or an upgrade.

In the end I advised everyone to upgrade to 2.0.8. I'll stop commenting on this issue since this is not really the place for it anyway.

Thanks for the reaction though.


Ceki Gulcu - 07/Jan/08 04:41 AM

In my 20 months experience with Maven, the test-classes always came before "classes". This is a feature that I heavily rely on. Could you please kindly document this behavior as part of the Maven/Surefire contract, so that the re-ordering problem does not reoccur?

Many thanks in advance,


Juan Losada - 10/Jan/08 01:20 PM
Same to me Ceki. Days of work lost cause this.

Not to mention a regression issue in the surefire 2.3 with testng that only allows me to work with 2.4-SNAPSHOT

And although I love maven my only way out is to migrate everything to ant if I don't want to lose the testing options in my C.I. machine. This just sad!!


Benjamin Bentmann - 11/Jan/08 11:12 AM
While I agree that having a documentation would be nice, it does not prevent the bugs from reoccurring. What you really want are tests. Therefore, you are invited to vote for MNG-2365 and SUREFIRE-428.