在测试中,当我设置 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,而是basedir
通过 maven 资源过滤设置了一个属性:
我已将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();