RE: import gson issue

Scarletake Bwi, modified 3 Years ago. Expert Posts: 327 Join Date: 12/20/10 Recent Posts

hi 

i try import gson, like how-import-gson-library-corfrectly

i modify build.gradle

compileInclude group: "com.google.code.gson", name: "gson", version: "2.9.0"

bnd.bnd

Bundle-Name: DEM
Bundle-SymbolicName: demo.srg
Bundle-Version: 1.0.0
Export-Package:\
	demo.srg.constants,\
	com.google.gson.*

Import-Package:\
	com.google.gson.*; version='2.9.0',\
    *

but doesn't work

error message from gradle build

error  : Classes found in the wrong directory: {META-INF/versions/9/module-info.class=module-info}

 

error when server run up

2022-07-15 04:44:34.233 ERROR [Framework Event Dispatcher: Equinox Container: 6ea82b61-4cc8-443a-8df4-c91c4c11d9da][Framework:47] FrameworkEvent ERROR
com.liferay.portal.kernel.log.LogSanitizerException: org.osgi.framework.BundleException: Could not resolve module: com.pac.ci.srg [1597]_  Unresolved requirement: Import-Package: com.google.gson; version="[2.9.0,3.0.0)"_ [Sanitized]

is there anything i missed? 

thanks in advance 

Scarletake Bwi, modified 3 Years ago. New Member Posts: 2 Join Date: 4/25/22 Recent Posts
You need to exclude the packages like this with exclamation sign "!" and read this article

https://liferay.dev/blogs/-/blogs/gradle-compile-vs-compileonly-vs-compileinclude

Import-Package: \    
!com.google.gson,\

*

and don't forgot to put * in the last line.