Eclipse RCP: Dependency check of Manifest file - osgi

Background
I am developing an Eclipse RCP application with about 100 plug-ins. It's my responsibility to control the dependencies of these plug-ins. If the source code of one plug-in is changing and another plug-in is needed it's easy in Eclipse to add a new dependency by a quick-fix or the Manifest Editor.
My questions
Is there also a way to get informed, that a referenced plug-in is not anymore needed and can be removed from the Manifest file? My goal is to keep dependencies as minimal as possible. So is there a static code analyze tool or an Eclipse plug-in that covers this?

There is an unused dependencies analysis tool in the MANIFEST.MF editor.
Open the MANIFEST.MF editor and switch to the Dependencies tab. At the bottom right there is a 'Dependency Analysis' section which is usually collapsed. Expand this section and choose the 'Find unused dependencies' tool. This will run an analysis and suggest unused dependencies to be removed from from the MANIFEST.MF
This needs to be used with caution because it can be a bit too keen to remove dependencies when there are indirect dependencies.

If its a maven project you could always run mvn 'dependency:analyze' on the project and check for 'used undeclared' and unused declared dependencies

Related

How to use maven artifact in the development of Eclipse plugin via Tycho

Since version 2.2.0 Tycho has introduced a new feature to allow using maven artifacts in PDE target platforms, and here's the how-to. Following its instructions I have included an artifact of Saxon-HE into my target platform. I can see the wrapped OSGi bundle of Saxon after ticking the Show Location Content option in the Target Definition Editor. Also I ran mvn clean verify command to make sure that the artifact is downloaded into my computer. However,
as I began to try to import the package into my Eclipse plugin code, I found no suggestions from this package.
When I tried to include the package as a feature in the Product Editor, I couldn't find any option.
In addition, when attempting to include it as required plugin / imported packages in the Plugin Editor, there was no option, too.
What's more, the product produced by mvn clean verify did not contain such plugin as Saxon-HE after checking my whole RCP project.
All the efforts in vain above made me wonder how I can use a maven artifact in my plugin development. I desperately need the functionalities Saxon-HE provides with to enhance my plugin. Anyone experienced sharing your expertise?
-- 2021.08.13 update --
Manually I included this plugin in the plugin list of my RCP project via source file editing. Its jar file appeared in the plugin folder of the product. But anyway I was not able to validate the availability of the library in the dependency tab of the plugin manifest editor as shown in Vogella's tutorial. Restarting the IDE did not help, either. This might mean that I have to manually code the source code without the content assistance.

How to find a library reference in Intellij Idea

