Reputation: 1897
I've got a Maven build for an OSGI project I'm working on. I'd like to use some functionality from Google's guava-osgi library, version 11.0.1.
One of the projects I'm depending on has a dependency on guava-osgi, version 10.0.0. I know that having multiple versions for a particular dependency is feasible, but I'm having a little trouble with it.
Specifying the dependency on 11.0.1 in my project's pom compiles just fine, but when I run my unit tests, Java's pulling in version 10.0.0, which results in a runtime error. Specifically, one of the classes in 11.0.1 has the same name as an interface in 10.0.0, so Java barfs when I try to instantiate it.
Is there a way to do this elegantly?
Upvotes: 1
Views: 1043
Reputation: 2776
Since you are working on a OSGi based environment you can easily specify the needed guava version using the bundle plugin. But, it's important to understand that at compile-time, and at unit testing time (ie. within Maven), it doesn't know/care about the OSGi environment you created. So, you have to use some trick as mentioned in other answers. I haven't tested those though.
Upvotes: 0
Reputation: 2369
mvn dependency:tree
guava-osgi:10.0.0
versionguava-osgi:10.0.0
from test scope...
<dependency>
<groupId>dep1-groupid</groupId>
<artifactId>dep1-artifactid</artifactId>
<version>dep1-version</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.googlecode.guava-osgi</groupId>
<artifactId>guava-osgi</artifactId>
</exclusion>
</exclusions>
</dependency>
...
Upvotes: 4
Reputation: 1248
You could try to exclude the 10.0.0 version from the 'project i depend on'
...
<dependency>
<groupId>project i depend on</groupId>
<artifactId>project</artifactId>
<version>2.0.0</version>
<exclusions>
<exclusion>
<groupId>com.googlecode.guava-osgi</groupId>
<artifactId>guava-osgi</artifactId>
</exclusion>
</exclusions>
</dependency>
...
Upvotes: 0