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)?

6 Answers 6

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".
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. Sep 13, 2017 at 12:00
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.

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?
    – Drake .C
    Apr 25, 2019 at 20:50
  • 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.
    – Brenn
    Apr 26, 2019 at 1:28
  • I tried but still got those annoying suggestions. I changed the settings to ignore those since my code is working. Thanks.
    – Drake .C
    Apr 26, 2019 at 17:39
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.

1
  • If the OSGi facet is configured "by accident", simply remove the facet. Module settings -> Facets.
    – makasprzak
    Mar 31, 2015 at 13:39
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.

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>
-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.

3
  • 1
    Would you like to explain this solution in order to improve your chances for upvotes?
    – Yunnosch
    Aug 21, 2019 at 6:38
  • @Yunnosch 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.
    – inkinworld
    Aug 21, 2019 at 9:40
  • Please edit your question to add an explanation, instead of hiding it in a comment.
    – Yunnosch
    Aug 21, 2019 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.