How to avoid "The package is not exported by the bundle dependencies" error in IntelliJ IDEA? - maven

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
Is this a legitimate error?
How can I fix it (as opposed to disabling the inspection)?

I'm using version 12.1.4
The error seems legit. I'm not able to find that package in the ACQ 5.6.1 Doc.
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".

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.

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.

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.

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>

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.

Related

How to find out about unused dependencies Maven in Intellij Idea

My project is growing but i have many unused dependencies, how to find out, which one i really need, and which one is really useless? There is a some Intellij Idea Extensions?
You can run the Maven goal dependency:analyze which lists the dependencies that are not used in your source code. Beware, though, that sometimes dependencies are necessary although they are not referenced in source code.
Add below plugin in your pom
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
</plugin>
Find maven option on Intellij, and under plugin you can trigger dependency:analyze-report

Unresolved plugin: 'org.apache.maven.plugins:maven-jar-plugin:2.4'

After I use IntelliJ IDEA to create a maven module, there is some problem in the Maven Projects view. And when my cursor hover on the maven project, i see this:
Project:
cn.itcast.babasport:parent:1.0-SNAPSHOT
Location:
/home/shuaidi/IdeaProjects/parent/pom.xml
Problems:
Unresolved plugin: 'org.apache.maven.plugins:maven-jar-plugin:2.4'
Unresolved plugin: 'org.apache.maven.plugins:maven-compiler-plugin:3.1'
Unresolved plugin: 'org.apache.maven.plugins:maven-surefire-plugin:2.12.4'
Unresolved plugin: 'org.apache.maven.plugins:maven-install-plugin:2.4'
Unresolved plugin: 'org.apache.maven.plugins:maven-site-plugin:3.3'
This is my first time using IntelliJ IDEA, so I do these thing with a new installed IDEA and a new installed maven, and i just create a maven module and didn't do any other thing. I don't know why these problem appearance.
I just want to create a maven module without any problem.
ps:
this is all my pom file.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.itcast.babasport</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
This is a duplicate of Maven plugins can not be found in IntelliJ. The top answers there did not work for me, so I'll describe what I did.
I just put the needed plugins into my ~/.m2/repository. There are two ways that achieve that. Either download the files manually with mvn dependency:get, or (my preferred way) make the plugins a dependency in some (whichever) pom.xml and build that project.
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<type>maven-plugin</type>
</dependency>
Now you can remove the dependencies. Then click "Reimport all Maven Projects" in Intellij (the blue circular arrows icon).
This issue seems completely harmless, but the squiggly lines are kind of infuriating, so I am glad I was able to get rid of them.
Instead of trying to install the plugin into your repository, actually delete it from your repository. It might have a corrupt or unsupported version that IJ cannot parse.
see https://stackoverflow.com/a/44883900/5093961
Change Maven home directory in Maven setting, and select supported Maven bundle version (Maven 2 or Maven 3), then apply setting. It's worked for me.
In my case same situation occurred because of different version exist in same system.
System have version 2.** and my project expect 3.** something
in such case, i use maven wrapper instead of maven to build project.
mvn clean install
instead of,
mvnw clean install
If you want this error to be gone without having to worry about all those xml files and copy pasting stuff just try the below solution
Note: This is manual way
In your InteliJ IDEA, go to search and type "Project Structure"
Search>Project Structure
or press:
Ctrl + Alt + Shift + S
Now go to Libraries under project settings
Project Settings>Libraries
Now look for red lined dependencies and click it
For example:
Click "Maven: javax:javaee-web-api:7.0"
Now look whether all three files are red lined
Example: Classes, Sources, JavaDocs
If any of the path under these names are redlined then go to that path and keep the folder open
For example: The path would look like this
Classes
C:\Users\shifny.m2\repository\javax\javaee-web-api\7.0\javaee-web-api-7.0.jar
Sources
C:\Users\shifny.m2\repository\javax\javaee-web-api\7.0\javaee-web-api-7.0-sources.jar
JavaDocs
C:\Users\shifny.m2\repository\javax\javaee-web-api\7.0\javaee-web-api-7.0-javadoc.jar
Now go to the folder as said above and keep it open
In my case its
C:\Users\shifny.m2\repository\javax\javaee-web-api\7.0
Now click this website
and search for the jar file
In my case it's:
javaee web api
Now click the link and select the version in next page
In my case it's:
7.0
Now find the "Files" row which will be between "Date" and "Repositories"
In the Files row, click View All
It will open a page like This
In that page download the missing files(classes,source,javadoc)
It will look like this
javaee-web-api-7.0.jar
javaee-web-api-7.0-sources.jar
javaee-web-api-7.0-javadoc.jar
Download all three and put it into the folder which I said you to keep open
Now open your project in inteliJ IDEA and build your project and open the "project structure" as instructed above and check it, the redlined files will have no redlines anymore.
This may seem easy but if there are more files which generates errors then you will have to do this process multiple times and download the missing files.
In that case the above solutions may help...
Check idea.log for errors related to Maven importing, it could be
a network issue with localhost
invalid VM options for Maven VM (too large heap or a typo in VM options)
Maven process failing for some other reason (like the recent Nvidia driver update has caused Java crashes).
I just solved this problem few minutes ago and this is what I figured and my solution:
The reason intellij is popping up with those errors is because the plugin files for those failed plugins in the ".m2" directory are not properly downloaded or they are broken.
This is what I did:
I went to "C:\Users\IYANU.m2\repository\org\apache\maven\plugins" folder. You will see that the name of the plugins matches the ones giving errors in IntelliJ
One after the other, in each plugin folder, I checked for the version giving error in IntelliJ then delete the version folder. Like for "maven-jar-plugin", the version in 2.4, delete the 2.4 folder in the maven-jar-plugin folder.
After deleting, go back to IntelliJ and reload your maven project. Make sure there is an internet connection. This will make IntelliJ properly download the plugin and the error won't pop up for that particular plugin again.
Repeat it for the other plugins giving error
Thank me later
This worked for me:
Download 'maven-jar-plugin:2.4.jar' from maven-repository (https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-jar-plugin/2.4)
Paste the downloaded 'maven-jar-plugin:2.4.jar' in the local PC's mvn-repository ('C:\Users\[user-name].m2\repository\org\apache\maven\plugins\maven-jar-plugin\2.4' folder)
Wait for IntelliJ to pick up the change
All done!

