Maven 1.x Test Plugin

Order of classpath entries should be changed

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Description:
    Hide

    Behavior of my application is controlled through set of configuration files(like log4j.propertrties).

    I want to control behavior of my application differently for the test
    environment and differently for the production environment.

    The problem is that currently in maven the "production" resources are preceding the test resources in the classpath
    and [test] plugin is always taking them in first order.

    I am including short example showing where is the problem.
    Basically in it I have two log4j.properties files: one in
    'test-resources', second in 'resources' directory.
    This example shows that the the one kept in test-resources is never used and it is not possible to easily control
    the "test environment" when it is overlapping with "production'
    environment".

    As a result of this program the output of log statements is always written to production.log. Test resources are containing log4j.properties file which configures the log system for tests and directs log statements to a file test.log. This example shows that
    this file is never created.

    Other problem here is: if any of the dependencies in the classpath contains
    log4j.properties this file will even preceeds the log4j.properties in the classpath.
    So the best solution in my opinion will be to have followiing order of entries in the class path:

    <classpath>
    <pathelement location="${maven.test.dest}"/>
    <path refid="maven.dependency.classpath"/>
    <pathelement location="${maven.build.dest}"/>
    <pathelement path="${plugin.getDependencyPath('junit')}"/>
    </classpath>

    The problem is generic and not only typical to log4j. The same applies for example to jndi.properties.

    Michal Maczka

    Show
    Behavior of my application is controlled through set of configuration files(like log4j.propertrties). I want to control behavior of my application differently for the test environment and differently for the production environment. The problem is that currently in maven the "production" resources are preceding the test resources in the classpath and [test] plugin is always taking them in first order. I am including short example showing where is the problem. Basically in it I have two log4j.properties files: one in 'test-resources', second in 'resources' directory. This example shows that the the one kept in test-resources is never used and it is not possible to easily control the "test environment" when it is overlapping with "production' environment". As a result of this program the output of log statements is always written to production.log. Test resources are containing log4j.properties file which configures the log system for tests and directs log statements to a file test.log. This example shows that this file is never created. Other problem here is: if any of the dependencies in the classpath contains log4j.properties this file will even preceeds the log4j.properties in the classpath. So the best solution in my opinion will be to have followiing order of entries in the class path: <classpath> <pathelement location="${maven.test.dest}"/> <path refid="maven.dependency.classpath"/> <pathelement location="${maven.build.dest}"/> <pathelement path="${plugin.getDependencyPath('junit')}"/> </classpath> The problem is generic and not only typical to log4j. The same applies for example to jndi.properties. Michal Maczka
  1. test-diff.txt
    (1 kB)
    Michal Maczka
    03/Mar/03 5:11 AM
  2. test.zip
    (4 kB)
    Michal Maczka
    03/Mar/03 5:09 AM

Activity

Hide
Michal Maczka added a comment - 03/Mar/03 5:09 AM

Test case - to run type:
maven test

Show
Michal Maczka added a comment - 03/Mar/03 5:09 AM Test case - to run type: maven test
Hide
Michal Maczka added a comment - 03/Mar/03 5:11 AM

Patch

Show
Michal Maczka added a comment - 03/Mar/03 5:11 AM Patch
Hide
Robert Dawson added a comment - 08/Apr/03 9:26 AM

I agree that this issue should be looked at, and would suggest that the classpath order should be:
<pathelement location="${maven.test.dest}"/>
<pathelement location="${maven.build.dest}"/>
<path refid="maven.dependency.classpath"/>

i.e. test related elements get a higher priority than either build ones or the maven dependency classpath.

Show
Robert Dawson added a comment - 08/Apr/03 9:26 AM I agree that this issue should be looked at, and would suggest that the classpath order should be: <pathelement location="${maven.test.dest}"/> <pathelement location="${maven.build.dest}"/> <path refid="maven.dependency.classpath"/> i.e. test related elements get a higher priority than either build ones or the maven dependency classpath.
Hide
Ben Walding added a comment - 03/Aug/03 9:09 PM

Removed xml breaking characters.

Show
Ben Walding added a comment - 03/Aug/03 9:09 PM Removed xml breaking characters.
Hide
dion gillard added a comment - 24/Sep/03 3:01 AM

Applied similar fix today

Show
dion gillard added a comment - 24/Sep/03 3:01 AM Applied similar fix today
Hide
David Wong added a comment - 31/Jan/08 7:17 PM

Hi,

Has this issue been fixed? When I do mvn -X to see the classpath when running an unit test; the build path is still before the test path. I'm running Maven 4.2.

[DEBUG] Test Classpath :
[DEBUG] W:\data\ejb\target\classes
[DEBUG] W:\data\ejb\target\test-classes
[DEBUG] ...

Shouldn't test path be come before the build path?

Thanks,
David

Show
David Wong added a comment - 31/Jan/08 7:17 PM Hi, Has this issue been fixed? When I do mvn -X to see the classpath when running an unit test; the build path is still before the test path. I'm running Maven 4.2. [DEBUG] Test Classpath : [DEBUG] W:\data\ejb\target\classes [DEBUG] W:\data\ejb\target\test-classes [DEBUG] ... Shouldn't test path be come before the build path? Thanks, David

People

  • Assignee:
    Unassigned
    Reporter:
    Michal Maczka
  • Votes:
    2
    Watchers:
    1

Dates

  • Created:
    03/Mar/03 5:07 AM
    Updated:
    31/Jan/08 7:17 PM
    Resolved:
    26/Sep/03 11:34 AM