I have a Project A which has got certain features and associated sling models. As per the requirement, I have to add the core and ui.apps of this Project A as a dependency to Project B.
So Project A core.jar added as dependency to Project B core module
& Project A ui.apps.zip added as dependency to Project B ui.apps module.
Also I have to extend Sling Models from Project A into Project B and override some of their getters where additional logic is implemented. (typical requirement and needs to be done). The sling models in Project A are actually composed of multiple other sling models as sub elements.
Example.
@Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class Content extends abc.core.models.Content {
@inject
private TextSlingModel text;
@Override
public TextSlingModel getText() {
return text;
}
}
All the build time dependencies are resolved and this is deployed to AEM. Now, when I'm trying to access fields of Project A Sling Models via Project B Sling Models, it works fine if the extended sling model just has new fields and none of the SDM getters(getText in above example) from parent SDM are overriddren in child SDM.
However, when the child SDM has overridden getters I get error as below:
java.lang.LinkageError: loader constraint violation for class projectA.core.models.Content: when selecting overriding method projectA.core.models.Content.getText()LprojectB/core/models/context/TextSlingModel; the class loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @4f50a54b (instance of org.apache.felix.framework.BundleWiringImpl$BundleClassLoader, child of org.apache.sling.launchpad.base.shared.LauncherClassLoader @147a5d08 org.apache.sling.launchpad.base.shared.LauncherClassLoader) of the selected method's type projectA.core.models.Content, and the class loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @4f9211d8 (instance of org.apache.felix.framework.BundleWiringImpl$BundleClassLoader, child of org.apache.sling.launchpad.base.shared.LauncherClassLoader @147a5d08 org.apache.sling.launchpad.base.shared.LauncherClassLoader) for its super type projectB.core.models.Content have different Class objects for the type projectB.core.models.context.TextSlingModel used in the signature
Please note that thing was working fine when the Parent Project was included in the ui.apps and core module as sibling folders even in this case SDMs were extended.