Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing order of locations on classpath to be loaded up by surefire-plugin

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 );
}
like image 255
lisak Avatar asked Jan 04 '11 11:01

lisak


1 Answers

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.

like image 130
Ed Staub Avatar answered Nov 15 '22 22:11

Ed Staub