Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: RE: Exporting and Importing packages with bnd.bnd
Im trying to make an utility class with some methods and constants for usage in other modules. I use "Export-Package:" in the module where i want to export the package, and Import-Package in the module where i want to import it. According to the tutorials this should work automatically.
It does not. As there are no more detailed information, I try to refresh the gradle project, still the package is not available to use.
I would appreciate it if anyone could help
The Export-Package you do need to do, but you don't have to worry about the Import-Package directive. That will be handled during the build simply by declaring the dependency on the other module.
If all you are doing is modifying the bnd.bnd's Import-Package directive but not using the build.gradle to declare the dependency, then you're not understanding how the Import-Package directive is being used. It will not affect gradle, it will not afffect the build, it will only apply when the OSGi container is trying to process your module and will fail with an Unresolved Requirement exception if the module exporting the package is not available.
This would of course be fine and dany if it did work. I´ve tried to declare a dependency in the build.gradle and a bunch of stuff, as i always do before i ask questions here.
According to the official guides the package should be available to declare a dependency like
compileOnly group: "com.liferay", name: "com.liferay.item.selector.criteria.api"
Allthough i do use export-package: i get
Could not resolve all files for configuration
compileOnly only declares the dependency on a package, it will not include it nor guarantee it's availability at deployment time.
https://liferay.dev/blogs/-/blogs/gradle-compile-vs-compileonly-vs-compileinclude
Also, compileOnly does not include the package in the Import-Package directive in METAINF.inf, that's why you are forced to put it into the bnd.bnd file.
I think it is just the case that you're using the wrong directive in your build.gradle file.
Powered by Liferay™