Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing a new version of Groovy on my OSGi environment makes my bundle import it, though it shouldn't

Tags:

java

groovy

osgi

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

like image 285
Renato Avatar asked Aug 10 '14 21:08

Renato


1 Answers

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 :( )

like image 124
Richard Avatar answered Nov 20 '22 01:11

Richard