I made a Liferay 7.4 Service-Builder module, in which I needed to import okhttp3. First, I wrote in build.gradle:
compileInclude 'com.squareup.okhttp3:okhttp:4.10.0'
Then the Gradle build process produced an error:
error : Classes found in the wrong directory: {META-INF/versions/9/module-info.class=module-info}
After that I changed the build.gradle line to:
compile 'com.squareup.okhttp3:okhttp:4.10.0'
The build process passed, but in deployment there was an exception:
com.liferay.portal.kernel.log.LogSanitizerException: org.osgi.framework.BundleException: Could not resolve module: com.toptoken.core.service [1610]_ Unresolved requirement: Import-Package: okhttp3_ [Sanitized]
at org.eclipse.osgi.container.Module.start(Module.java:444) ~[org.eclipse.osgi.jar:?]
at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:428) ~[org.eclipse.osgi.jar:?]
at com.liferay.portal.file.install.internal.DirectoryWatcher._startBundle(DirectoryWatcher.java:1156) [bundleFile:?]
at com.liferay.portal.file.install.internal.DirectoryWatcher._startBundles(DirectoryWatcher.java:1189) [bundleFile:?]
at com.liferay.portal.file.install.internal.DirectoryWatcher._startAllBundles(DirectoryWatcher.java:1130) [bundleFile:?]
at com.liferay.portal.file.install.internal.DirectoryWatcher._process(DirectoryWatcher.java:1041) [bundleFile:?]
at com.liferay.portal.file.install.internal.DirectoryWatcher.run(DirectoryWatcher.java:247) [bundleFile:?]
How can I import the okhttp3 library without errors?
My Java version is 11.
Adding Import-Package: okhttp3;version="[4.10,5)" or Require-Bundle: okhttp3;version="[4.10,5)" to bnd.bnd didn't work.
I had the same problem with a poi library, it worked for me by adding the line
-fixupmessages: Classes found in the wrong directory: ...;is:=ignorein thebnd.bndfile, leave the compileInclude so the resources are part of your jar file.