10

有谁知道如何改变它?

我的意思是从

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

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

它与这个 surefire-plugin功能请求有关

这是因为 surefire-plugin 不能从 /target/classes 包含/排除资源......它只能通过<testResources>元素包含/排除资源,该元素只能影响 /target/test-classes,而不是 /target/classes

这一切都发生在 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 );
}
4

2 回答 2

1

考虑在单独的项目中进行测试。一般来说,当您有一个与 The Maven Way 冲突的项目时,这就是解决方案 - 将其拆分。

于 2011-06-29T16:09:16.933 回答
0

我从您的功能请求链接中了解到,您有一些src/main/resources/config.xml依赖项,其中还包含一个config.xml您想在测试中使用的依赖项。那正确吗?

如果是这种情况,您可以做的是将您的移动src/main/resources/config.xml到另一个地方(不是资源目录),就像他们通过设置战争jar插件配置src/config/config.xml将其包含在您的最终 JAR/WAR 中。

这样,您的测试将看到config.xml您的依赖项,但看不到您的src/config/config.xml,因为它不在类路径中。

于 2011-12-06T03:59:49.373 回答