# Using -noimport with @Export annotation

**URL:** <https://bnd.discourse.group/t/using-noimport-with-export-annotation/253>\
**Category:** GENERAL\
**Created:** [August 9, 2022, 9:15am UTC](https://bnd.discourse.group/t/using-noimport-with-export-annotation/253 "2022-08-09T09:15:18Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![chrisrueger](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/chrisrueger/32/18_2.png) [@chrisrueger](https://bnd.discourse.group/u/chrisrueger)\
**Post date:** [August 27, 2024, 5:46pm UTC](https://bnd.discourse.group/t/using-noimport-with-export-annotation/253/7 "2024-08-27T17:46:32Z")

</div>

Just found this discussion here after hanging around [here](https://github.com/bndtools/bnd/issues/6220#issuecomment-2312660794) and learning how stuff actually works.

And I discovered the prescious `-noimport:=true`

> [@pkriens](#):
>
> not using the defaults will cause more pain in the long run than you trying to be cleverer than bnd and its 23 year history in these matters. But you won’t be the first one if that comforts you

My initial reaction was like "Why is `-noimport:=true` not the default? Like perspective of @laeubi in [Using -noimport with @Export annotation - #5 by laeubi](https://bnd.discourse.group/t/using-noimport-with-export-annotation/253/5)

What about we promote the more prominently to use something like `-noimport:=true` on the Exports when “just” adding OSGi meta data?

`-exportcontents: *;-noimport:=true`

This would reflect the default-behavior which is expected by @laeubi , [the github issue](https://github.com/bndtools/bnd/issues/6220) and myself somehow (throwing in a buzzword\*: principle of least surprise\*). Then the substitution use-case could be documented as an alternative.

Given that the default behavior won’t change (that is what I took from discussion and [github](https://github.com/bndtools/bnd/issues/6220#issuecomment-2312660794)) I would like to ask

1. how we could do a better job of documenting it?
2. and maybe give better advice to library authors who just want to add OSGi metadata, but do not have OSGi knowledge?

A real life example of the pain it causes is the origin github [Issues with 2024-06 and gson library used by lsp4j v0.22 · Issue #3236 · eclipse-jdtls/eclipse.jdt.ls · GitHub](https://github.com/eclipse-jdtls/eclipse.jdt.ls/issues/3236#issuecomment-2276399714)

> The problem, as you’ve noted, is that both gson bundles import just “com.google.gson.annotations” (implied \>= 0.0.0) leaving the door open for resolution between different versions of the same library 😐 gson 2.10.1 should import with a range of `[2.10.1,2.11.0)` and gson 2.11.0 should import with a range of `[2.11.0,2.12.0)` to be safe.
> 
> com.google.gson\_2.10.1.jar  
> `Import-Package = sun.misc;resolution:=optional,com.google.gson.annotations;version="[2.10.1,2.11.0)"`
> 
> com.google.gson\_2.11.0.jar  
> `Import-Package = sun.misc;resolution:=optional,com.google.gson.annotations;version="[2.11.0,2.12.0)"`

This problem resulted in multiple other github issues in different projects (gson, bnd, eclipse..) and seems to be a real-world issue only a few people are able to debug.  
This makes me think “What could we do about it?”

I am willing to contribute documentation but not sure if and where to start. So feedback is welcome.

## As a starting point

I see the following docs pages:

- [FAQ - Frequently Asked Questions | bnd](https://bnd.bndtools.org/chapters/920-faq.html)
- [Export-Package ::= export ( ‘,’ export)\* | bnd](https://bnd.bndtools.org/heads/export_package.html)
- [-exportcontents PACKAGE-SPEC, ( ‘,’ PACKAGE-SPEC )\* | bnd](https://bnd.bndtools.org/instructions/exportcontents.html)
- [Wrapping Libraries to OSGi Bundles | bnd](https://bnd.bndtools.org/chapters/390-wrapping.html)
- [Generating JARs | bnd](https://bnd.bndtools.org/chapters/160-jars.html)
- [bnd/maven-plugins/bnd-maven-plugin/README.md at master · bndtools/bnd · GitHub](https://github.com/bndtools/bnd/blob/master/maven-plugins/bnd-maven-plugin/README.md)
- [wrap | bnd](https://bnd.bndtools.org/commands/wrap.html)

---

_[View the full topic](https://bnd.discourse.group/t/using-noimport-with-export-annotation/253)._
