簡體   English   中英

通過surefire-plugin更改要加載的類路徑上的位置順序

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

有人知道如何改變嗎?

我的意思是

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 );
}

考慮在單獨的項目中進行測試。 一般來說,當你有一個與Maven Way沖突的項目時,這就是解決方案 - 將其拆分。

我從您的功能請求鏈接中了解到,您有一些src/main/resources/config.xml以及一個依賴項,該依賴項還包含您要在測試中使用的config.xml 是對的嗎?

如果是這種情況,你可以做的是將你的src/main/resources/config.xml到另一個地方(不是資源目錄),比如src/config/config.xml ,它們將它包含在你的最終JAR中WAR通過設置warjar插件配置。

這樣,您的測試將從您的依賴項中看到config.xml ,而不是您的src/config/config.xml因為它不在類路徑中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM