Why does bnd add a usage directive for a package that is used only inside the method body?

I have a project with a single source file, which is listed here in its entirety:

package com.acme.el; public class ExpressionUtils { public static Object evaluate() { new org.apache.commons.el.ExpressionEvaluatorImpl(); return null; } } 

Functionality is not relevant. When I create a project as an OSGi package using Gradle, the manifest contains the following command:

 Export-Package: com.acme.el;uses:="org.apache.commons.el";version="1.0" 

What puzzles me is the uses directive. Since I understood the directive, it is intended to determine dependencies on other packages that need to be distributed in other packages importing this exported package - for example, if my class definitions or method signatures refer to classes in the org.apache.commons.el package, for example . But in this class, the dependency on org.apache.commons.el completely contained within the body of the method. It does not appear in the API, and no other package importing com.acme.el can ever get the ExpressionEvaluatorImpl instance created in the method. So the addiction should not be spread, right?

Did I not understand the meaning of the uses directive, or is it not necessary to use it here?

I made a minimal GitHub repository for playback that can be cloned and imported as a Gradle project in Eclipse.

+6
source share
2 answers

If you set -experiments: true in your bnd file, you should get the correct use: sentence based only on public API links.

The problem is that bnd used all imports from the very beginning to calculate usage restrictions. It was the easiest, and no one has ever complained about it. However, I created code to scan the public API, but I never felt confident enough to remove it from the experimental phase ... The current model creates too many usage restrictions, but this should generally be a safe way.

This code is not sufficiently tested, and I'm not sure that changing this calculation will not create problems in existing assemblies. Therefore, I am a little attached.

+8
source

Gradle 1.7 uses bnd 2.1.0 instead of bnd 1.50.0, which was used by earlier Gradle distributions. This problem does not occur when using Gradle 1.7, as evidenced by this GitHub repository .

+1
source

Source: https://habr.com/ru/post/948527/


All Articles