Finding unused dependency in repository

I was wondering: Is there a way to identify dependency entries in my central.maven MavenBndRepository which are not needed (not referenced from any bundle)?

Is this theoretically possible? Isn’t the resolver the one who knows this dependency-universe?

Our use case is just cleanup of historical garbage. We have some historical entries in our repository file and I am sure there are some we have forgotten to remove.

Anything in the tool (bnd or bndtools) which would help me with this?

There are a number of very useful functions in the bnd command line. If the current directory is in the workspace, it will check for versions, duplicates, etc. Unfortunately, it does not look at all the used dependencies since this is tricky but if more people want this then I can add it.

This only works for the MavenBndRepository since it directly manipulates the GAV files.

Maintain Maven Bnd Repository GAV files

Available sub-commands: 

  check                       -         For each archive in the index,
                                        show the available higher
  repos                       -         List the repositories in this
  update                      -         For each archive in the index,
                                        update to a higher version if
                                        available in the repository 
  verify                      -         Verify the repositories, this
                                        checks if a GAV is defined in
                                        multiple repositories or if there
                                        are multiple revisions for the
                                        same program 
1 Like

There is no function like that to my knowledge. I might have a suggestion for a workaround though. After you resolve your application, you end up with most of the actually necessary bundles as -runbundles, minus some development time Bundles like osgi.core.

First you need a litte helper project, that can be deleted afterwards. In that you need to place a file e.g. runtime.maven with the following content:


Then you need the following bnd.bnd file:

# point to your bndrun, that contains all the resolved bundles. 
-include: ${.}/required.bndrun
# putt all the runbundles on the buildpath
-buildpath: ${-runbundles}

# all bundles on the buildpath will usually be available as GAV coordinates with this -maven-dependencies instruction
# The makro just creates a list similar to the usual content of the maven index file
mavendeps: ${sjoin;\n; ${template;-maven-dependencies;${@}}}

# copy the runtime file to the jar and resolve any macros in that file
-includeresource: \

The resulting jar will now contain the runtime.maven with a list of all used bundles that have a known GAV. You can now use this instead of your original file and add the few missing bundles.

I hope this helps.

1 Like

Thanks for the suggestions. I will try them out.

Works great. Now I will apply some texteditor magic:

  • create 2 files
  • sort each alphabetically
  • use a diff tool to check which exists in old but not in runtime.maven anymore.

Thanks for the tip.

Really? The {} around the ´-includeresource` tells it to do its macro processing on the file and not only copy it. See -includeresource iclause | bnd under preprocessing.

If you put a $ before that, you should receive a warning that the macro can’t be expanded.

I think you are right. Maybe I looked at the wrong time… misunderstanding. Anyway your initial script is correct. I will adjust my comment.