【发布时间】:2011-01-04 11:15:29
【问题描述】:
有人知道怎么改吗?
我的意思是从
target/test-classes ... target/classes .... maven dependencies
到
target/test-classes ... maven dependencies .... target/classes
它与这个surefire插件有关feature request
这是因为 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 );
}
【问题讨论】:
-
这听起来像是你在尝试解决错误的问题
-
@Sean Patrick Floyed 我确定我没有,如果您阅读 JIRA 问题,尤其是我的最后 3 个 cmets,我有充分的理由这样做
-
@lisak 你的 cmets 似乎有道理,但气味仍然存在:必须有更好的方法来实现你想要做的事情
-
@Sean Patrick Floyed 您会看到,但这是一种解决方法,这意味着在测试时无法更改 /target/classes 中的资源......我真的不明白为什么 maven 家伙不这样做'不想要它。有很多这样的功能请求。该插件有一个 Liferay 的代码生成器,它使用 META-INF/ 作为输出路径,但是我在测试时不能使用 META-INF,因为我正在从依赖项加载资源:[META-INF/]
-
这是一个常见的 maven 依赖项,我自己无法对其进行类加载......我只需要接受它在这条冲突的路径上有我需要的资源......我所能做的就是复制资源转到 src/test/resources,但它是一个测试原型,我不能这样做