Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
scr bnd plugin 1.9.0
Description
When building a project where a newer version of a dependency is embedded in the project artifact with a conflicting older version of said dependency is also present on the classpath, SOME environments encounter an exception that is similar to the following:
[ERROR] Manifest com.adobe.acs:acs-aem-commons-bundle:bundle:3.19.1-SNAPSHOT : Got unexpected exception while analyzing:org.apache.felix.scrplugin.SCRDescriptorException: Unable to load compiled class: com.google.common.base.Suppliers$SupplierFunctionImpl at org.apache.felix.scrplugin.helper.ClassScanner.scanSources(ClassScanner.java:156) at org.apache.felix.scrplugin.SCRDescriptorGenerator.execute(SCRDescriptorGenerator.java:146) at org.apache.felix.scrplugin.bnd.SCRDescriptorBndPlugin.analyzeJar(SCRDescriptorBndPlugin.java:178) at aQute.bnd.osgi.Analyzer.doPlugins(Analyzer.java:820) at aQute.bnd.osgi.Analyzer.analyze(Analyzer.java:229) at aQute.bnd.osgi.Builder.analyze(Builder.java:408) at aQute.bnd.osgi.Analyzer.calcManifest(Analyzer.java:850) at aQute.bnd.osgi.Builder.build(Builder.java:116) at org.apache.felix.bundleplugin.ManifestPlugin.getAnalyzer(ManifestPlugin.java:291) at org.apache.felix.bundleplugin.ManifestPlugin.execute(ManifestPlugin.java:98) at org.apache.felix.bundleplugin.BundlePlugin.execute(BundlePlugin.java:384) at org.apache.felix.bundleplugin.BundlePlugin.execute(BundlePlugin.java:375) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288) at org.apache.maven.cli.MavenCli.main(MavenCli.java:192) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) Caused by: java.lang.IncompatibleClassChangeError: Implementing class at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:468) at java.net.URLClassLoader.access$100(URLClassLoader.java:74) at java.net.URLClassLoader$1.run(URLClassLoader.java:369) at java.net.URLClassLoader$1.run(URLClassLoader.java:363) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:362) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at org.apache.felix.scrplugin.helper.ClassScanner.scanSources(ClassScanner.java:144) ... 33 more [ERROR] Error(s) found in manifest configuration
The sequence of dependencies in the build should allow the preferred embedded version to be declared with higher precedence than the non-preferred version, but this sequence does not appear to be respected because of the use of a non-linked HashSet in `SCRDescriptorBndPlugin.getClassPath()` to post-process the list of classpath elements returned from Analyzer.getClasspath().
I attached to debug logs from the execution. the *.bnd-1.9.0.log file shows the `uber-jar` artifact listed before the `guava` artifact in the classpath log, but their order is reversed in the dependencies log.
I then replaced the HashSet with a LinkedHashSet in the bnd plugin and rebuilt the project, resulting in the *.bnd-1.9.1-SNAPSHOT.log, which shows the sequence of these two artifacts being the same in both the classpath log and the dependencies log.
See: https://github.com/Adobe-Consulting-Services/acs-aem-commons/issues/1675 for background.