Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

How to use dependency classes in AEM as a cloud

Avatar

Level 2

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 ?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@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

View solution in original post

14 Replies

Avatar

Community Advisor

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!

Avatar

Level 2

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"?

Avatar

Community Advisor

@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>

Avatar

Level 2

Asutosh_Jena Yeah, I have "bnd-maven-plugin" in both parent and core pom, below is the config, 

bnd-maven-plugin in Core POM-

<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,*
                                ]]>
				</bnd>
			</configuration>
		</execution>
	</executions>
</plugin>

bnd-maven-plugin in Parent  POM-

 

<plugin>
	<groupId>biz.aQute.bnd</groupId>
	<artifactId>bnd-maven-plugin</artifactId>
	<version>${bnd.version}</version>
	<executions>
		<execution>
			<id>bnd-process</id>
			<goals>
				<goal>bnd-process</goal>
			</goals>
			<configuration>
				<bnd>
					<![CDATA[
Bundle-Category: ${componentGroupName}

# 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
-snapshot: SNAPSHOT

Bundle-DocURL:
-plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin
-plugin 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>1.0.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.sling</groupId>
			<artifactId>org.apache.sling.bnd.models</artifactId>
			<version>1.0.0</version>
		</dependency>
	</dependencies>
</plugin>

I think it is expecting to export the package.

Avatar

Community Advisor

Hi @Ezhilcloud 

We need to use either conditionalPackage or includeResource based on your requirement(of how you want the dependency to be part of your core bundle - either inline/embedded/conditionally) 

You can refer the below for sample usage of these instructions. 

https://myaemlearnings.blogspot.com/2021/12/embed-third-party-dependency-using-bnd.html

 

Also, remove the <scope> tag from dependency entry in parent pom.xml

Avatar

Level 2

Vijayalakshmi_S - Thanks for the reference - I tried using "-conditionalpackage: org.apache.commons.*" in parent POM but getting the same error. Could you check if the syntax is correct? I also tried this child POM but no luck,

 

<plugin>
   <groupId>biz.aQute.bnd</groupId>
   <artifactId>bnd-maven-plugin</artifactId>
   <version>${bnd.version}</version>
   <executions>
      <execution>
         <id>bnd-process</id>
         <goals>
            <goal>bnd-process</goal>
         </goals>
         <configuration>
            <bnd><![CDATA[Bundle-Category: ${componentGroupName}

# 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
-snapshot: SNAPSHOT
-conditionalpackage: org.apache.commons.*

Bundle-DocURL:
-plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin
-plugin 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>1.0.2</version>
      </dependency>
      <dependency>
         <groupId>org.apache.sling</groupId>
         <artifactId>org.apache.sling.bnd.models</artifactId>
         <version>1.0.0</version>
      </dependency>
   </dependencies>
</plugin>

Avatar

Community Advisor

@Ezhilcloud 

Can you explicitly mention the Java package names of the ones that you are using as opposed to the generic wildcards in conditionalpackage. (package names from the import statements with respect to this dependency in your Java class)

Avatar

Level 2

Vijayalakshmi No luck with full package name, I tried this in both parent  and child POM. Am I missing anything?

 

<configuration>
   <bnd><![CDATA[Bundle-Category: ${componentGroupName}

# 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
-snapshot: SNAPSHOT
-conditionalpackage: org.apache.commons.beanutils.BeanUtils

Bundle-DocURL:
-plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin
-plugin org.apache.sling.bnd.models.ModelsScannerPlugin]]></bnd>
</configuration>

 

Avatar

Community Advisor

@Ezhilcloud 

Is this the only package you use ? - org.apache.commons.beanutils.BeanUtils

I will try to reproduce this in my local and update you. 

Avatar

Level 2

@Vijayalakshmi_S Yeah at the moment I am using  only org.apache.commons.beanutils.BeanUtils. Later I may use other packages. Thanks for your support.

Avatar

Community Advisor

@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. 

Avatar

Correct answer by
Community Advisor

@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

Avatar

Level 2

@Vijayalakshmi_S- It works. Thank you so much. Appreciate your effort and support. Do you suggest to have this in parent or core POM file?

 

Cause of the issue : I am not sure what is happening here. Both org.apache.commons.beanutils.BeanUtilsclass and org.apache.commons.beanutils.BeanUtilsBean are part of org.apache.commons* package then why it could not include?

 

In general, we usually want to include all the classes in the jar file. in this case should we specify all package one by one? maybe we can includeresource if we want to include all classes isnt it?

 

 

Avatar

Community Advisor

@Ezhilcloud 

You can add in core/pom.xml

Purpose of conditional package is just to include only the classes that you need as opposed to whole dependency that would result in added size to the resulting bundle. 

See this explanation from the official docs - https://bnd.bndtools.org/instructions/conditionalpackage.html

Vijayalakshmi_S_0-1641306928839.png

If you would like to use all the classes of a dependency, you can go for -includeresource. (either inline or embedded)

Again, you have options in includeresource as well to include specific class from a jar. Please refer the possible options in official doc -https://bnd.bndtools.org/instructions/includeresource.html