AEM6 and Archiva Servlet gotcha

I am working on a project that is using AEM6 and an AEM FeaturePack for Adobe Campaign. As this is a FP, the APIs are not available through the normal public repositories. I needed to get the project to build so the solution is to use the Archive Servlet. This worked great and the project compiled and installed into AEM fine.

I then needed to use HTTPClient to make some external webservice calls, so looked at what was exposed by the Archiva servlet, found that AEM already uses 4.3.3, added the dependency, mvn clean install, code compiled, happy days.

Until I went to install it into AEM. Then I was getting weird bundle dependency issues:

21.04.2015 16:56:53.374 *INFO* [OsgiInstallerImpl] org.apache.sling.installer.core.impl.tasks.RestartActiveBundlesTask Unable to start bundle com.xyz.test-bundle [396] : Unresolved constraint in bundle com.st.test-bundle [396]: Unable to resolve 396.9: missing requirement [396.9] osgi.wiring.package; (osgi.wiring.package=com.carrotsearch.hppc)

CarrotSearch? Very strange. A quick look at the MANIFEST.MF revealed a huge number of dependencies now on my bundle:

$ cat ./bundle/target/classes/META-INF/MANIFEST.MF
Manifest-Version: 1.0
Bnd-LastModified: 1429628261535
Build-Jdk: 1.7.0_67
Built-By: brobertson
Bundle-ClassPath: .,httpcore-4.3.2.jar,httpclient-4.3.2.jar
Bundle-Description: Maven Multimodule project.
Bundle-ManifestVersion: 2
Bundle-Name: ST Test Integration Bundle
Bundle-SymbolicName: com.st.test-bundle
Bundle-Version: 0.1.1.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Embed-Dependency: httpcore;httpclient;
Embedded-Artifacts: httpcore-4.3.2.jar;g="org.apache.httpcomponents";a="
 httpcore";v="4.3.2",httpclient-4.3.2.jar;g="org.apache.httpcomponents";
 a="httpclient";v="4.3.2"
Export-Package: com.st.test;uses:="org.apache.sling.api.servlets,javax.s
 ervlet,org.apache.sling.api";version="0.1.1.SNAPSHOT"
Import-Package: com.carrotsearch.hppc,com.carrotsearch.hppc.cursors,com.
 google.common.base,com.google.common.cache,com.google.common.collect,co
 m.google.common.io,com.googlecode.concurrentlinkedhashmap,com.sun.manag
 ement,com.vividsolutions.jts.algorithm,com.vividsolutions.jts.geom,com.
 vividsolutions.jts.io,com.vividsolutions.jts.operation.union,com.vivids
 olutions.jts.operation.valid,com.vividsolutions.jts.simplify,com.vivids
 olutions.jts.util,javax.annotation,javax.crypto,javax.crypto.spec,javax
 .management,javax.management.openmbean,javax.management.remote,javax.na
 ming,javax.net,javax.net.ssl,javax.script,javax.security.auth,javax.sec
 urity.auth.callback,javax.security.auth.kerberos,javax.security.auth.lo
 gin,javax.security.auth.spi,javax.security.auth.x500,javax.security.sas
 l,javax.servlet,javax.servlet.http,javax.xml.namespace,javax.xml.parser
 s,javax.xml.stream,javax.xml.transform,javax.xml.transform.dom,javax.xm
 l.transform.sax,javax.xml.transform.stream,javax.xml.xpath,jline,org.ap
 ache.commons.codec.binary;version="[1.6,2)",org.apache.commons.fileuplo
 ad,org.apache.commons.fileupload.disk,org.apache.commons.fileupload.ser
 vlet,org.apache.commons.io,org.apache.commons.io.input,org.apache.commo
 ns.logging;version="[1.1,2)",org.apache.hadoop.conf,org.apache.hadoop.f
 s,org.apache.hadoop.fs.permission,org.apache.hadoop.ipc,org.apache.hado
 op.metrics,org.apache.hadoop.metrics.jvm,org.apache.hadoop.security,org
 .apache.hadoop.util,org.apache.jackrabbit.oak.api;version="[1.0,2)",org
 .apache.jackrabbit.oak.commons;version="[1.0,2)",org.apache.jackrabbit.
 oak.plugins.index;version="[1.0,2)",org.apache.jackrabbit.oak.plugins.i
 ndex.aggregate;version="[1.0,2)",org.apache.jackrabbit.oak.query.fullte
 xt;version="[1.0,2)",org.apache.jackrabbit.oak.spi.commit;version="[1.0
 ,2)",org.apache.jackrabbit.oak.spi.lifecycle;version="[1.0,2)",org.apac
 he.jackrabbit.oak.spi.query;version="[1.0,2)",org.apache.jackrabbit.oak
 .spi.state;version="[1.0,2)",org.apache.log4j,org.apache.log4j.jmx,org.
 apache.log4j.spi,org.apache.lucene.expressions,org.apache.lucene.expres
 sions.js,org.apache.lucene.index.memory,org.apache.regexp,org.apache.sl
 ing.api;version="[2.3,3)",org.apache.sling.api.servlets;version="[2.1,3
 )",org.eclipse.jetty.server,org.eclipse.jetty.server.bio,org.eclipse.je
 tty.server.handler,org.eclipse.jetty.server.nio,org.eclipse.jetty.serve
 r.session,org.eclipse.jetty.server.ssl,org.eclipse.jetty.servlet,org.ec
 lipse.jetty.util.component,org.eclipse.jetty.util.log,org.eclipse.jetty
 .util.ssl,org.eclipse.jetty.util.thread,org.ietf.jgss,org.jboss.netty.b
 ootstrap,org.jboss.netty.buffer,org.jboss.netty.channel,org.jboss.netty
 .channel.group,org.jboss.netty.channel.socket.nio,org.joda.time,org.jod
 a.time.format,org.osgi.service.component;version="[1.1,2)",org.restlet,
 org.restlet.data,org.restlet.representation,org.restlet.resource,org.re
 stlet.routing,org.slf4j;version="[1.5,2)",org.slf4j.impl,org.w3c.dom,or
 g.xml.sax,org.xml.sax.ext,org.xml.sax.helpers
