Unresolved requirements using a class from util-java in custom development
How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!
While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.
Legacy Article
You are viewing an article from our legacy "FastTrack"
publication program, made available for informational purposes. Articles
in this program were published without a requirement for independent
editing or verification and are provided"as is" without
guarantee.
Before using any information from this article, independently verify its
suitability for your situation and project.
Issue
- Trying to use a class from
/util-java, such as com.liferay.util.Normalizer, in a custom development by adding to build.gradle the dependency
compileOnly group: "com.liferay.portal", name: "com.liferay.util.java"
will lead to unresolved requirements such as:
2021-08-19 09:56:31.228 ERROR [fileinstall-directory-watcher][DirectoryWatcher:1139] Unable to start bundle: file:[...]/testportlet-1.0.0.jar
org.osgi.framework.BundleException: Could not resolve module: test.sample.versions [1591]_ Unresolved requirement: Import-Package: com.liferay.util; version="[10.0.0,11.0.0)"_ [Sanitized]
at org.eclipse.osgi.container.Module.start(Module.java:444)
at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:428)
at com.liferay.portal.file.install.internal.DirectoryWatcher._startBundle(DirectoryWatcher.java:1122)
at com.liferay.portal.file.install.internal.DirectoryWatcher._startBundles(DirectoryWatcher.java:1155)
at com.liferay.portal.file.install.internal.DirectoryWatcher._startAllBundles(DirectoryWatcher.java:1100)
at com.liferay.portal.file.install.internal.DirectoryWatcher._process(DirectoryWatcher.java:1012)
at com.liferay.portal.file.install.internal.DirectoryWatcher.run(DirectoryWatcher.java:265)
Resolution
- To fix this unresolved requirements it's necessary to explicitly include the requirements in the file bnd.bnd, as well as the related dependencies.
- For the example above the additional lines to include in bnd.bnd would be
Include-Resource: @com.liferay.util.java-[0-9.]*.jar
Import-Package: \
!net.fortuna.ical4j.model,\
!net.fortuna.ical4j.model.property,\
!org.apache.axis.tools.ant.wsdl,\
!org.apache.poi.hssf.usermodel,\
!org.apache.poi.ss.usermodel,\
*
- There is a feature request to simplify this: LPS-137726 As a developer I would like to use classes in util-java more easily.
Did this article resolve your issue ?