How to avoid "The package is not exported by the bundle dependencies" error in IntelliJ IDEA?
Asked Answered
F

6

10

I have created a new Maven project using the CQ5 archetype and imported it into IntelliJ IDEA. IntelliJ marks usages of some classes such as org.apache.felix.annotations.Component, org.apache.felix.annotations.Reference, etc. IntellIJ as erroneous with the following error message:

The package is not exported by the bundle dependencies

IntelliJ OSGi Error Message

  1. Is this a legitimate error?
  2. How can I fix it (as opposed to disabling the inspection)?
Fearsome answered 13/8, 2014 at 11:29 Comment(0)
A
3

I'm using version 12.1.4

  1. The error seems legit. I'm not able to find that package in the ACQ 5.6.1 Doc.

  2. I turn off the inspection by:

    • Right-clicking on the block in the right margin.
    • Click "Customize Highlighting level".
    • Bring the slider down to "None".
Allier answered 13/10, 2014 at 14:59 Comment(1)
I tried this and found that it turned off all my errors and warnings; definitely not what was intended! You can turn it back on again by right clicking the little 'off' icon at the top of the right margin.Praetor
D
3

Are you exporting those packages as part of the bundle definition? In the maven project, you should have the maven bundle plugin with <Export-Package>your.packages.here</Export-Package> defined. Are these packages included in that definition? If not, those services won't actually be availale in OSGi.

Dragoon answered 30/11, 2014 at 18:19 Comment(3)
Hi, all my packages are defined correctly and my project was built successfully with maven. However, I am still facing the same issue while using intellij idea to view my codes. Any thoughts?Cloudscape
First, try rebuilding your project in intellij. I've found that the intellij project files can get corrupt and they will not successfully fix themselves. For these packages, I also believe the latest versions of AEM are now using slightly different interfaces.Dragoon
I tried but still got those annoying suggestions. I changed the settings to ignore those since my code is working. Thanks.Cloudscape
M
1

In my case, I accidentally "configured OSGi" when I only wanted to configure Spring. The way I dealt with this issue was by right clicking the right margin at one of the affected lines, clicking "Customize Highlighting Level" --> "Configure Inspections". I think hippoLogic's solution will get rid of all your syntax-level error highlighting as well as helpful inspection-level highlighting. This way you can simply tune the latter to exclude OSGi.

It'd be even better to de-configure OSGi (which I haven't investigated), but here's a quick/dirty fix to reduce the highlighting noise.

Ministry answered 27/11, 2014 at 23:49 Comment(1)
If the OSGi facet is configured "by accident", simply remove the facet. Module settings -> Facets.Haunting
S
0

To Fix this check if the respective dependencies are present in the pom file, in your case I think it mught be present since you just imported them up from eclipse where it wasn't giving any error. Also check if the settings.xmml being referred to is correct, and is in right place and the correct one is been referred from intellij. your settings.xml is present in the maven home or might be reffered as a symbolic link in the maven home. Hope this helps.

Sheila answered 20/8, 2014 at 11:54 Comment(0)
G
0

just export related packages on maven build plugins as @Brenn's answer, deteails as below:

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>${maven.bundle.version}</version>
    <extensions>true</extensions>
    <configuration>
      <instructions>
        <Bundle-DocURL>${project.url}</Bundle-DocURL>
        <Bundle-Activator>
          org.apache.tika.parser.internal.Activator
        </Bundle-Activator>
        <Import-Package>
          org.w3c.dom,
          org.apache.tika.*,
          *;resolution:=optional
        </Import-Package>
        <Export-Package>
          your package here
        </Export-Package>
      </instructions>
    </configuration>
  </plugin>
Gamb answered 26/12, 2019 at 10:5 Comment(0)
I
-1

I work on a project clone from github, it's unrelated about OSGI, so i think that's a bug of idea or i accidentally turn on . Then i assume the feature of "OSGI" in idea work depend on plugin,so i diabel this plugin Disable the OSGI plugin, the error message disappear.

in mac os:

command + shift + a, type plugin

search "OSGI", then disable this plugin.

Irrupt answered 21/8, 2019 at 6:36 Comment(3)
Would you like to explain this solution in order to improve your chances for upvotes?Expeller
@Expeller I work on a project clone from github, it's unrelated about OSGI, so i think that's a bug of idea or i accidentally turn on . Then i assume the feature of "OSGI" in idea work depend on plugin,so i diabel this plugin.Irrupt
Please edit your question to add an explanation, instead of hiding it in a comment.Expeller

© 2022 - 2024 — McMap. All rights reserved.