RE: Unresolved requirement: Import-Package

Zaberca David, modified 6 Years ago. New Member Post: 1 Join Date: 2/10/20 Recent Posts
Hello guys,
This is my 2th try following the first tutorial from the official documentation. The steps simply talk about creating a service-builder and a mvc portlet. I followed the instructions and all works great, I'm able to insert the portlet into a page and change the view. Then I arrive to this wonderful step https://portal.liferay.dev/docs/7-2/tutorials/-/knowledge_base/t/integrating-the-back-end .

As the tutorial states I insert this in my mvc portlet build.gradle:
compileOnly project(":modules:guestbook:guestbook-api")
compileOnly project(":modules:guestbook:guestbook-service")

... and put this in my portlet class:
@Reference
private GuestbookEntryLocalService _guestbookEntryLocalService;

@Reference
private GuestbookLocalService _guestbookLocalService;

I save the files and gradle does his thing and tries to rebuild something and I get this:Unresolved requirement: Import-Package: com.liferay.docs.guestbook.service

I've tried setting the export packages on the service builder. I've switched version. I've tried refreshing and refreshing gradle for everything. I even did this whole tutorial again. I even deleted all the modules, refreshed project and refreshed gradle. All in hopes of starting the server again but it's dead, the exception above won't let me.Please don't send me to other threads, they are not helpful. 

David
thumbnail
David H Nebinger, modified 6 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
So first, strip out whatever you did in the guestbook-service/bnd.bnd file, you shouldn't be exporting anything there.

You should see, however, in the guestbook-api/bnd.bnd file that there is an "Export-Package:" declaration with one of the lines having the com.liferay.docs.guestbook.service package.

Pay attention to spelling and package here, it should match the actual package where the service interfaces are.

Also, note that two modules cannot export the same package, only one module should export a package. So, for example, if the service module had the same Export-Package declaration, it would conflict with the one from the api module. Your web module, it should not be exporting any packages either.

Additionally, when changing imports and exports, I've sometimes encountered cases where the OSGi meta information gets a little messed up during development, especially when making and deploying changes on bnd.bnd files. If I see weird things like one module saying a package can't be imported when I can see in the code that another module is exporting it, I'll purge the osgi/state directory (while the app server is stopped) and let it rebuild during restart. Doesn't fix everything, but sometimes it does help straighten out the meta conflicts.