Bayani Portier
Bayani Portier

Reputation: 660

OSGI dependency issue with Sling Models project

I'm having a slight problem with incorporating the appropriate maven dependencies into my project for sling models.

When I deploy my bundle, I get the following import that can't be resolved:

org.apache.sling.models.annotations,version=[1.1,2) -- Cannot be resolved

I believe I have included this with the following dependencies:

<dependency>
    <groupId>org.apache.sling</groupId>
    <artifactId>org.apache.sling.models.api</artifactId>
</dependency>
<dependency>
    <groupId>org.apache.sling</groupId>
    <artifactId>org.apache.sling.models.impl</artifactId>
</dependency>

I tried using:

<Embed-Transitive>true</Embed-Transitive>
<Import-Package>*</Import-Package>

in my bundle compile instructions, but this has just resulted in a ton of other dependencies not being resolved.

Surely I've gone down the garden path here somewhere. Any help would be greatly appreciated.

Upvotes: 0

Views: 3632

Answers (2)

Neil Bartlett
Neil Bartlett

Reputation: 23948

Using Embed-Transitive is almost always a terrible idea. It traverses the entire transitive dependency hierarchy in Maven and pulls each one of those JARs into your own JAR. As a result you inherit all the package dependencies of all that crap you have dragged in.

When you have a bundle such as yours that requires an import -- in this case org.apache.sling.models.annotations -- the best solution is to find another bundle already available that exports the same package.

Upvotes: 1

Bertrand Delacretaz
Bertrand Delacretaz

Reputation: 6100

The org.apache.sling.models.api V1.0.2 bundle does export the following packages:

javax.inject,version=0.0.0
org.apache.sling.models.annotations,version=1.1.0
org.apache.sling.models.annotations.injectorspecific,version=1.0.0
org.apache.sling.models.spi,version=1.0.0
org.apache.sling.models.spi.injectorspecific,version=1.0.0

So if that bundle is active in your Sling instance, the org.apache.sling.models.annotations,version=[1.1,2) import should resolve.

Note that adding bundles to your maven dependencies might not be sufficient to install them in the running instance, what matters is whether the models.api bundle is active as seen from /system/console/bundles

Upvotes: 1

Related Questions