In tests when I set a full path to pom.xml, everything works fine:
{code}
File[] files = Maven.resolver().loadPomFromFile("/full/system/path/pom.xml").importDependencies(ScopeType.TEST, ScopeType.PROVIDED).resolve().withTransitivity().asFile();
{code}
In a lot of examples, just pom.xml is used, so I tried:
{code}
File[] files = Maven.resolver().loadPomFromFile("pom.xml").importDependencies(ScopeType.TEST, ScopeType.PROVIDED).resolve().withTransitivity().asFile();
{code}
But in this case I get exception:
Path to the pom.xml file must be defined and accessible
Same result if I try to pass ""../pom.xml". I have to include all dependencies from pom.xml
into the war archive, that is deployed during arquillian tests, is there a workaround?
Ideally, I'd like to reuse the pom.xml that is used to build project. I don't want to have a separate pom.xml file in the "src/test/resources" folder.
EDIT: I've got the main idea of @baba, but instead of coping pom.xml, I've set a basedir
property via maven resource filtering:
I've added the tests.properties
file into test/resources
, added a property in the file:
basedir=${basedir}
In pom.xml I've used the [http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html]
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
In tests, I've loaded all dependencies:
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();
You have to realize one thing first and then two other things. Here is the first thing:
Now that we realized that there is no way to avoid the classpath, we have to answer two other questions:
META-INF/maven/${groupId}/${artifactId}/pom.xml
)Suggested solution: Since
META-iNF/MAVEN/${groupId}/${artifactId}
is subject to change, you shouldn't have reference in your code that loads the stuff from there. So I'd suggest you take a look at the maven-resources-plugin. Which'd allow you to copy the pom.xml file during compilation at a location of your choosing (I'd actually recommend you copy it to two locations:and
During the
process-resources
and theprocess-test-resources
phases accordingly: see maven-build-lifecyclesTo sum it up:
You need to load the pom.xml from the classpath if you want to be using a location of type (pom.xml) and not the full path
You need to include the pom.xml file during the compilation phase using the maven-resources-plugin to be in your classpath