Forums de discussion

Unresolved requirement: Import-Package: com.liferay.mail.model

thumbnail
Clint Wilde, modifié il y a 7 années.

Unresolved requirement: Import-Package: com.liferay.mail.model

Junior Member Publications: 39 Date d'inscription: 05/03/13 Publications récentes
I am still quite confused by the way OSGi handles dependencies. Here is the issue I am having:

I'm writing a custom portlet for Liferay 7, and I'm getting this error:

org.osgi.framework.BundleException: Could not resolve module: market-photolibrary-portletv2 [570]
Unresolved requirement: Import-Package: com.liferay.mail.model; version="[6.2.0,7.0.0)"
Updated bundle 570

* I am not explicitly using com.liferay.mail.model, anywhere in my code, so I assume this is a dependency of another dependency?

On this page, it explains the old package was renamed: com.liferay.mail.model → com.liferay.mail.kernel.model

This is odd to me because I'm using the new package, com.liferay.mail.kernel.model, not the old one that it's complaining about.

I am *only* using the new Liferay 7 jars(I believe), so what jar would possibly be using use this old dependency?

Here is my bnd.bnd file:
Bundle-SymbolicName: market-photolibrary-portletv2
Bundle-Version: 1.0.0
-sources: true
    
Bundle-ClassPath:\
  .,\
  lib/util-java.jar,\
   
-includeresource:\
  lib/util-java.jar=util-java-7.0.0-nightly.jar,\
  
Import-Package: com.liferay.mail.model;version="[6.2.0,7.0.0)"


My build.gradle file:
buildscript {
	dependencies {
		classpath group: "com.liferay", name: "com.liferay.gradle.plugins", version: "2.0.10"
	}

	repositories {
		mavenLocal()

		maven {
			url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
		}
	}
}

apply plugin: "com.liferay.plugin"

dependencies {
	compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
	compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.0.0"
	
	compile 'com.liferay.portal:com.liferay.portal.kernel:2.0.0'
	compile 'com.liferay:com.liferay.portal.configuration.metatype:2.0.0'
	compile group: 'com.liferay', name: 'com.liferay.portal.settings.web', version: '1.0.3'
	compile group: 'com.liferay', name: 'com.liferay.journal.service', version: '3.4.1'
	compile group: 'com.liferay.portal', name: 'util-bridges', version: '7.0.0-nightly'
	compile group: 'com.liferay', name: 'com.liferay.content.util', version: '1.0.1'
	compile group: 'com.liferay', name: 'com.liferay.journal.api', version: '2.0.1'
	compile group: 'com.liferay.portal', name: 'portal-service', version: '7.0.0-nightly'
	compile group: 'com.liferay.portal', name: 'util-java', version: '7.0.0-nightly'
	
	compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
	compileOnly group: "jstl", name: "jstl", version: "1.2"
	compileOnly group: "org.osgi", name: "org.osgi.compendium", version: "5.0.0"
	
	compile 'biz.aQute.bnd:biz.aQute.bndlib:3.1.0'
	
	compile 'javax.servlet:javax.servlet-api:3.0.1'
	
	compile 'org.osgi:org.osgi.service.component.annotations:1.3.0'
		
	compile group: 'org.apache.velocity', name: 'velocity', version: '1.7'
	compile group: 'org.apache.velocity.tools', name: 'velocity-tools', version: '2.0-alpha1'
	compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
	
	compile group: 'org.jsoup', name: 'jsoup', version: '1.9.2'
	compile group: 'commons-io', name: 'commons-io', version: '2.5'
	
	compile group: 'javax.mail', name: 'mail', version: '1.4.7'
}

repositories {
	mavenLocal()

	maven {
		url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
	}
}


If someone could explain why I am getting this error and a hint as to how to solve it, I would greatly appreciate it.
Thank you!
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Unresolved requirement: Import-Package: com.liferay.mail.model

Liferay Legend Publications: 14915 Date d'inscription: 02/09/06 Publications récentes
Hey, Clint.

Clint Wilde:
Unresolved requirement: Import-Package: com.liferay.mail.model; version="[6.2.0,7.0.0)"


Okay, whenever I see the ranges like this, it looks to me like you're trying to use a pre-release version of the Liferay modules. They all got reset at one point down to 1.0.0, some are even now at 2.0.0+.

The regular util-java.jar file is actually around 2.2.3 for fixpack 4.

For your OSGi modules, though, you don't want to use util-java if you can help it. Instead, you want to try to use the petra bundles, in your case you would want to use "com.liferay:com.liferay.petra.mail:1.0.3".

Util-java is not OSGi friendly, the petra bundles are.

I'm a little confused by your statement:

I am not explicitly using com.liferay.mail.model, anywhere in my code, so I assume this is a dependency of another dependency?


since in your provided bnd.bnd file you have:

Import-Package: com.liferay.mail.model;version="[6.2.0,7.0.0)"


So to me it looks like you actually are using the com.liferay.mail.model and that you're pulling it in directly.

Another thing you have to do is sweep through and get rid of all of this pre-release junk. You shouldn't be using nightly anything.

