【发布时间】:2015-08-24 14:30:31
【问题描述】:
在测试中,当我设置 pom.xml 的完整路径时,一切正常:
{code}
File[] files = Maven.resolver().loadPomFromFile("/full/system/path/pom.xml").importDependencies(ScopeType.TEST, ScopeType.PROVIDED).resolve().withTransitivity().asFile();
{code}
在很多例子中,只是使用了pom.xml,所以我尝试了:
{code}
File[] files = Maven.resolver().loadPomFromFile("pom.xml").importDependencies(ScopeType.TEST, ScopeType.PROVIDED).resolve().withTransitivity().asFile();
{code}
但在这种情况下,我得到了异常:
Path to the pom.xml file must be defined and accessible
如果我尝试传递 ""../pom.xml",结果相同。我必须将来自 pom.xml 的所有依赖项包含到在 arquillian 测试期间部署的战争存档中,是否有解决方法?
理想情况下,我想重用用于构建项目的 pom.xml。我不想在“src/test/resources”文件夹中有一个单独的 pom.xml 文件。
编辑:我已经掌握了@baba 的主要思想,但是我没有处理 pom.xml,而是通过 maven 资源过滤设置了一个 basedir 属性:
我已将tests.properties 文件添加到test/resources,在文件中添加了一个属性:
basedir=${basedir}
在 pom.xml 中我使用了 [http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html]
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
在测试中,我已经加载了所有依赖项:
ResourceBundle resourceBundle = ResourceBundle.getBundle ("tests");
String baseDir = resourceBundle.getString("basedir");
File[] files = Maven.resolver().loadPomFromFile(baseDir + File.separator + "pom.xml").importDependencies(ScopeType.TEST, ScopeType.PROVIDED).resolve().withTransitivity().asFile();
【问题讨论】:
-
你在 Linux 上运行吗?
-
@AndrewSmiley,是的,我是。
-
@Alexandr 那更好。
标签: java maven integration-testing shrinkwrap