How to publish Scalastyle results in Jenkins Maven job?

We have a Scala project and use Maven and Jenkins for building it. Now we also want to use Scalastyle for static code analysis.
It works fine in the IDE and if I use a Jenkins freestyle job. The output file is created and Jenkins shows a nice graph with the style warnings and errors.
However, if I use a Jenkins Maven job, the "Checkstyle trend" remains empty, although the xml file is there and has the right name (checkstyle-result.xml).
I found this. The discussion there is a bit confusing, but I understood that publishing the Scalastyle results should also work for a Maven job.
Did I get that wrong? Or is there in fact a way to make Jenkins publish the Scalastyle results for my Maven job? Or some kind of workaround? (Apart from using a freestyle job or SBT...)
After trying out some things, I found the solution. All I needed was a Scalastyle entry in the root pom of my multi-module project that looks like this:
<build>
<plugins>
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<version>0.8.0</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/scala</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/scala</testSourceDirectory>
<configLocation>scalastyle_config.xml</configLocation>
<outputFile>${project.basedir}/checkstyle-result.xml</outputFile>
<outputEncoding>UTF-8</outputEncoding>
</configuration>
</plugin>
</plugins>
</build>
The important part here is ${project.basedir}. I tried it before without and it didn't work.
In the project configuration in Jenkins I give the scalastyle:check goal in the section Build -> Goals and options, e.g.
clean install scalastyle:check
Under Build settings I ticked the checkbox Publish Checkstyle analysis results.
Now Jenkins publishes the Scalastyle results. One problem remains, however: Jenkins doesn't seem to pick up my Scalastyle config file (scalastyle_config.xml) but uses the scalastyle-maven-plugin's default rules. At least that's what I suspect, because for the same project I get more Scalastyle warnings in IntelliJ (which uses my custom config file) than in Jenkins...
UPDATE: I was wrong with that. Jenkins does indeed pick up my custom rules. Nevertheless it shows more Scalastyle warnings than IntelliJ does. I'll look into that later.

How to configure OSGI in IntelliJ when it's handled by Maven

