views:

2468

answers:

5

I'm in the process of converting my projects to OSGI bundles using maven and eclipse. Maven builds the stuff just fine, only I get the above error now within Eclipse. How can I find out which project causes this? Is there a special view or something? How can this happen, I would expect that maven can detect cyclic dependencies as well?

Update

Ok, I found something here and here

Could this be caused by the felix maven-bundle-plugin which does for each export also an import?

A: 

When I've had these problems it always has been a true cycle in the dependencies expressed in Manifest.mf

So open the manifest of the project in question, on the Dependencies Tab, look at the "Required Plugins" entry. Then follow from there to the next project(s), and repeat eventually the cycle will become clear.

You can simpify this task somewhat by using the Dependency Analysis links in the bottom right corner of the Dependencies Tab, this has cycle detection and easier navigation depdendencies.

I also don't know why Maven is more tolerant,

djna
A: 

Maven will fail the build if it detects a cycle, as the dependencies must be a tree.

You may find that you have additional declarations in the manifest.mf over those defined in the pom.xml. any extra declaration could introduce a cycle that wouldn't be apparent to Maven.

Rich Seller
A: 

In simple terms, a cycle is when bundle A depends on bundle B which depends on bundle A. If this is source code, then there's no way of building the bundles seperately in one pass.

Since the problem only shows in Eclipse, it may be a binary circular dependency as opposed to a source code circular dependency.

There is support for binary cycles in recent versions of Eclipse: Eclipsesource Blog

If the cycle is in your code, then I suggest refactoring the code by breaking out some of the code to a 3rd bundle to remove the circular dependency.

And watch out if you are using OSGi fragments (a common pattern for unit testing) as it is very easy to introduce cycles.

Eclipse's manifest editor does have functionality on the "Dependencies" tab for looking for cycles (you need to click on "Dependency Analysis"), but I've never seen it show a cycle even when Eclipse has a big red X telling me there's a cycle!

hbunny
+1  A: 

As well as the Require-Bundle form of dependency management (most similar to Maven's pom dependencies), it's also possible to have Import-Package dependencies. It's much easier to introduce circular dependencies with Import-Package than Require-Bundle, but YMMV.

Also, Eclipse projects have a 'project references' which says which other projects it depends on. Eclipse uses this at a high level to decide what projects to build, and in which order, so it's quite possible that your Manifest.MF lists everything correctly but the project references are out of whack. Right click on a project and then go to properties - you'll see which projects you depend on. If you're a text kind of person, open up the .project files and see which ones you depend on there - it's probable that a project cyclic link is being defined at that level instead (often caused when you have an A-B dependency and then flipped from B-A but without updating the .project references).

AlBlue
+1 for mentioning the Eclipse problems with .project files.. Sometimes the only solution is throwing away everything related to Eclipse and let it figure it out from the pom again..
Tim
A: 

I faced similar problem a while ago and decided to write Eclipse plug-in that shows complete build path dependency tree of a Java project (although not in graphic mode - result is written into file). The plug-in's sources are here http://github.com/PetrGlad/dependency-tree

Petr Gladkikh