How to use dependency classes in AEM as a cloud | Community
Skip to main content
Level 2
January 2, 2022
Solved

How to use dependency classes in AEM as a cloud

  • January 2, 2022
  • 1 reply
  • 4808 views

I want to use org.apache.commons.beanutils.BeanUtils class so I added a below dependency in core module,

 

Parent POM-

 

<dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>1.9.4</version> <scope>compile</scope> </dependency>

 

Core POM-

 

<dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> </dependency>

 

I am trying to access BeanUtils class within the same bundle but I could not build the code, it is giving below build error 

 

[ERROR] com.adobe.aem.xyz:1.1.0-SNAPSHOT: Bundle xyz.core:1.1.0-SNAPSHOT is importing package(s) org.apache.commons.beanutils in start level 20 but no bundle is exporting these for that start level. [ERROR] Analyser detected errors on feature 'com.adobe.aem.xyz:xyz.analyse:slingosgifeature:aggregated-publish.dev:1.1.0-SNAPSHOT'. See log output for error messages.

 

But I could not see any error in eclipse while importing the BeanUtils class but the code is getting failed. I thought it is expecting org.apache.commons.beanutils.BeanUtils to be set in Export-Package section, so I tried below config,

 

<plugin> <groupId>biz.aQute.bnd</groupId> <artifactId>bnd-maven-plugin</artifactId> <executions> <execution> <id>bnd-process</id> <goals> <goal>bnd-process</goal> </goals> <configuration> <bnd><![CDATA[Import-Package: javax.annotation;version=0.0.0, \ Export-Package: org.apache.commons;version=1.9.3, \ *]]></bnd> </configuration> </execution> </executions> </plugin>

 

But I ended up with same error. Can you please tell how dependencies are being managed and used in aem as cloud ?

Best answer by Vijayalakshmi_S

@ezhilcloud 

  • Bring back/Reset the changes done in parent pom.xml and core/pom.xml so far with respect to bnd-maven-plugin 
    • Note : We need not copy plugin configurations from parent to child. In this case, core module will inherit the plugin configurations from the parent. Specific instructions can then go in sub/child module. This is the case with any plugin in multi module maven project. 
  • Add the below line in core/pom.xml -> bnd-maven-plugin config alone (This will include this dependency inline)
    • -includeresource: @commons-beanutils-1.9.4.jar!/*

Meanwhile, I will check on the issue with -conditionalpackage and update this thread. 


@ezhilcloud 

Found the issue with conditionalpackage, use the below

-conditionalpackage: org.apache.commons.beanutils.*

Cause of the issue : 

 org.apache.commons.beanutils.BeanUtils class in turn is using org.apache.commons.beanutils.BeanUtilsBean class. Hence conditionalpackage entry to include BeanUtils alone was not getting included in the core bundle. 

Based on your requirement for this dependency, you can either use -conditionalpackage or -includeresource

1 reply

Asutosh_Jena_
Community Advisor
Community Advisor
January 3, 2022

Hi @ezhilcloud 

 

You need to add the dependency in 2 different location i.e., Parent POM.XML and Core POM.XML

 

Parent POM.XML

<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>

 

Core POM.XML

<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</dependency>

 

There is no different between AEM as Cloud and AEM on premise dependency management! I just did it on my AEM as Cloud and it works perfectly fine!

 

Hope this helps!

 

Thanks!

Level 2
January 3, 2022

Asutosh_Jena - It is not resolving the build issue. I get the same error. it is giving error "no bundle is exporting these package" Dont we need to export this package anywhere"?

Asutosh_Jena_
Community Advisor
Community Advisor
January 3, 2022

@ezhilcloud Please make sure your bnd-maven-plugin has the below code.

 

<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>${bnd-maven-plugin.version}</version>
<executions>
<execution>
<id>bnd-process</id>
<goals>
<goal>bnd-process</goal>
</goals>
<configuration>
<bnd>
Bundle-Category: yourbundlename
<!-- export all versioned packages except for conditional ones (https://github.com/bndtools/bnd/issues/3721#issuecomment-579026778) -->
-exportcontents: ${removeall;${packages;VERSIONED};${packages;CONDITIONAL}}
<!-- reproducible builds (https://github.com/bndtools/bnd/issues/3521) -->
-noextraheaders: true
<!-- Use "SNAPSHOT" suffix for snapshot bundle versions -->
-snapshot: SNAPSHOT
<!-- Do not set Bundle-DocURL because the maven auto-generated URLs are often not useful -->
Bundle-DocURL:
<!-- Generate bundle header containing all configuration annotation classes -->
-plugin.slingcaconfig: org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin
<!-- Generate bundle header for Sling Models classes -->
-plugin.slingmodels: org.apache.sling.bnd.models.ModelsScannerPlugin
</bnd>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.caconfig.bnd-plugin</artifactId>
<version>${org.apache.sling.caconfig.bnd-plugin.version}</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.bnd.models</artifactId>
<version>${org.apache.sling.bnd.models.version}</version>
</dependency>
</dependencies>
</plugin>