Maven dependency when using opencsv in AEM Bundle [duplicate] - maven

I am trying to import
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.apache.directory.ldap.client.api.DefaultLdapConnectionFactory;
import org.apache.directory.ldap.client.api.LdapConnection;
import org.apache.directory.ldap.client.api.LdapConnectionConfig;
import org.apache.directory.ldap.client.api.LdapConnectionPool;
import org.apache.directory.ldap.client.api.ValidatingPoolableLdapConnectionFactory;
import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
and using
<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-ldap-client-api</artifactId>
<version>2.0.0.AM4</version>
</dependency>
in the parent pom and
<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-ldap-client-api</artifactId>
</dependency>
in the bundle pom.
The issue is
- The artifact is not present in osgi after build and
- Project bundle is in resoved state due to error
org.apache.commons.pool2,version=[2.6,3) -- Cannot be resolved
org.apache.commons.pool2.impl,version=[2.6,3) -- Cannot be resolved
org.apache.directory.ldap.client.api,version=[2.0,3) -- Cannot be resolved
org.apache.directory.ldap.client.template,version=[2.0,3) -- Cannot be resolved
UPDATED QUESTION -
"How to resolve these dependencies? Which ldap dependency/library
could be used in OSGi?"
Objective - I'm trying to connect LDAP
LdapConnection connection = new LdapNetworkConnection( "localhost", 10389 );
Reference - LDAP Connection documentation

You have to distinguish between build time and runtime dependencies. In Maven you define your build time dependencies. Per default they have nothing to do with the bundles installed in AEM (runtime dependencies).
To make it clear:
Dependencies defined in Maven are not automatically installed into AEM.
There are a few options how you can deploy the required runtime dependencies to AEM:
Install them by hand (/system/console/bundles)
Put them in a content package and deploy that content package by hand.
Extend your Maven build to create a content-package which includes the bundles you need at runtime (e.g. org.apache.directory.api:api-ldap-client-api:2.0.0.AM4)
Install the bundles using the install directory of AEM on the hard disk: crx-quickstart/install.
All of them have advantages and disadvantages. I usually opt for option #3. I have written a lengthy answer that explains this here: https://stackoverflow.com/a/56698917/190823

If you do not require them, you can exclude them in the section, by doing something like this:
<configuration>
<instructions>
<Import-Package>
!org.apache.commons.pool2,
And so on.

Related

Maven dependency for LDAP library could not be resolved in OSGi

I am trying to import
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.apache.directory.ldap.client.api.DefaultLdapConnectionFactory;
import org.apache.directory.ldap.client.api.LdapConnection;
import org.apache.directory.ldap.client.api.LdapConnectionConfig;
import org.apache.directory.ldap.client.api.LdapConnectionPool;
import org.apache.directory.ldap.client.api.ValidatingPoolableLdapConnectionFactory;
import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
and using
<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-ldap-client-api</artifactId>
<version>2.0.0.AM4</version>
</dependency>
in the parent pom and
<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-ldap-client-api</artifactId>
</dependency>
in the bundle pom.
The issue is
- The artifact is not present in osgi after build and
- Project bundle is in resoved state due to error
org.apache.commons.pool2,version=[2.6,3) -- Cannot be resolved
org.apache.commons.pool2.impl,version=[2.6,3) -- Cannot be resolved
org.apache.directory.ldap.client.api,version=[2.0,3) -- Cannot be resolved
org.apache.directory.ldap.client.template,version=[2.0,3) -- Cannot be resolved
UPDATED QUESTION -
"How to resolve these dependencies? Which ldap dependency/library
could be used in OSGi?"
Objective - I'm trying to connect LDAP
LdapConnection connection = new LdapNetworkConnection( "localhost", 10389 );
Reference - LDAP Connection documentation
You have to distinguish between build time and runtime dependencies. In Maven you define your build time dependencies. Per default they have nothing to do with the bundles installed in AEM (runtime dependencies).
To make it clear:
Dependencies defined in Maven are not automatically installed into AEM.
There are a few options how you can deploy the required runtime dependencies to AEM:
Install them by hand (/system/console/bundles)
Put them in a content package and deploy that content package by hand.
Extend your Maven build to create a content-package which includes the bundles you need at runtime (e.g. org.apache.directory.api:api-ldap-client-api:2.0.0.AM4)
Install the bundles using the install directory of AEM on the hard disk: crx-quickstart/install.
All of them have advantages and disadvantages. I usually opt for option #3. I have written a lengthy answer that explains this here: https://stackoverflow.com/a/56698917/190823
If you do not require them, you can exclude them in the section, by doing something like this:
<configuration>
<instructions>
<Import-Package>
!org.apache.commons.pool2,
And so on.

