Hiya. I'm working on an OSGi project (although that's kind of beside the point), divided into several projects (each compiled to a jar using maven).

Rather than having interdependencies all over the place, I have a single project called "types" which defines all the interfaces, enums, reusable classes, etc. All other projects depend on "types" and nothing else (of my code that is, of course they depend on external jars; spring, jdbc, apache commons etc).

This works fine, until I try to implement unit testing. There are several common tasks that need to be performed during the tests, including testing of types. However, some of these tasks themselves depend on Types defined in the "types" project (such as creation of mock objects).

What's the best way to do this?

My first attempt didn't work. Rough outline is the following projects, in dependency order
  • testutils (no dependencies). Provides common setUp code, and some custom assertions
  • types (depends on testutils). Provides all types used in the oveall project set. Unit tests can only use testutils.
  • testmocks (depends on types). Provides mock objects, and other common test code that depends on "types"
  • all other projects (depend on all of the above). Can use whatever


This doesn't work; I'm writing code that is used in testing the "types" project, which depends on Types defined in "types", that should be available for testing other projects. I've got nowhere to put it.

So my next idea is to get rid of the two test projects and put the common unit testing code into the "types" project itself, but I'm not sure on how to do this. If I put it in src/main/java, it'll be available during regular runtime, which I don't think I want. If I put it in src/test/java, it won't be exported at all, so it won't be usable by any of the other projects.

What's the best way of doing this?

Cheers.