Message Boards

Liferay DXP 7.3 Using mongo-java-driver gradle dependency in portlet

Moshe Steinvortzel, modified 3 Years ago.

Liferay DXP 7.3 Using mongo-java-driver gradle dependency in portlet

New Member Posts: 3 Join Date: 9/23/19 Recent Posts
When I'm using the mongo-java-driver gradle dependency in portlet, it seems that whenever I try to create a class attribute from that dependency (Such as MongoClient) and try to deploy it, I get:
Could not resolve module: com.qqq [2279]_  Unresolved requirement: Import-Package: com.mongodb; version="[3.12.0,4.0.0)"_ [Sanitized] exception.
But when I create it a function or constructor it seems to work properly.

Not Working:
public class Mongo {
    protected MongoClient mongoClient;
}
Working:
public class Mongo {
    public Mongo() {
        MongoClient mongoClient = null;
    }
}
Any suggestions or ideas why would it happned?

The portlet dependency:
​​​​​​​dependencies {
    compileOnly group: "com.liferay", name: "com.liferay.asset.taglib", version: "5.0.6"
    compileOnly group: "com.liferay", name: "com.liferay.comment.taglib", version: "3.0.2"
    compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib", version: "5.1.1"
    compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib.dynamic.section", version: "3.0.1"
    compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib.form.navigator", version: "4.0.1"
    compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib.util", version: "3.0.1"
    compileOnly group: "com.liferay", name: "com.liferay.journal.taglib", version: "4.0.1"
    compileOnly group: "com.liferay", name: "com.liferay.layout.taglib", version: "5.0.8"
    compileOnly group: "com.liferay", name: "com.liferay.site.taglib", version: "3.0.1"
    compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "5.4.0"
    compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "5.0.3"
    compileOnly group: "javax.portlet", name: "portlet-api", version: "3.0.0"
    compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
    compileOnly group: "jstl", name: "jstl", version: "1.2"
    compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations", version: "1.3.0"        
    compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.12.4'
    cssBuilder group: "com.liferay", name: "com.liferay.css.builder", version: "3.0.2"
    
}
thumbnail
David H Nebinger, modified 3 Years ago.

RE: Liferay DXP 7.3 Using mongo-java-driver gradle dependency in portlet

Liferay Legend Posts: 14916 Join Date: 9/2/06 Recent Posts
You absolutely should be using compileInclude, not compile, to include the transient dependencies into the module.
Moshe Steinvortzel, modified 3 Years ago.

RE: Liferay DXP 7.3 Using mongo-java-driver gradle dependency in portlet

New Member Posts: 3 Join Date: 9/23/19 Recent Posts
I tried that. I get:Unresolved requirement: Import-Package: com.github.luben.zstd_ [Sanitized]
thumbnail
David H Nebinger, modified 3 Years ago.

RE: Liferay DXP 7.3 Using mongo-java-driver gradle dependency in portlet

Liferay Legend Posts: 14916 Join Date: 9/2/06 Recent Posts
So you either need to include this dependency too, or specifically exclude it.