3

In a Bndtools workspace, I would like to add dependencies to JUnit and Mockito in a certain project

Therefore the project's bnd.bnd file contains this -testpath instruction:

-testpath: \
    junit:junit;version=latest,\
    org.mockito:mockito-core;version=latest

A 'global' bnd file in cnf/ext/repositories.bnd denotes these repositories:

-plugin: \
    aQute.bnd.repository.osgi.OSGiRepository; \
        name=Bndtools Hub; \
        locations=https://raw.githubusercontent.com/bndtools/bundle-hub/master/index.xml.gz; \
    , \
    aQute.bnd.repository.maven.pom.provider.BndPomRepository; \
        releaseUrls=https://repo.maven.apache.org/maven2/; \
        pom=${workspace}/cnf/maven-central.xml; \
        location=cnf/cache/maven-central.xml; \
        name=Maven Central;

The maven-central.xml lists these dependencies:

<dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
  </dependency>
  <dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-core</artifactId>
    <version>2.6.3</version>
  </dependency>
</dependencies>

The Repositories view shows both repositories. The Mockito library is even present in both repositories: v2.6 in the Maven repository and v 1.x in Bndtools Hub

The JUnit dependency can be resolved just fine, but whatever I tried, the Mockito dependency cannot be resolved:

The Repositories view decorates the unresolvable entries with an exclamation mark [!] and NullPointerException

enter image description here

Debugging Bndtools leads me to the conclusion that there is no local copy of the respective POM files (see bnd issue #1849). However, I am unable to figure out as to why there is no POM file.

I've also tried other libraries instead of Mockito, AssertJ for example, without a notable difference, though. Hence this seems not to be an issue with Mockito itself.

Any hints as to why Mockito cannot be resolved or how to fix this would be very welcome.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79

1 Answers1

0

I'm not exactly sure why your example isn't working, but I've successfully used Bndtools 4.1 and 4.2-dev successfully with both Mockito and AssertJ (and both at the same time). The OSGi enRoute 7.0 templates include Mockito.

It is a little suspicious to me that your pom specifies 2.6.3 but the Bndtools repository view is showing 2.6.0. Seems to me that Bndtools isn't refreshing it or perhaps isn't parsing it properly. It also hasn't downloaded Mockito's transitive dependencies. Perhaps make sure you're not running in offline mode?

Try upgrading to the latest version of Bndtools and see if that fixes it. I've just tried it with 4.2-dev and Mockito 2.6.3 and it seems to work (including downloading the necessary transitive dependencies).

If this doesn't work, perhaps post the full maven-central.xml pom file rather than just the dependencies section (or does the file only contain the dependencies section?).

I hope that some of these suggestions help.

Also note (slightly unrelated): If you're using AssertJ with OSGi, make sure you use 3.11.1 or higher. Earlier versions had a small bug in the OSGi manifest which prevented assumptions from working (see https://github.com/joel-costigliola/assertj-core/issues/1290).

Fr Jeremy Krieg
  • 482
  • 5
  • 13