I have a complex project with a lot of Maven libraries. From time to time I am facing the problem of a library version conflict. I can open the class which is conflicting and see all libraries a class is packed in. But unfortunately I don't find an easy way to check where these libraries are referenced in the Maven dependencies. Do you have an idea how to find a library in the Maven tree?
You need Maven Helper plugin
https://plugins.jetbrains.com/plugin/7179-maven-helper
It has a dependencies viewer and lets you resolve conflicts right there. Open your pom file after installing the plugin and you will see another tab at the bottom of the editor window.
Right click on any dependency to bring up the context menu and you will see an option to exclude it. It will add exclude to your pom file. That obviously won't work for uberjars.
Going more low-tech, you can let maven tell you the answer with the command
mvn dependency:tree -Dincludes=groupId:artifactId
You can also invoke this command simply from an Intellij terminal window.
mvn dependency:tree will print the entire tree, the includes addition will let you filter on a specific artifact making it easier to search (although I've been known to just copy the entire tree into a scratch file and just do searches on it there).
If you don't know the groupId or the artifactId is already unique enough, you can filter like this:
mvn dependency:tree -Dincludes=*:artifactId

Simple way to remove unused dependencies from POM in Spring Initializr web project (IntelliJ Idea 2017.2.1)

I created one simple Spring Initializr web project in Intellij Idea. After project creation, I see only two dependencies (spring-boot-starter-web and spring-boot-starter-test) in pom.xml file but the External Libraries in project structure does contain many unused jars (Which obviously degrades the performance). See the below screenshot.
Is there any shortcut or manual way to remove unused dependencies and keep only the required ones?
Edit
Though Remove Unused Resources option is available (right click on External Libraries then Refactor option) but it doesn't seem to work.
you can try dependency:analyze, it will help you. the main goal of dependency:analyze is analyse the dependencies in to the project and determines that which are used and declared and used and undeclared and unused and declared.
you can also refer below link for reference for more study:
http://maven.apache.org/plugins/maven-dependency-plugin/index.html
http://maven.apache.org/plugins/maven-dependency-plugin/usage.html
you can try to run mvn dependency:tree, this won't remove dependencies
but it is allow you to do the analysis yourself

Minor Annoyance: edu.emory.mathcs.backport.java.util

I know this is trivial, but I bet I am not the only developer being annoyed by this issue:
I have a maven project building a Spring Hibernate frameowrk for a webapp.
I am building using Eclipse.
I use Eclipse shortcuts to import dependencies and often do so almost subconsciously.
Somewhere in my project dependencies I have a jar that includes the following package.
edu.emory.mathcs.backport.java.util
I often accidentally import this package instead of java.util and get compile or runtime errors.
QUESTION: How can I find out which dependency includes this package so I can (hopefully) exclude it using the Maven enforcer plugin.
This does not directly answer your question but may help you prevent the accidental import in the first place:
In Eclipse you can add a type filter in Preferences → Java → Appearance → Type Filters.
From the description there:
All types whose fully qualified name matches the selected filter strings will not be shown in the 'Open Type' dialog. They will also be ignored in content assist or quick fix proposals and when organizing imports. For example 'java.awt.*' will hide all types from the awt packages.
You can run mvn dependency:tree from the command line. It will show a tree of your dependencies and their transitive dependencies.
Within Eclipse you can open your pom.xml using the Maven POM Editor (default editor for POM files) and click on Dependency Hierarchy.
Within this view you can use a filter or select the dependency on the right side and the dependency tree for this dependency will be shown on the left side.
I recently encountered this issue with a Maven project in IntelliJ IDEA.
You can view transitive dependencies using the Maven command mvn dependency:tree to figure out where this package is creeping in.
However, it's worthwhile to mention that this problem can occur for Gradle or Maven projects. If you are using IntelliJ, then another workaround that will work for all of your projects - regardless of build tool - is to exclude the package altogether from the IDE's editor settings.
The steps to exclude the edu.emory.mathcs.backport.java.util package when using auto-import for all of your projects opened in IntelliJ are as follows (this is valid for IntelliJ IDEA 2022.2):
Ctrl + Alt + S (or click on File, then Settings)
Editor > General > Auto Import
Under the exclusion section, add the following exclusion with an IDE scope: edu.emory.mathcs.backport.java.util.*
Reference Screenshot

Add a Maven dependency to a Eclipse Plugin project

just a simple question: I need to add a Maven dependency to a Eclipse Plugin project.
The project has not a POM file, so I converted it to a Maven one.
Now I have plugin.xml file and pom.xml file. POM contains the dependency I need to satisfy, but it's ignored; I mean, I can't resolve an import in source code referring to that import.
Can you help me?
ty
I read about Tycho plugin, but online configurations don't work.
If I'm reading this correctly, you've just started by adding a Maven dependency to your project, but don't have the dependency available for Eclipse to validate your code against.
You will need to start a Maven build after you add a brand new dependency so that Maven can add that to your local cached repository. Once the Maven build is done, Eclipse should recognize your imports properly.
You may want to check whether the dependency you are looking for is available in the Eclipse Orbit.
The Orbit project is basically a repository of libraries to make them available for Eclipse Plug-in Development. What is especially nice in the Orbit libraries is that they also provide the sources. Thus, it is possible to view the implementation and get proper JavaDoc and so on.
Example
One can find the com.google.gson library using the update site
https://download.eclipse.org/tools/orbit/downloads/drops/R20190602212107/repository
Thereby, the part R20190602212107 refers to the Orbit build name that you find on the downloads page of the project.

Resources