Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven cyclic dependency with test scope

We have a ProjectB (only main, not tests) depend on ProjectA. ProjectA's test (not main) depends on ProjectB. We have maven produce two separate artifacts (main and test jars) for each project. So there is really no circular dependency here but maven complains about circular dependency. I am wondering if there there is a way to tell in maven that this is really not a circular dependency.

In ProjectA we have dependency section of ProjectB with "test" scope since only ProjectA tests depend on ProjectB.

like image 369
ppeddi Avatar asked Jun 05 '13 19:06

ppeddi


People also ask

Does Maven allow circular dependencies?

Maven does not allow cyclic dependencies between projects, because otherwise, it is not clear which project to build first. So you need to get rid of this cycle.

How do you resolve cyclic reference in Maven?

So you need to get rid of this cycle. One solution is the one you already mentioned, to create another project. Another one would be to just move some classes from B to C or vice versa when this helps. Or sometimes it is correct to merge project B and C to one project if there is no need to have two of them.

How would you fix a cyclic dependency?

A cyclic dependency is an indication of a design or modeling problem in your software. Although you can construct your object graph by using property injection, you will ignore the root cause and add another problem: property injection causes Temporal Coupling. Instead, the solution is to look at the design closely.

What is test dependency in Maven?

A test -scoped dependency is a dependency that is available on the classpath only during test compilation and test execution. If your project has war or ear packaging, a test -scoped dependency would not be included in the project's output archive.


1 Answers

Maven builds modules as a whole, so you can't have :

Building Project A (main)
Building Project B (main)
Building Project A (test)
Building Project B (test)

You can either group your code in one project or create a third project that will have all common code for projects A and B.

like image 188
Guillaume Darmont Avatar answered Oct 21 '22 06:10

Guillaume Darmont