![](/img/trans.png)
[英]Using Arquillian Shrinkwrap Resolver Maven reading dependencies from the pom.xml
[英]Maven resolver from pom.xml, Shrinkwrap
在测试中,当我将完整路径设置为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();
您必须首先实现一件事,然后再实现另外两件事。 这是第一件事:
公共静态LoadPomTask loadPomFromClassLoaderResource(最终字符串pathToPomResource)
既然我们意识到无法避免类路径,我们必须回答另外两个问题:
META-INF/maven/${groupId}/${artifactId}/pom.xml
) 建议的解决方案:由于META-iNF/MAVEN/${groupId}/${artifactId}
可能会发生更改, 因此您的代码中不应包含从那里加载内容的引用 。 所以我建议您看一下maven-resources-plugin 。 这样一来,您就可以在编译期间在您选择的位置复制pom.xml文件(我实际上建议您将其复制到两个位置:
/src/main/resources
和
/src/test/resources
在process-resources
process-test-resources
阶段和process-test-resources
阶段相应地, 请参见 : maven-build-lifecycles
把它们加起来:
如果要使用类型为(pom.xml)的位置而不是完整路径,则需要从类路径中加载pom.xml。
您需要在编译阶段使用maven-resources-plugin将pom.xml文件包括在类路径中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.