Also portal-service, that is long gone and does not apply to any release of CE or DXP.
thumbnail
Clint Wilde, modifié il y a 7 années.

RE: Unresolved requirement: Import-Package: com.liferay.mail.model

Junior Member Publications: 39 Date d'inscription: 05/03/13 Publications récentes
Dave,

Thanks for your quick help on that. With your tips and comments, was able to get quite a but further.

Now I'm getting another issue, and I'm not sure why.

When I do blade deploy, I get this error:

org.osgi.framework.BundleException: Could not resolve module: market-photolibrary-portletv2 [570]
Unresolved requirement: Import-Package: antlr
Updated bundle 570

Here is my bnd.bnd:

Bundle-SymbolicName: market-photolibrary-portletv2
Bundle-Version: 1.0.0
-sources: true


#option 3 - uber module (classes are exploded in the module's jar)
Include-Resource: @velocity-1.7.jar,\
  @werken-xpath-0.9.4.jar,\
  @antlr4-4.5.3.jar,\
  


Here's my build.gradle:
buildscript {
	dependencies {
		classpath group: "com.liferay", name: "com.liferay.gradle.plugins", version: "2.0.10"
	}

	repositories {
		mavenLocal()

		maven {
			url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
		}
	}
}

apply plugin: "com.liferay.plugin"

dependencies {
	compileOnly 'com.liferay.portal:com.liferay.util.taglib:2.0.0'
	compile 'com.liferay.portal:com.liferay.portal.kernel:2.0.0'
	compile 'com.liferay:com.liferay.portal.configuration.metatype:2.0.0'
	
	compile 'com.liferay:com.liferay.portal.settings.web:1.0.3'
	compile 'com.liferay:com.liferay.journal.service:3.4.1'
	compile 'com.liferay:com.liferay.content.util:1.0.1'
	
	compile 'com.liferay:com.liferay.journal.api:2.0.1'
	compile 'com.liferay:com.liferay.petra.mail:1.0.3'
	
	compileOnly 'javax.portlet:portlet-api:2.0'
	compileOnly 'jstl:jstl:1.2'
	compileOnly 'org.osgi:org.osgi.compendium:5.0.0'

	compile 'biz.aQute.bnd:biz.aQute.bndlib:3.1.0'
	compile 'javax.servlet:javax.servlet-api:3.0.1'
	compile 'org.osgi:org.osgi.service.component.annotations:1.3.0'
		
	compile 'org.apache.velocity:velocity:1.7'
	compile 'org.apache.velocity.tools:velocity-tools:2.0-alpha1'
	compile 'org.apache.commons:commons-lang3:3.4'
	
	compile 'org.jsoup:jsoup:1.9.2'
	compile 'commons-io:commons-io:2.5'
	
	compile 'javax.mail:mail:1.4.7'
	
	compile 'werken-xpath:werken-xpath:0.9.4'	
	compile 'org.antlr:antlr4:4.5.3'
}

repositories {
	mavenLocal()

	maven {
		url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
	}
}


The odd thing is, I can see the antlr file being downloaded when I do the build, and antlr4-4.5.3.jar is being copied correctly into %USER_HOME%\.gradle\caches\modules-2\files-2.1\org.antlr\antlr4\4.5.3\f35db7e4b2446e4174ba6a73db7bd6b3e6bb5da1

Also, my module's jar file has the exploded classes that I would expect in org\antlr. See below. Any idea how to resolve this? thanks again!

Pièces jointes:

thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Unresolved requirement: Import-Package: com.liferay.mail.model

Liferay Legend Publications: 14915 Date d'inscription: 02/09/06 Publications récentes
Clint Wilde:
Unresolved requirement: Import-Package: antlr


It's complaining about the antlr package, not the org.antlr package. Do you have some sort of transitive dependency on an older version of antlr?
thumbnail
Clint Wilde, modifié il y a 7 années.

RE: Unresolved requirement: Import-Package: com.liferay.mail.model

Junior Member Publications: 39 Date d'inscription: 05/03/13 Publications récentes
Thanks for the hint Dave! That was the issue, I didn't notice that difference. I found an older version of the jar that had the right package and added that and it worked. Thank you emoticon

Now, I am getting a different error:

Unresolved requirement: Import-Package: org.apache.commons.compress.compressors


I found the jar in maven (the latest version is 1.12), and added it to my build.gradle.

