Integration test dependencies without export-package

I have some integration tests that depend on classes from my main sources. It’s not only about services, but also some utility classes and other internal code.

How can I make these tests work without making all the main classes OSGi exports/imports?

The problem is that the test jar does not include the main classes, so it’s throwing ClassNotFoundException on runtime. It only works when I add export-package on the main JAR and then import-package in test atlassian-plugin.xml. I would really like to avoid that, since exporting all these packages to the container is causing different kinds of trouble.

Somewhat desperate, I’ve tried the following in my pom.xml. None of it seems to do anything:


One way to achieve this is to use Maven build profiles with different Export-Package configuration for prod and dev.

As you see, if you want to interact with a component, you need to export all related objects it exposes to ‘you’ the caller, externalizing internal state may not be best. What we did to solve this was to make a dedicated public exported API specifically for integration testing with a set of DTO beans that isolate internal state and references from your integration tests. This means tests only need the API package to interact with your integration testing layer. Sure, you’re not driving the ‘component’ directly, but as its not a public component, its probably the easiest way. This also means (if you’re using arquillian) that you can run tests against a local non-amps launched app instance, or even DataCenter (ie one build is enough).