-
-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bnd-maven-plugin] Generated substitution import does not define version range #6220
Comments
I expect that there is no version available for com.google.gson.annotations when gson is processed? I.e. its JAR contains no version information. It must then explicitly set in the Import-Package, i.e. don't use a ${range}, just give the version. Best is of course to provide a version for com.google.gson.annotations package in its JAR.. |
There might be a misunderstanding here, Therefore I think the version information should be present to bnd, at least in theory. But maybe it is not accessible to that part of bnd for whatever reason? It seems there is some analysis on this in #6221 (comment). Footnotes
|
I checked the MANIFEST.MF of gson 2.10.1 as an example: I guess the version behind the My observation is:
results in MANIFEST.MF:
results in Manifest.mf
I guess my questions are (@pkriens , @bjhargrave ):
In the code it looks like for Import-Package this defaultVersion is explicitly set to null while Export-Package get the defaultVersion. Looks like this was added a long long time ago. If the behavior stays unchanged as it is, it would be good to document it e.g. in the FAQ |
It would certainly be great if there was a way to enable this behavior. But based on what I read here and in the Gson issue it feels to me (as someone external) that case 2 should be the default and it is a bug that the version is not propagated by bnd internally, despite being present.
Not sure if passing a (But I am not very familiar with the code.) |
Yes you are right, it is likely not the correct place in the code. I was just pointing to this specific place, because it is at least somehow related. My impression is, the challange is to find the place where self-imports are identified. Not familiar with the code either. |
@Marcono1234 I added draft PR #6238 as a base for discussion. |
@Marcono1234 Have a look at comment by @bjhargrave about the
I didn't know about
Question to @bjhargrave Basically like saying: "All packages which I export and re-import I want them to never be imported from any other bundle". |
If you never intend to import an exported package, then A bundle cannot import from its own export. When a bundle declares it both exports and imports a package, only one of those is chosen by the framework during bundle resolution. So the bundle either exports without import or imports without export. So importing from one's self does not exist. If a bundle is exporting a package, any internal references to the package will be to the bundle's copy of the package. |
Thanks @bjhargrave I was just playing around with @Marcono1234 so I guess it comes down to this: GSON needs to append
This will cause that alternatively they could use the shortcut I just tested this with your bnd-test.zip of your other issue.
will result in the MANIFEST.MF
Update: adding link to documentation: https://bnd.bndtools.org/heads/export_package.html and a related discussion |
append |
Thanks @bjhargrave , I updated my answer above. On that note: I added a link to this discussion which I think is related. |
Thanks a lot for all your research, work and support on this!
That is the question, what Gson wants. Personally (not being a direct member of Gson) I think it wants to produce an OSGi manifest which is usable by users, and does not cause any issues for them. Unfortunately, I don't know how to achieve that, and I don't know either if your suggestion to remove the "self-import" with I am wondering though if other projects are affected by this default bnd behavior as well, and if in that case this "self-import (without version range?)" should be enabled by default. |
Thanks for getting back @Marcono1234
My impression is, that changing default behavior won't happen, since it is usually dangerous for everybody out there relying on the current behavior. BUT: I think that instead of changing default behavior we should make this a prominent documentation change and change the "default recommentation" we give to library authors. The OSGi spec already defines strict boundaries when package substition (the current default) should be done, and I assume this is something a lot of non-OSGi library authors are not aware of - nor do a lot of them know what that means. I think changing the default-recommendation to something like "you should use Since I don't feel qualified enough to make this decision alone it would be great to get more opinion for the OSGi veterans around here. I have written something in a related discussion in https://bnd.discourse.group/t/using-noimport-with-export-annotation/253/7 and maybe you could add your thoughts there too. I think the result of the the discussion could be something like a new "How-to OSGi-fy article for library authors" which is linked in various places in the current manual. |
Yes that would definitely be useful. The current situation is rather confusing, where there are three different views on what is correct:
I share the sentiment of that Discourse discussion, that for someone with little / no OSGi knowledge who wants to provide an OSGi manifest for their library for convenience, it is difficult to understand what the 'correct' way of doing this is. Note: Maybe another possibility is also that the analysis in google/gson#2725 is incorrect and the self-import is not actually the cause? |
based on google#2725 and bndtools/bnd#6220 (comment) append -noimport:=true to all exports which we do not want to re-import This avoids issues in OSGi environments where multiple versions of gson are deployed and com.google.gson.annotations causes wiring conflicts between these different versions
@Marcono1234 I have created PR google/gson#2735 to remove the self-import of gson.annotations via Meanwhile I have discovered a statement which makes me think -noimport is the right thing to do here. Source: https://bugs.eclipse.org/bugs/show_bug.cgi?id=183595#c7
I suggest closing this issue here if you agree. |
based on #2725 and bndtools/bnd#6220 (comment) append -noimport:=true to all exports which we do not want to re-import This avoids issues in OSGi environments where multiple versions of gson are deployed and com.google.gson.annotations causes wiring conflicts between these different versions
Can we close this? |
Version: Maven plugin
biz.aQute.bnd:bnd-maven-plugin
6.4.0Hello,
https://github.com/google/gson uses the bnd-maven-plugin to generate the OSGi manifest attributes1. Recently in google/gson#2725 it was reported that the "substitution"
Import-Package
forcom.google.gson.annotations
causes issues when multiple third-party bundles import Gson packages.In that Gson issue and the linked discussions it was mentioned that the problem might be that Gson's own
Import-Package
(generated by bnd) does not define a version range forcom.google.gson.annotations
2:Do you think as well that this is the cause here, and that the solution is to use
...;version="${range;[==,=+)}"
or similar? But in that case is that something bnd can / should generate on its own?Disclaimer: I am not very familiar with OSGi, so please let me know if there is any misunderstanding.
Footnotes
Maven plugin configuration: https://github.com/google/gson/blob/9615c8d7c895797872d7e601702e690e5ed7a2e8/gson/pom.xml#L125-L157 ↩
Can for example be seen in the Gson 2.11.0 JAR, or if you build Gson manually with
mvn package
; the JAR is then under/gson/target/gson-2.11.1-SNAPSHOT.jar
. ↩The text was updated successfully, but these errors were encountered: