Fórum

Grandle dependency problem

Jorge Cardo, modificado 6 Anos atrás.

Grandle dependency problem

New Member Postagens: 5 Data de Entrada: 31/05/17 Postagens Recentes
Hello.

I am using Liferay 7.
I got a Porlet and i need to to use Odata client Library.

I added this to my build.grandle

compileOnly group: "org.apache.olingo", name: "odata-client-core", version: "4.0.0-beta-01"


I added the jar to bnd.bnd:


-includeresource:\
	@odata-client-core-4.0.0-beta-01.jar


Then, i refresh my project and lots of Jars are downloaded. It seems it has lot of dependencies. Its ok.

When i try to deploy my porlet, i get the folowing error in gogo shell:

"Unresolved requeriment: import-package: com.fasterxml.aalto.stax"

Then i include the new jar in the bnd.bnd.

-includeresource:\
	@odata-client-core-4.0.0-beta-01.jar,\
	@aalto-xml-0.9.9.jar

or

-includeresource:\
	@odata-client-core-4.0.0-beta-01.jar,\
	@aalto-xml-0.9.9.jar,\
	@stax2-api-3.1.4.jar


The same error happens.

Then i tried to add all the dependencies of the library (Everything grandle downloaded):

-includeresource:\
	@odata-client-core-4.0.0-beta-01.jar,\
	@odata-client-api-4.0.0-beta-01.jar,\
	@odata-commons-core-4.0.0-beta-01.jar,\
	@odata-commons-api-4.0.0-beta-01.jar,\
	@commons-io-2.4.jar,\
	@httpclient-4.2.6.jar,\
	@commons-codec-1.9.jar,\
	@jackson-dataformat-xml-2.4.2.jar,\
	@aalto-xml-0.9.9.jar,\
	@commons-lang3-3.3.2.jar,\
	@slf4j-api-1.7.7.jar,\
	@httpcore-4.2.5.jar,\
	@commons-logging-1.1.1.jar,\
	@jackson-module-jaxb-annotations-2.4.2.jar,\
	@stax2-api-3.1.4.jar


Same error.

¿Do you know what could i be doing wrong?

Thx you very much.
thumbnail
David H Nebinger, modificado 6 Anos atrás.

RE: Grandle dependency problem

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
Including the resource does not automagically include in the Bundle-ClassPath key. Check out my blog for how to include these into the classpath for the bundle resolution: https://web.liferay.com/web/user.26526/blog/-/blogs/osgi-module-dependencies









Come meet me at the 2017 LSNA!
Jorge Cardo, modificado 6 Anos atrás.

RE: Grandle dependency problem

New Member Postagens: 5 Data de Entrada: 31/05/17 Postagens Recentes
Thx for your response.

I have fixed the problem adding all the dependencies in the build.grandle:

        compile group: "com.fasterxml.jackson.core", name: "jackson-databind", version: "2.8.6"
	compile group: "com.fasterxml.jackson.core", name: "jackson-annotations", version: "2.8.6"
	compile group: "com.fasterxml.jackson.core", name: "jackson-core", version: "2.8.6"
	compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-xml', version: '2.4.2'
	compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-jaxb-annotations', version: '2.4.2'
	compile group: 'com.fasterxml', name: 'aalto-xml', version: '0.9.9'
	compile group: 'commons-codec', name: 'commons-codec', version: '1.9'
	compile group: 'commons-io', name: 'commons-io', version: '2.4'
	compile group: 'commons-logging', name: 'commons-logging', version: '1.1.1'
	compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'
	compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.2.6'
	compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.2.5'
	compile group: "org.apache.olingo", name: "odata-client-core", version: "4.3.0"
	compile group: "org.apache.olingo", name: "odata-client-api", version: "4.3.0"
	compile group: "org.apache.olingo", name: "odata-client-proxy", version: "4.3.0"
	compile group: "org.apache.olingo", name: "odata-commons-core", version: "4.3.0"
	compile group: "org.apache.olingo", name: "odata-commons-api", version: "4.3.0"
	compile group: 'org.codehaus.woodstox', name: 'stax2-api', version: '3.1.4'
	compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.7'



Include-Resource: @jackson-databind-[0-9]*.jar,\
	@jackson-annotations-[0-9]*.jar,\
	@jackson-core-[0-9]*.jar,\
	@odata-client-core-4.3.0.jar,\
	@odata-client-api-4.3.0.jar,\
	@odata-client-proxy-4.3.0.jar,\
	@odata-commons-core-4.3.0.jar,\
	@odata-commons-api-4.3.0.jar,\
	@commons-io-2.4.jar,\
	@httpclient-4.2.6.jar,\
	@commons-codec-1.9.jar,\
	@jackson-dataformat-xml-2.4.2.jar,\
	@aalto-xml-0.9.9.jar,\
	@commons-lang3-3.3.2.jar,\
	@slf4j-api-1.7.7.jar,\
	@httpcore-4.2.5.jar,\
	@commons-logging-1.1.1.jar,\
	@jackson-module-jaxb-annotations-2.4.2.jar,\
	@stax2-api-3.1.4.jar


But now i have the folowing error:
"unresolved dependency: import-package: org.apache.avalon.framework.logger"

I am sure this dependency is not needed. If i create a java aplication with this dependencies, the Odata service works.
Plus this are the dependencies that grandle download automatically, plus this are exact depedencies that are downloaded from Olingo Odata website if you do it manually.

So...
¿Why grandle could be asking for that dependency?

If i add the dependency of "avalon framework", then another one is required, then another, and another.. and after 5 o 6 then i start getting null pointers when trying to add my module to the server.

Thx you very much.
thumbnail
David H Nebinger, modificado 6 Anos atrás.

RE: Grandle dependency problem

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
Jorge Cardo:
But now i have the folowing error:
"unresolved dependency: import-package: org.apache.avalon.framework.logger"

I am sure this dependency is not needed. If i create a java aplication with this dependencies, the Odata service works.
Plus this are the dependencies that grandle download automatically, plus this are exact depedencies that are downloaded from Olingo Odata website if you do it manually.

So...
¿Why grandle could be asking for that dependency?


That's the problem with dependencies, they are cumulative...

Some libraries are just not marked correctly. For example, the lib that uses the avalon framework logger probably should have marked the dependency as optional in the pom file; because it didn't, when the library jar was built the manifest.mf file includes a fixed dependency on the avalon logger.

And so on, it becomes a wicked rabbit hole that you have no idea how deep it goes; each new dependency added brings in it's own dependencies and on and on...

The only way to break the chain is to include all necessary dependencies or, as in this case, you can tell OSGi to ignore the package.

Your bnd.bnd file will have something like:

Import-Package: !org.apache.avalon.framework.logger,\
  *


This tells OSGi not to attempt the import of this package, so you'll deploy this and find some other missing package that you either need to satisfy or exclude.

Note it is not as easy as saying "I'll just exclude everything", cuz some packages actually do have fixed dependencies that they won't work without. But for some fringe stuff or portions of a library you're not going to use, you can exclude those packages so you don't have to include them.

For example, a project I was working on had a real dependency on Jackson. Jackson has a dependency on JodaTime. My project wasn't dealing with dates/times in the imports, so I knew I wouldn't hit the code in Jackson with the dependency so I just excluded Joda from the import packages. If a new file comes in to be processed with dates/times, however, my exclusion of Joda might lead to the CNFE exception later on.

So you really need to make informed decisions about your dependency includes and excludes.







Come meet me at the 2017 LSNA!