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: Liferay Resolving third party Dependencies
Hi guys,
I am working on the Liferay 7.1.2.ga3 CE and I am strugguling with the third party libraries resolution.
I have a module that needs to use com.google.code.gson and the apache's commons-io.
I followed this tutorial: https://portal.liferay.dev/docs/7-1/tutorials/-/knowledge_base/t/adding-third-party-libraries-to-a-moduleand came up with the following build.gradle
and bnd.bnd
I have found a workaround for that which is to specify the version for the lib instead of giving a range with RegEx.
Why is this not working for me ?
P.S. I also tried the compileOnly for the two libraries in the gradle.build file.
I am working on the Liferay 7.1.2.ga3 CE and I am strugguling with the third party libraries resolution.
I have a module that needs to use com.google.code.gson and the apache's commons-io.
I followed this tutorial: https://portal.liferay.dev/docs/7-1/tutorials/-/knowledge_base/t/adding-third-party-libraries-to-a-moduleand came up with the following build.gradle
dependencies {
compileOnly group: "org.osgi", name: "org.osgi.core"
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel"
compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations"
compileInclude group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
compileInclude group: 'commons-io', name: 'commons-io', version: '2.6'
compileOnly project(":modules:ApplicationServices")
}
and bnd.bnd
-includeresource: META-INF/lib/gson.jar=gson-[0-9]*.jar;lib:=true
-includeresource: META-INF/lib/commons-io.jar=commons-io-[0-9]*.jar;lib:=true
First of all I was getting the following error on build error : Input file does not exist: commons-io-[0-9]*.jar
I have found a workaround for that which is to specify the version for the lib instead of giving a range with RegEx.
[code]-includeresource: lib/gson.jar=gson-2.8.6.jar,
lib/commons-io.jar=commons-io-2.6.jar
This way it build correctly but then I get an error on deploy.Unresolved requirement: Import-Package: com.google.gson; version="[2.8.0,3.0.0)"_ [Sanitized]
Why is this not working for me ?
P.S. I also tried the compileOnly for the two libraries in the gradle.build file.
gson latest jars already OSGi compliance so you don't need to add as include resources.
download latest gson jar and deploy it your osgi/module directory. add dependency in build.gradle file with compileOnly scope.
error : Input file does not exist: commons-io-[0-9]*.jar : dependency information not available in build.gradel file. add commons-io dependency.
remove includeresource directive from bnd.bnd file if you already deployed gson-2..8.5.jar in OSGi module directory.
http://www.liferaysavvy.com/2020/03/unrelated-packages-unresolved.html
http://www.liferaysavvy.com/2020/03/unresolved-requirement-import-package.html
https://github.com/LiferaySavvy/employee-web/blob/master/build.gradle
download latest gson jar and deploy it your osgi/module directory. add dependency in build.gradle file with compileOnly scope.
error : Input file does not exist: commons-io-[0-9]*.jar : dependency information not available in build.gradel file. add commons-io dependency.
remove includeresource directive from bnd.bnd file if you already deployed gson-2..8.5.jar in OSGi module directory.
http://www.liferaysavvy.com/2020/03/unrelated-packages-unresolved.html
http://www.liferaysavvy.com/2020/03/unresolved-requirement-import-package.html
https://github.com/LiferaySavvy/employee-web/blob/master/build.gradle
compileInclude already packages the jar files (in your case commons-io and gson) inside of your module. Using includeresource isn't necessary in that case. So, either use compileInclude or use includeresource, but not both. Personally, I prefer compileInclude because it is simpler and I don't need to add any jar files manually.
The following blog is quite helpful (note: compileInclude is a newer feature, it isn't covered in that blog). It shows how to use includeresource correctly:
https://liferay.dev/blogs/-/blogs/osgi-module-dependencies
Of course, using an OSGI package of a library is the best solution, as Meera Prince pointed out. But since they are not always available, compileInclude can be quite handy.
The following blog is quite helpful (note: compileInclude is a newer feature, it isn't covered in that blog). It shows how to use includeresource correctly:
https://liferay.dev/blogs/-/blogs/osgi-module-dependencies
Of course, using an OSGI package of a library is the best solution, as Meera Prince pointed out. But since they are not always available, compileInclude can be quite handy.
Thanks for the answers guys ! Realy helpful links too.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™