How to import classes from `com.android.build.api.transform` package in Maven

I am trying to transfer a gradle-based build plugin for android to a maven build system.
Up to now I was successful except with the android part.
It seems that I am missing classes from the package com.android.build.api.transform. Although I used this code
<dependency>
<groupId>com.android.tools.build</groupId>
<artifactId>gradle</artifactId>
<version>2.2.0</version>
<type>jar</type>
</dependency>
which is supposed to provide (rather indirectly) the required classes/packages, it seems that this is not working.
I also added
<repositories>
<repository>
<id>android</id>
<name>android</name>
<url>https://plugins.gradle.org/m2/</url>
</repository>
</repositories>
just in case, with no luck. Still the project is not able to compile due to missing classes.
Any idea what I am missing? I am very new to the gradle/maven scene, and I still feel out of my waters with these tools.
For reference here is a link to the javadoc of this artifact.
Thanks for your help
The 'gradle' artifact does not contain the missing package. As you mention, it depends transitively on at least one artifact that contains that package, but only in scope 'runtime'. Hence, it will not be available to your project on the compile classpath.
Anyway, adding the dependency explicitly in your pom.xml is the right thing to do. A search for the missing package on search.maven.org shows that you have the choice between com.android.tools.build:transform-api and com.android.tools.build:gradle-api. Locking at the transform-api artifact reveals that it's deprecated and encourages to use gradle-api instead. (The latest version is '2.0.0-deprecated-use-gradle-api'). I downloaded the gradle-api jar file, which indeed has the missing package. So please try adding that artifact to your pom.xml instead:
<dependency>
<groupId>com.android.tools.build</groupId>
<artifactId>gradle-api</artifactId>
<version>2.3.0</version>
</dependency>
I didn't check version 2.2.0, but if you for some reason want to use the older version, it will probably work too.
the transform API was a Google's Android Gradle plugin technology. but it was absorbed into and expanded by Gradle. so newer Android plugins migrated to the Gradle API and they no longer include the transform engine, which now is part of Gradle. if you use the deprecated transform API from Google that was bundled with older plugins, you will get the engine. but what you plan to do about all the other dependencies on Gradle, i have no idea.

POM dependency for AEM 6.2 implementation of Amazon S3 Bucket

I am trying to implement Amazon S3 in Adobe Experience Manager 6.2 and using maven 3.3.9.
When i add dependency:
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.aws-java-sdk</artifactId>
<version>1.11.18_1</version>
</dependency>
It is not building project and throwing maven-scr-plugin error:
SCR Descriptor parsing had failures.
[ERROR] Failed to execute goal org.apache.felix:maven-scr-plugin:1.20.0:scr (generate-scr-scrdescriptor) on project aviva-investors-bundle: SCR Descriptor parsing had failures (see log) -> [Help 1]
If I try to add only JAR
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.2</version>
</dependency>
Build is successful. But I am not able to resolve my project bundle. Bundle is in Installed state. Imported Packages shows: Cannot resolve dependency:
com.amazonaws.services.s3,version=[1.11,2) -- Cannot be resolved
Not sure what to add in dependency to make my imports work.
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.ClientConfiguration;
etc.
Any help is much needed.
When you include a dependency in your maven build it is not push to the osgi container. It would be used only to compile your site bundle.
Heres two options what do can do.
1. Upload the s3 jar as an osgi bundle
2. Create another maven task to deploy third party dependencies to your osgi container. See http://www.cqblueprints.com/tipsandtricks/build-and-deploy-osgi/deploy-third-party-libs.html

