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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With