[英]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 它涉及这个surefire-plugin 功能请求
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 这是因为surefire-plugin不能包含/排除来自/ target / classes的资源......它只能通过<testResources>
元素包含/排除资源,这只能影响/ target / test-classes,而不能影响/ target / classes
It all happens here in Surefire-plugin : 这一切都发生在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 );
}
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. 一般来说,当你有一个与Maven Way冲突的项目时,这就是解决方案 - 将其拆分。
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. 我从您的功能请求链接中了解到,您有一些src/main/resources/config.xml
以及一个依赖项,该依赖项还包含您要在测试中使用的config.xml
。 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. 如果是这种情况,你可以做的是将你的src/main/resources/config.xml
到另一个地方(不是资源目录),比如src/config/config.xml
,它们将它包含在你的最终JAR中WAR通过设置war或jar插件配置。
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. 这样,您的测试将从您的依赖项中看到config.xml
,而不是您的src/config/config.xml
因为它不在类路径中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.