10

Does anybody know how to change it ?

I mean from

target/test-classes ... target/classes .... maven dependencies

to

target/test-classes ... maven dependencies .... target/classes 

It relates to this surefire-plugin feature request

It's because surefire-plugin cannot include/exclude resources from /target/classes ... it can only include/exlude resources via <testResources> element which can affect only /target/test-classes, not /target/classes

It all happens here in Surefire-plugin :

File projectClassesDirectory = new File( project.getBuild().getOutputDirectory() );
if ( !projectClassesDirectory.equals( classesDirectory ) )
{
    int indexToReplace = classpathElements.indexOf( project.getBuild().getOutputDirectory() );
    if ( indexToReplace != -1 )
    {
        classpathElements.remove( indexToReplace );
        classpathElements.add( indexToReplace, classesDirectory.getAbsolutePath() );
    }
    else
    {
        classpathElements.add( 1, classesDirectory.getAbsolutePath() );
    }
}

File projectTestClassesDirectory = new File( project.getBuild().getTestOutputDirectory() );
if ( !projectTestClassesDirectory.equals( testClassesDirectory ) )
{
    int indexToReplace = classpathElements.indexOf( project.getBuild().getTestOutputDirectory() );
    if ( indexToReplace != -1 )
    {
        classpathElements.remove( indexToReplace );
        classpathElements.add( indexToReplace, testClassesDirectory.getAbsolutePath() );
    }
    else
    {
        classpathElements.add( 0, testClassesDirectory.getAbsolutePath() );
    }
}

getLog().debug( "Test Classpath :" );

for ( Iterator i = classpathElements.iterator(); i.hasNext(); )
{
    String classpathElement = (String) i.next();

    getLog().debug( "  " + classpathElement );

    surefireBooter.addClassPathUrl( classpathElement );
}
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
lisak
  • 21,611
  • 40
  • 152
  • 243
  • 1
    This smells like you are trying to solve the wrong problem – Sean Patrick Floyd Jan 05 '11 at 10:57
  • @Sean Patrick Floyed I'm sure I don't, if you read the JIRA issue, especially last 3 of my comments, I have good reason for it – lisak Jan 05 '11 at 11:01
  • @lisak your comments seem to make sense, but the smell remains: There has got to be a better way to achieve what you are trying to do – Sean Patrick Floyd Jan 05 '11 at 11:06
  • @Sean Patrick Floyed you see but that is the workaround that implies from absence of the possibility to change resources in /target/classes when testing ... I really don't see why maven guys don't want it there. There are tons of such feature requests. The plugin has a Liferay's code generator, that uses META-INF/ as an output path, but I can't use META-INF when testing because I'm loading resources from dependency:[META-INF/] – lisak Jan 05 '11 at 11:12
  • And it's a common maven dependency I cannot classload it myself ... I just have to accept that it has resources I need on this conflicting path ... All that I can do, is copy the resources over to src/test/resources, but it is a Testing Archetype, I can't do that – lisak Jan 05 '11 at 11:15
  • Perhaps you can tell us what you're trying to achieve. Changing the classpath order is a means how to get to it which may be ok, but perhaps the 'real' question is much easier to answer? – Stefan Hendriks Jun 24 '11 at 06:13
  • We've discussed about that in the feature request. It's quite complicated – lisak Jun 26 '11 at 17:07

2 Answers2

1

Consider testing in a separate project. In general, when you have a project that conflicts with The Maven Way, that's the solution - split it up.

Ed Staub
  • 15,480
  • 3
  • 61
  • 91
0

What I understood from your feature request link, is that you have some src/main/resources/config.xml and a dependency that also contains a config.xml that you want to use in your tests. Is that right?

If that is the case, what you could do is to move your src/main/resources/config.xml to another place (not a resource dir), like src/config/config.xml and them include it in your final JAR/WAR by setting the war or jar plugin config.

In that way your tests will see the config.xml from your dependency but not your src/config/config.xml since it is not in the classpath.

Diego
  • 4,353
  • 1
  • 24
  • 22