3
votes

Short version:

How can I configure the maven POM of a AEM / CQ5 content package so the package embed different versions of the same OSGI bundle ?

Long version:

I'm building a content package for AEM (CQ5). This content package embed direct and indirect osgi dependencies needed for the project.

I have an issue with one of the bundle (let's call it BundleX) who remain inactivated after the content-package is deployed because of an unresolved package import on a specific version of Google Guava. Guava is part of the osgi dependencies that I embed with the project. The problem is that different bundles are dependent on different versions of Guava.

So I have:

project-content-package:

  • MyBundle:
    • depends on Guava:15.0 ( I do need this version for some features)
  • BundleX
    • depends on Guava:r06 (r06 < 15.0. I don't have the control on this bundle)

When making my content package, I'd like to embed the two guava versions. As we know, OSGi supports multiple versions of packages deployed at the same time.

Until now, in my AEM content package pom configuration, I had:

<plugin>
    <groupId>com.day.jcr.vault</groupId>
    <artifactId>content-package-maven-plugin</artifactId>
    <configuration>
        <embeddeds combine.children="append">
            <embedded>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <target>${cq.slingUrlSuffix}</target>
            </embedded>
            ...
        </embeddeds>
        ...
    </configuration>
    ...
</plugin>

The version of the embedded dependency is determined by maven and of course is unique for this maven project.

So, to sum up, to solve by problem, I should:

  • embed multiple versions of Guava in osgi container. The only solution I see is creating another artifical content package pom just to upload the other Guava dependency. But it's far to be optimal since I'd like my main package to contain all embedded osgi dependencies.

  • override the version of the dependency of bundle2 from r06 to 15.0, so I need only Guava 15.0 in my container. Since I don't have the control on this bundle, I should override that from outside, but I have no idea if it's possible to do that.

In advance, thank you very much for your help !

1

1 Answers

3
votes

The Apache Sling OSGi installer that AEM uses under the hood does not support installing several versions of the same (meaning having the same Bundle-SymbolicName) bundle. So just adding several versions of a bundle in a content package won't help, the highest bundle version always wins and the other ones are not installed.

You can install multiple versions using the standard OSGi tooling, like the webconsole.

A workaround is to repackage a bundle with your own symbolic name (like "foo.0.15" for V0.15) so that the Sling installer considers multiple versions as distinct bundles and installs them all.

In both cases those bundles to have the correct version ranges in their Export-Package statements, to avoid conflicts.