I'm an OSGI newb.
I can really use any guidance I can get regarding IntelliJ IDEA / OSGI / Maven / Sling.
So the actual Felix plugin dies when I load it. Apparently it hasn't been maintained and is no longer compatible with the latest release by which I mean IntelliJ IDEA 13.
So I've configured the framework to felix-framework-4.2.1, and that seems to work fine. My greatest concern is that if I apply the OSGI facet to a bundle, the settings seem to indicate that it will change the bundle. Since we have this set up in Maven, I don't think we want this. The source of the facet seems to be the Osmorc plugin. When I used it before, there were complaints about some packages in maven that weren't OSGI enabled and the IDE wanted to point to a special Spring repository for OSGI enabled jar dependencies.
Since we are doing this in Maven, should I even bother with Osmorc? Is there a better way to manage OSGI in IntelliJ IDEA? It is handy knowing which packages are OSGI enabled but an error for that? Really? Specifically I am referring to "The package is not exported by the bundle dependencies" showing up on imports and annotations.
My personal observation with Intellij IDEA 13 is that the OSGI project inspector is slightly more aggressive when it comes to profiling your classes that utilize non-osgi exported classes. That being said, a way around this is by adjusting the inspector severity level. This enables you to use the same OSGI-based approach you were using in Intellij IDEA 12.
To do this, go into your project settings (on Mac: Command+,) and then navigate to the following node:
Inspections --> OSGI --> Package accessibility
Once selected, you'll be able to change the severity level from error to warning.
Performing this change is requisite on a few changes in your pom.xml:
<dependencies>
.
.
<dependency>
<groupId>com.pkg.name</groupId>
<artifactId>some-non-osgi-artifact</artifactId>
<version>0.1-EXAMPLE</version>
</dependency>
</dependencies>
<build>
<plugins>
.
.
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${maven-bundle-plugin.version}</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Export-Package>
you.know.what.goes.here
</Export-Package>
<Private-Package>you.know.what.goes.here</Private-Package>
<Import-Package>
*
</Import-Package>
<Embed-Dependency>some-non-osgi-artifact;scope=compile|runtime;inline=false</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Embed-StripGroup>true</Embed-StripGroup>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
Hope this helps,
Ajay
I think your best bet currently is to use the maven bundle plugin to manage your imports and exports. This means intellij will simply see your bundles as maven projects. Still the correct jars should result. I handle OSGi bundles the same way in eclipse and it works fine.
I also read on the OSGi dev mailing list that there is a bndtools for intellij planned but this will for sure take a while.

How to make M2E eclipse plugin understand Bundle packaging

I'm almost new with Osgi.
I'm using Eclipse 3.6 Helios for building my first Felix Bundle but find out that M2E don't understand bundle packaging...
Project build error: Unknown packaging: bundle
Project build error: Unresolveable build extension:
Plugin org.apache.felix:maven-bundle-plugin:2.0.0 or one of its dependencies could not be resolved:
Failed to collect dependencies for org.apache.felix:maven-bundle-plugin:jar:2.0.0 ()
As I done google searches, it was an error in Maven 2 but fixed in Maven 3 with M2E using.
Also, I'm using Window XP and under a proxy, which I think I sussefully config it, other connections in Eclipse work fine...
So I don't know how to get M2E understand bundle packaging ?
Using these settings, import the maven project. If there are missing connectors (which links maven goals and eclipse plugins), the 'Next' button should be enabled. Do Next and auto-resolve the connectors to install tycho plugins. From now on, your project will have a Plugin nature.
P.S Be sure to at least have one class to compile in the project or maven-bundle-plugin will complain.
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
</plugin>
</plugins>
Justy FYI, ebelanger's answer above led me down the right direction. If you're not seeing the eclipse popup prompting for resolving connections, you need to add the parent pom that declares the plugin to eclipse.
In my case I had a child pom project I was importing into eclipse (but not the parent pom). Note that the actual plugin decleragion for maven-bundle-plugin was in the parent pom, not the child pom eclipse was aware of.
With just the child imported, Eclipse's build problems panel showed the errors about not being able to find the maven-bundle-plugin dependency, but the "quick fix" option after right clicking on the error in the problems panel was greyed out.
Importing the parent project into eclipse caused it to pop up the prompt asking for eclipse plugin connectors to install to support the maven-bundle-plugin.

Resources