Service-Component: OSGI-INF/serviceComponents.xml
Tool: Bnd-1.50.0

And when I removed the HTTPClient dependency, they all disappeared.

What I found was that in my ~/.m2/repository/org/apache/httpcomponents/httpclient/4.3.3 the JAR was suspiciously large at over 10MB. And when I looked at the MANIFEST.MF of this file:

Manifest-Version: 1.0
Bnd-LastModified: 1399600663141
Build-Jdk: 1.7.0_40
Built-By: jzitting
Bundle-Category: oak
Bundle-Description: Oak Solr OSGi support
Bundle-DocURL: http://jackrabbit.apache.org/oak/
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-ManifestVersion: 2
Bundle-Name: Oak Solr OSGi
Bundle-SymbolicName: org.apache.jackrabbit.oak-solr-osgi
Bundle-Vendor: The Apache Software Foundation
Bundle-Version: 1.0.0
Created-By: Apache Maven Bundle Plugin
Embed-Dependency: *;scope=runtime;inline=true
Import-Package: org.apache.lucene.expressions;resolution:=optional,org.a
 pache.lucene.expressions.js;resolution:=optional,org.apache.lucene.inde
 x.memory;resolution:=optional,com.carrotsearch.hppc;resolution:=optiona
 l,com.carrotsearch.hppc.cursors;resolution:=optional,com.googlecode.con
 currentlinkedhashmap;resolution:=optional,com.vividsolutions.jts.algori
 thm;resolution:=optional,com.vividsolutions.jts.geom;resolution:=option
 al,com.vividsolutions.jts.io;resolution:=optional,com.vividsolutions.jt
 s.operation.union;resolution:=optional,com.vividsolutions.jts.operation
 .valid;resolution:=optional,com.vividsolutions.jts.simplify;resolution:
 =optional,com.vividsolutions.jts.util;resolution:=optional,com.sun.mana
 gement;resolution:=optional,jline;resolution:=optional,org.apache.hadoo
 p.conf;resolution:=optional,org.apache.hadoop.fs;resolution:=optional,o
 rg.apache.hadoop.fs.permission;resolution:=optional,org.apache.hadoop.i
 pc;resolution:=optional,org.apache.hadoop.metrics;resolution:=optional,
 org.apache.hadoop.metrics.jvm;resolution:=optional,org.apache.hadoop.se
 curity;resolution:=optional,org.apache.hadoop.util;resolution:=optional
 ,org.apache.regexp;resolution:=optional,org.apache.log4j;resolution:=op
 tional,org.apache.log4j.jmx;resolution:=optional,org.apache.log4j.spi;r
 esolution:=optional,org.jboss.netty.bootstrap;resolution:=optional;vers
 ion="[3.2,4)",org.jboss.netty.buffer;resolution:=optional;version="[3.2
 ,4)",org.jboss.netty.channel;resolution:=optional;version="[3.2,4)",org
 .jboss.netty.channel.group;resolution:=optional;version="[3.2,4)",org.j
 boss.netty.channel.socket.nio;resolution:=optional;version="[3.2,4)",or
 g.restlet;resolution:=optional,org.restlet.data;resolution:=optional,or
 g.restlet.representation;resolution:=optional,org.restlet.resource;reso
 lution:=optional,org.restlet.routing;resolution:=optional,org.joda.time
 ;resolution:=optional;version="[2.2,3)",org.joda.time.format;resolution
 :=optional;version="[2.2,3)",org.eclipse.jetty.server;resolution:=optio
 nal;version="[8.1,9)",org.eclipse.jetty.server.bio;resolution:=optional
 ;version="[8.1,9)",org.eclipse.jetty.server.handler;resolution:=optiona
 l;version="[8.1,9)",org.eclipse.jetty.server.nio;resolution:=optional;v
 ersion="[8.1,9)",org.eclipse.jetty.server.session;resolution:=optional;
 version="[8.1,9)",org.eclipse.jetty.server.ssl;resolution:=optional;ver
 sion="[8.1,9)",org.eclipse.jetty.servlet;resolution:=optional;version="
 [8.1,9)",org.eclipse.jetty.util.component;resolution:=optional;version=
 "[8.1,9)",org.eclipse.jetty.util.log;resolution:=optional;version="[8.1
 ,9)",org.eclipse.jetty.util.ssl;resolution:=optional;version="[8.1,9)",
 org.eclipse.jetty.util.thread;resolution:=optional;version="[8.1,9)",ja
 vax.servlet;resolution:=optional;version="[2.6,3)",javax.servlet.http;r
 esolution:=optional;version="[2.6,3)",com.google.common.base;version="[
 15.0,16)",com.google.common.cache;version="[15.0,16)",com.google.common
 .collect;version="[15.0,16)",com.google.common.io;version="[15.0,16)",j
 avax.annotation,javax.crypto,javax.crypto.spec,javax.management,javax.m
 anagement.openmbean,javax.management.remote,javax.naming,javax.net,java
 x.net.ssl,javax.script,javax.security.auth,javax.security.auth.callback
 ,javax.security.auth.kerberos,javax.security.auth.login,javax.security.
 auth.spi,javax.security.auth.x500,javax.security.sasl,javax.xml.namespa
 ce,javax.xml.parsers,javax.xml.stream,javax.xml.transform,javax.xml.tra
 nsform.dom,javax.xml.transform.sax,javax.xml.transform.stream,javax.xml
 .xpath,org.apache.commons.codec.binary;version="[1.5,2)",org.apache.com
 mons.fileupload;version="[1.2,2)",org.apache.commons.fileupload.disk;ve
 rsion="[1.2,2)",org.apache.commons.fileupload.servlet;version="[1.2,2)"
 ,org.apache.commons.io;version="[1.4,2)",org.apache.commons.io.input;ve
 rsion="[1.4,2)",org.apache.commons.logging;version="[1.1,2)",org.apache
 .jackrabbit.oak.api;version="[1.0,2)",org.apache.jackrabbit.oak.commons
 ;version="[1.0,2)",org.apache.jackrabbit.oak.plugins.index;version="[1.
 0,2)",org.apache.jackrabbit.oak.plugins.index.aggregate;version="[1.0,2
 )",org.apache.jackrabbit.oak.query.fulltext;version="[1.0,2)",org.apach
 e.jackrabbit.oak.spi.commit;version="[1.0,2)",org.apache.jackrabbit.oak
 .spi.lifecycle;version="[1.0,2)",org.apache.jackrabbit.oak.spi.query;ve
 rsion="[1.0,2)",org.apache.jackrabbit.oak.spi.state;version="[1.0,2)",o
 rg.ietf.jgss,org.osgi.service.component;version="[1.1,2)";resolution:=o
 ptional,org.slf4j;version="[1.7,2)",org.slf4j.impl;version="[1.6,2)",or
 g.w3c.dom,org.xml.sax,org.xml.sax.ext,org.xml.sax.helpers
Service-Component: OSGI-INF/org.apache.jackrabbit.oak.plugins.index.solr
 .osgi.SolrQueryIndexProviderService.xml,OSGI-INF/org.apache.jackrabbit.
 oak.plugins.index.solr.osgi.SolrServerProviderService.xml,OSGI-INF/org.
 apache.jackrabbit.oak.plugins.index.solr.osgi.SolrIndexEditorProviderSe
 rvice.xml,OSGI-INF/org.apache.jackrabbit.oak.plugins.index.solr.osgi.Em
 beddedSolrServerConfigurationProvider.xml,OSGI-INF/org.apache.jackrabbi
 t.oak.plugins.index.solr.osgi.RemoteSolrServerConfigurationProvider.xml
 ,OSGI-INF/org.apache.jackrabbit.oak.plugins.index.solr.osgi.OakSolrConf
 igurationProviderService.xml
Tool: Bnd-2.1.0.20130426-122213

So in the end I moved the Archiva servlet to the last Repository in the Repositories list to make this work.

Hope this helps someone!