adobe / aem-project-archetype

Maven template to create best-practice websites on AEM.
https://experienceleague.adobe.com/docs/experience-manager-core-components/using/developing/archetype/overview.html
Apache License 2.0
540 stars 416 forks source link

Context-Aware Configuration does not work #971

Open alberndt opened 1 year ago

alberndt commented 1 year ago

Expected Behaviour

a Sling Context-Aware configuration can be used

Actual Behaviour

An interface annotated as org.apache.sling.caconfig.annotation.Configuration is not found by the bnd-process

The issue can be fixed, if the current bnd-configuration (main pom.xml)

# does NOT work
-plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin
-plugin org.apache.sling.bnd.models.ModelsScannerPlugin

is changed to

# does work
-plugin.caconfig org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin
-plugin.models org.apache.sling.bnd.models.ModelsScannerPlugin

see merged bnd-instructions (chapter 33.2 Merged Instructions at https://bnd.bndtools.org/chapters/820-instructions.html)

alternatively all plugins can be specified in a single line

# works too
-plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin,org.apache.sling.bnd.models.ModelsScannerPlugin

In the current version only the ModelsScannerPlugin is used. By changing the order of the lines, only the ConfigurationClassScannerPlugin is used. So the last -plugin instruction wins.

Steps to Reproduce

Add a Context-aware configuration to core, and the built bundle should have 2 Manifest-Headers

Platform and Version

AEMaaCS, MacOS w. M1 chip - but probably all platforms

PS: I could create a Pull-Request, which also includes a sample CA-Config.

kind regards, Alexander Berndt

juan-ayala commented 1 year ago

I have replicated this issue. It is worth nothing that projects like AEM WCM Core Components are still using the maven-bundle-plugin and not bnd-maven-plugin.

Either of the solutions proposed by @alberndt works.

kwin commented 8 months ago

Bnd instructions should use the format outlined in https://bnd.bndtools.org/chapters/820-instructions.html:

bnd instruction is a property that starts with a minus sign (‘-‘)

That implies using the properties format <name>: <value>