-
1. Re: Best way to work with Maven Dependencies
plexusnexus Jul 6, 2012 9:13 AM (in response to gboro54)Hi,
this is quite easy, if you do in the following way
First create a POM below src/test/resources and call it arquillian-deps.xml.
Your POM should be similar to this one:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yourcompanygroupId>
<artifactId>xyz</artifactId>
<version>0.0.3-SNAPSHOT</version>
</parent>
<artifactId>xyz.yourcompany.testdependencies</artifactId>
<dependencies>
<dependency>
<groupId>com.yourcompany</groupId>
<artifactId>abc.service</artifactId>
<version>${project.version}</version>
<type>ejb</type>
</dependency>
</dependencies>
</project>
As you see, this POM inherits the parent POM of your project. With Maven 3 it also inherits the version of your project. As the result, this POM defines a dependency to com:yourcompany:abc.service:0.0.3-SNAPSHOT.
In your deployment method initialise your MavenDependecyResolver like this:
String pom = RegistrationServiceArquillianModuleTest.class.getResource("/arquillian-deps.xml").getFile();
EnterpriseArchive earArchive = ShrinkWrap.create(EnterpriseArchive.class, createEarName());
MavenDependencyResolver resolver = DependencyResolvers.use(MavenDependencyResolver.class)
.includeDependenciesFromPom(pom)
.goOffline();
Now you have only one place there to manage your dependencies, the arquillian-deps.xml.
For me it works perfect even with more dependencies.
-
2. Re: Best way to work with Maven Dependencies
kpiwko Jul 13, 2012 3:24 AM (in response to plexusnexus)Oliver, you're approach should generally work. Two notes though. It's hard to tell which ShrinkWrap version are you using, but in 2.0.0-alpha-1 following improvents are present:
1/ You should be able to simplify access to the pom via classpath: protocol:
DependencyResolvers.use(MavenDependencyResolver.class).loadEffectivePom("classpath:arquillian-deps.xml") .importAllDependencies().resolveAs(JavaArchive.class));
2/ There is a experimental classpath resolution a.k.a. reactor support in 2.0.0-alpha-1 activated by default. This means that you're able to resolve dependencies defined in your multimodule project even if they are not yet in any repository, like sybling modules.
To answer original question, you can alway load a version from a pom file and then you can omit it when asking for dependency:
DependencyResolvers.use(MavenDependencyResolver.class).loadEffectivePom("classpath:arquillian-deps.xml").artifact("com.company.billing:billing-common").resolveAs(...);
Reformatted.