34

I have a little bundle that uses Groovy to interpret scripts.

The manifest Import-Package instruction looks like this:

Import-Package: groovy.util;version="[1.8,2)"

The version range above clearly states the import version must be between 1.8 (inclusive) and 2.0 (exclusive).

When I run this bundle in an OSGi environment with only Groovy 1.8.6 installed, it works as expected... when I type inspect package requirement 4, it prints:

-> com.athaydes.gradle.osgi.groovy-1-8-6-runner [4] imports packages:
------------------------------------------------------------------
ipojo.example.code; version=0.0.0 -> com.athaydes.gradle.osgi.code-runner-api [1]
groovy.util; version=1.8.6 -> groovy-all [5]

This is exactly as I expected, and when I ask the CodeRunner to interpret this Groovy snippet:

GroovySystem.version

It correctly returns 1.8.6.

Now, when I start my OSGi environment with both Groovy 1.8.6 and 2.3.3 installed, when I inspect the packages for my bundle, I get this instead:

-> com.athaydes.gradle.osgi.groovy-1-8-6-runner [4] imports packages:
------------------------------------------------------------------
ipojo.example.code; version=0.0.0 -> com.athaydes.gradle.osgi.code-runner-api [1]

The groovy.util import is gone (even though the MANIFEST still has it, of course)! And now, when I run GroovySystem.version I get 2.3.3, not 1.8.6 as it should be!

This is crazy stuff, it seems like just the fact that a newer version of Groovy is present is breaking the OSGi promise that I should be able to use whatever version of a dependency I want.

I have tested this in Felix and Equinox, with the exact same result.

I have also used an exact version in the manifest instead of a range, but that did not change anything.

Can anyone see what exactly is going on here??

PS. if you don't believe me, try yourself, here's the project on GitHub: https://github.com/renatoathaydes/osgi-run/tree/next/osgi-run-test/ipojo-dosgi

Renato
  • 12,940
  • 3
  • 54
  • 85
  • 2
    I checked out the project and gave it a quick look, but gradle had problems finding the ipojo-plugin. Maybe you could add some instructions for building the bundles? Have you checked the actual MANIFEST.MF residing in the jar? – Rikard Dec 24 '14 at 09:07
  • Hi. The ipojo-plugin is available on JCenter, you need to add the jCenter() repo to the builscript repository list (see https://github.com/renatoathaydes/osgi-run/tree/next/ipojo-plugin). I checked the MANIFEST.MF, yes. I always look at it as I hoped that's the only source of information for the actual OSGi environment... but in my case, something else seems to be going on. – Renato Jan 01 '15 at 13:36
  • have you tried [1.8,2.0) as version range? – blackdrag Apr 29 '15 at 08:53
  • Do you see both dependencies installed in your OSGI container? Do you have any errors in your log? – perbellinio Jul 26 '16 at 08:47

1 Answers1

1

Don't use a version range. Explicitly set the version of groovy.util This might not seem helpful, but I believe it will work. We get a very similar problem when we try to generate Karaf features.xml files on dependencies with version ranges (we worked around this by writing our own plugin that removed the upper versioned item from the finished features file :( )

Richard
  • 1,070
  • 9
  • 22
  • Hi, thanks for the answer, but I mentioned in the question, near the end, that I tried using an exact version in the MANIFEST but it did not work. I will get back to this soon as quite a few people have been upvoting the question, so there seems to be some interest (I had gained the obscure question badge for this one, earlier!) – Renato Feb 19 '15 at 14:09