AEM 6: OSGi package dependencies not getting resolved

I am trying to use Jsoup library by creating an OSGi bundle out of it. I have created the bundles before so I am pretty much familiar with the process. I have also added the dependencies in the pom.xml like this:
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.7.3</version>
</dependency>
I am also following the steps given here: https://helpx.adobe.com/experience-manager/using/html-parser-service.html
I have tried everything but still the dependencies are not getting resolved. Attached are the screenshots.
What do I do ?
Thanks in advance
There is a version mismatch. Your bundle depends on the packages org.jsoup and friends having version 1.7 or higher. Strictly speaking it imports from version 1.7.0 (inclusive) up to version 2.0.0 (exclusive).
However, the bundle installed in your runtime exports as version 0.0.0. Therefore the import does not match the available exports and your bundle cannot resolve.
It seems you need to find an org.jsoup bundle that exports as version 1.7, and install that into your runtime instead of the bundle you have used here.
There a couple of various ways to resolve your problem:
Force import 0.0.0 version exported by your Jsoup bundle. (easiest)
This can be performed by update of Import-Package section of your bundle which consumes Jsoup packages:
<Import-Package>
org.jsoup.*;resolution:=required;version="[0.0,0.1)"
</Import-Package>
Wrap your Jsoup dependency with Maven POM and set version which you would like to export via update of Export-Package section (optional):
<Export-Package>
org.jsoup.*;version="1.7.2"
</Export-Package>
Details: http://www.cqblueprints.com/tipsandtricks/build-and-deploy-osgi/deploy-third-party-libs.html
Install another Jsoup JAR as OSGi bundle.
Original Jsoup 1.7.2 (http://mvnrepository.com/artifact/org.jsoup/jsoup/1.7.2) was good in my project.
Update your Maven "dependency" item to import:
<dependency>
<groupId>com.adobe.cq.jsoup</groupId>
<artifactId>jsoupservice-bundle</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

OSGI dependency issue with Sling Models project

I'm having a slight problem with incorporating the appropriate maven dependencies into my project for sling models.
When I deploy my bundle, I get the following import that can't be resolved:
org.apache.sling.models.annotations,version=[1.1,2) -- Cannot be resolved
I believe I have included this with the following dependencies:
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.impl</artifactId>
</dependency>
I tried using:
<Embed-Transitive>true</Embed-Transitive>
<Import-Package>*</Import-Package>
in my bundle compile instructions, but this has just resulted in a ton of other dependencies not being resolved.
Surely I've gone down the garden path here somewhere. Any help would be greatly appreciated.
The org.apache.sling.models.api V1.0.2 bundle does export the following packages:
javax.inject,version=0.0.0
org.apache.sling.models.annotations,version=1.1.0
org.apache.sling.models.annotations.injectorspecific,version=1.0.0
org.apache.sling.models.spi,version=1.0.0
org.apache.sling.models.spi.injectorspecific,version=1.0.0
So if that bundle is active in your Sling instance, the org.apache.sling.models.annotations,version=[1.1,2) import should resolve.
Note that adding bundles to your maven dependencies might not be sufficient to install them in the running instance, what matters is whether the models.api bundle is active as seen from /system/console/bundles
Using Embed-Transitive is almost always a terrible idea. It traverses the entire transitive dependency hierarchy in Maven and pulls each one of those JARs into your own JAR. As a result you inherit all the package dependencies of all that crap you have dragged in.
When you have a bundle such as yours that requires an import -- in this case org.apache.sling.models.annotations -- the best solution is to find another bundle already available that exports the same package.

Resources