dependencies {
	compileOnly 'com.liferay.portal:com.liferay.util.taglib:2.0.0'
	compile 'com.liferay.portal:com.liferay.portal.kernel:2.0.0'
	compile 'com.liferay:com.liferay.portal.configuration.metatype:2.0.0'
	
	compile 'com.liferay:com.liferay.portal.settings.web:1.0.3'
	compile 'com.liferay:com.liferay.journal.service:3.4.1'
	compile 'com.liferay:com.liferay.content.util:1.0.1'
	
	compile 'com.liferay:com.liferay.journal.api:2.0.1'
	compile 'com.liferay:com.liferay.petra.mail:1.0.3'
	
	compileOnly 'javax.portlet:portlet-api:2.0'
	compileOnly 'jstl:jstl:1.2'
	compileOnly 'org.osgi:org.osgi.compendium:5.0.0'

	compile 'biz.aQute.bnd:biz.aQute.bndlib:3.1.0'
	compile 'javax.servlet:javax.servlet-api:3.0.1'
	compile 'org.osgi:org.osgi.service.component.annotations:1.3.0'
		
	compile 'org.apache.velocity:velocity:1.7'
	compile 'org.apache.velocity.tools:velocity-tools:2.0-alpha1'
	compile 'org.apache.commons:commons-lang3:3.4'
	
	compile 'org.jsoup:jsoup:1.9.2'
	compile 'commons-io:commons-io:2.5'
	
	compile 'javax.mail:mail:1.4.7'
	
	compile 'werken-xpath:werken-xpath:0.9.4'	
	compile 'org.antlr:antlr:3.1.1'
	
	compile 'junit:junit:4.12'
	
	compile 'org.apache.logging.log4j:log4j-core:2.6.2'

	compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.3'
	compile 'com.fasterxml.jackson.core:jackson-core:2.8.3'
	compile 'com.fasterxml.jackson.core:jackson-databind:2.8.3'
	compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.8.3'
	compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.8.3'
	compile 'com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.8.3'
	
	compile 'com.lmax:disruptor:3.3.6'

	compile group: 'org.apache.commons', name: 'commons-compress', version: '1.12'	
}


and to my bnd.bnd:

Bundle-SymbolicName: market-photolibrary-portletv2
Bundle-Version: 1.0.0
-sources: true


#option 3 - uber module (classes are exploded in the module's jar)
Include-Resource: @velocity-1.7.jar,\
  @werken-xpath-0.9.4.jar,\
  @antlr-3.1.1.jar,\
  @junit-4.12.jar,\
  @log4j-core-2.6.2.jar,\
  @jackson-annotations-2.8.3.jar,\
  @jackson-core-2.8.3.jar,\
  @jackson-databind-2.8.3.jar,\
  @jackson-dataformat-xml-2.8.3.jar,\
  @jackson-dataformat-yaml-2.8.3.jar,\
  @jackson-module-jaxb-annotations-2.8.3.jar,\
  @disruptor-3.3.6.jar,\  
  @commons-compress-1.12.jar,\


but now I am getting this error:

Unresolved requirement: Import-Package: org.apache.commons.compress.compressors; version="[1.12.0,2.0.0)"


How is it coming up with this range? 1.12.0, and 2.0.0 are not even valid versions listed in maven, here. The latest version is 1.12 (NOT 1.12.0), which is what I'm using.

So why would it be giving me this error message?

Thanks again!
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Unresolved requirement: Import-Package: com.liferay.mail.model

Liferay Legend Publications: 14915 Date d'inscription: 02/09/06 Publications récentes
Yeah, not sure that you can even resolve this. commons-compress is not going to report itself as 1.12.0 but, unless it does, I don't know that the dependency will be satisfied...

For something like this where you have no control over the version reported, it may be easier to make commons-compress global and use the portal-ext.properties override to include commons-compress in the exposed packages...
Matthias Weise, modifié il y a 6 années.

RE: Unresolved requirement: Import-Package: com.liferay.mail.model

New Member Publications: 19 Date d'inscription: 09/07/15 Publications récentes
I just had a similar problem with Apache Commons Lang. For me it helped to use compileInclude instead of compile.

For you it would look like this:
compileInclude group: 'org.apache.commons', name: 'commons-compress', version: '1.12'

Maybe this solves your issue or helps other people with a similar issue.
thumbnail
David H Nebinger, modifié il y a 6 années.

RE: Unresolved requirement: Import-Package: com.liferay.mail.model

Liferay Legend Publications: 14915 Date d'inscription: 02/09/06 Publications récentes
Compile vs compileInclude has absolutely no effect...

They apply when building gradle artifacts when determining whether to include a dependency directly in the artifact or to include it for compiling but exclude from the artifact build.

However, Gradle is not building your OSGi modules, BND is. BND doesn't give a hoot which of these types you use, you are still responsible for satisfying the dependency.






Come meet me at the 2017 LSNA!
Daniele Cascato, modifié il y a 6 années.

RE: Unresolved requirement: Import-Package: com.liferay.mail.model

New Member Publications: 8 Date d'inscription: 17/07/15 Publications récentes
compileInclude solved my problem!
Ashwini Sidhanti, modifié il y a 6 années.

RE: Unresolved requirement: Import-Package: com.liferay.mail.model

New Member Publications: 20 Date d'inscription: 15/12/16 Publications récentes
CompileInclude worked for me too. I find it quite strange that I get errors when I have compileOnly in build.gradle file .
thumbnail
Ney Anderson, modifié il y a 5 années.

RE: Unresolved requirement: Import-Package: com.liferay.mail.model

New Member Publications: 3 Date d'inscription: 25/09/17 Publications récentes
Thanks Matthias Weise! Its solve the problem here, gradle stuffs.